SlideShare a Scribd company logo
1 of 15
Intel Dynamic Execution Environments Symposium
Collaborate Innovate Strategize Lead
Session III: Productization Issues
The price of similarity,
or whether to say ‘NO’ to STL
Anton Malakhov
Alexey Kukanov
Arch Robison
2
IDEES’09
Outline
Why STL similarity? Related works
Issues with STL semantics for concurrency
A possible solution: Dual Interfaces
Summary
3
IDEES’09
Why STL similarity?
 STL is C++ standard, authority, and a role model
 Many libraries try STL similarity for parallelism:
 TBB, PPL, STAPL, PSTL, Range Partition Adapters, Thrust, Glift
 But only TBB and PPL try to closely follow STL
requirements for concurrent containers
 Now, we can sum up this experience
4
IDEES’09
STL is incompatible with concurrency:
lack of atomicity
 C++ standard prescribes interfaces for efficient
serial manipulation of containers
item = queue.front(); // Get the first item
queue.pop(); // Remove it from the queue
 front() returns a reference to avoid overhead of return-by-value
 Interface precludes safe concurrent manipulation
 Two threads cannot grab items from the queue concurrently
 front() and pop() operations might race in unfortunate ways
 Race is induced by the interface and can not be fixed by any
implementation technique from inside
The interface is too orthogonal to maintain
level of atomicity required for correctness
5
IDEES’09
STL is incompatible with concurrency:
Control of lifetime and access
 Destruction and deallocation of an element is only
safe if all other threads are done accessing it
 Supporting concurrent erase() and following STL
semantics is not feasible for concurrent containers
 How we
 ppl::concurrent_unordered_map drops concurrent erase()
 tbb::concurrent_hash_map introduces accessor
• a smart pointer to prevent premature destruction
STL lacks support for synchronizing
object access and lifetime
6
IDEES’09
Strict STL similarity is inefficient:
Decomposition vs. Merge
 Decomposition of entities is a key STL principle
 C++0x expectedly follows it
class shared_ptr { atomic ops }; class mutex { atomic ops };
function F { ptr = shared_ptr; ptr->lock(); } // 2 atomic ops
 Merge of entities can be optimized for efficiency
class shared_lockable_ptr { atomic ops };
function F { ptr = shared_lockable_ptr.lock(); } // 1 atomic op
The interface is too orthogonal to maintain
level of atomicity required for efficiency
7
IDEES’09
STL is not efficient for concurrency:
Iterators vs. Ranges
 4 of 5 iterator kinds are inherently serial
 Abstraction of pointer bumping
 Enabling concurrency-safe iteration is tricky
 Concurrent modifications can invalidate iterators
 STL ranges only defined implicitly
 Abstraction of a linear sequence: [first, last)
 Carried dependency precludes efficient parallel iteration
• Only random-access iterators allow it
 Generic recursively divisible range would be better
 E.g. enable scalable parallelism in breadth-first tree traversal
STL abstracted a serial idiom
unsuitable for parallel programming
8
IDEES’09
Concurrent interface is not efficient
for serial usage
 Objects can be used both in serial and in parallel
 Due to data sharing between program stages
 It’s also desirable to add parallelism incrementally
 Concurrent interface can require code changes
 Due to semantic differences discussed earlier
 Contradictory to incremental parallelization
 Serial performance can suffer
 Traded for better concurrency in implementations
 Impacted by synchronization overhead (even without contention)
Enabling concurrency imposes additional cost
even to serial stages of a program
9
IDEES’09
Concurrency as an STL extension:
The root of the problems
 STL similarity bends
concurrent interface
 Concurrency is afterthought
for serial world of STL?
 Concurrency puts
pressure on serial code
 Undesired impact of
parallelism adoption
 Separate the interfaces
 Release from straitjackets!
STL requirements and principles
STL-like class {
Serial methods
};
Concurrent methods
Parallel principles
Serial Parallel execution Serial
Object lifetime
10
IDEES’09
Dual Interfaces
 Same data structure,
two interfaces
 Concurrent and serial views
 STL compatibility
 Enables smooth migration
 Enabled efficiency
 Concurrent interface drops
burden of STL similarity
 Serial performance is
available with serial interface
Parallel principles and practices
class ConcurrentFoo {
Concurrent methods
SerialViewOfFoo serial()
};
STL requirements and principles
class SerialViewOfFoo {
Serial methods, up to
100% STL compatible!
};
11
IDEES’09
Dual interfaces: the silver bullet?
 Writing “concurrent”, thinking “STL”
 Some C++ developers still expect STL behavior or guarantees
• An example:
• Const methods are expected to do no visible modification
• Modifications might be undetectable by concurrent interface
• BUT still visible by serial interface, e.g. as broken iterators
 Can indirectly affect concurrent interface and implementation
 Additional burden on users
 Bigger “surface area” to learn
 Special rules to remember & follow
• E.g. switch between interfaces – when and how?
 Will mainstream customers buy in the idea?
Solves the problems but puts new questions
12
IDEES’09
Summary
 STL compatibility is important for customers
 STL similarity in concurrent interface has problems
 Principles of STL and concurrency contradict
 Separate interfaces for serial and concurrent
access to the same object can do better
 Still some questions remain open
13
IDEES’09
Thank you!
14
IDEES’09
Dual interfaces: composability rules
 General rule is:
“Do not mix concurrent and serial interfaces”
 Interfaces are not compatible with each other anyway
 It enables smooth migration and efficiency
 Only one reference using only one type
must be passed to a function
 If callers are unknown
• Don’t switch interfaces inside
 If subroutine is unknown
• Don’t switch interfaces during its runtime
 For mixed interface, composability is worse
 It is unknown what interface to use
 Or use concurrent by default, but
• The whole access code must be changed
• Serial code loses efficiency
• e.g. in const-serial-access of a huge parallel region
//Thread-safe R/W
ConcurrentFoo crw;
//Thread-safe R/O
const SerialFoo cro;
//Serial R/W
SerialFoo srw;
15
IDEES’09
Links
 Many libraries try STL similarity for parallelism:
 TBB and PPL
 STAPL
 PSTL
 Range Partition Adapters
 Thrust: NVIDIA's STL
 Glift

More Related Content

Similar to The price of similarity, or whether to say 'NO' to STL

A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency ConstructsTed Leung
 
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben EvansJava Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben EvansJAX London
 
Presentation systemc
Presentation systemcPresentation systemc
Presentation systemcSUBRAHMANYA S
 
Bt0066 database management system2
Bt0066 database management system2Bt0066 database management system2
Bt0066 database management system2Techglyphs
 
Domain oriented development
Domain oriented developmentDomain oriented development
Domain oriented developmentrajmundr
 
siemens-eda_technical-paper_the-missing-link-the-testbench-to-dut-connection.pdf
siemens-eda_technical-paper_the-missing-link-the-testbench-to-dut-connection.pdfsiemens-eda_technical-paper_the-missing-link-the-testbench-to-dut-connection.pdf
siemens-eda_technical-paper_the-missing-link-the-testbench-to-dut-connection.pdfssuser1c8ca21
 
A Domain-Specific Embedded Language for Programming Parallel Architectures.
A Domain-Specific Embedded Language for Programming Parallel Architectures.A Domain-Specific Embedded Language for Programming Parallel Architectures.
A Domain-Specific Embedded Language for Programming Parallel Architectures.Jason Hearne-McGuiness
 
[2017/2018] Architectural languages
[2017/2018] Architectural languages[2017/2018] Architectural languages
[2017/2018] Architectural languagesIvano Malavolta
 
Friends let real friends use MySQL 8.0
Friends let real friends use MySQL 8.0Friends let real friends use MySQL 8.0
Friends let real friends use MySQL 8.0SaverioM
 
[2016/2017] Architectural languages
[2016/2017] Architectural languages[2016/2017] Architectural languages
[2016/2017] Architectural languagesIvano Malavolta
 
AEM Clean Code - Miklos Csere
AEM Clean Code - Miklos Csere AEM Clean Code - Miklos Csere
AEM Clean Code - Miklos Csere Miklos Csere
 
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...Raffi Khatchadourian
 
P Training Presentation
P Training PresentationP Training Presentation
P Training PresentationGaurav Tyagi
 
Pretzel: optimized Machine Learning framework for low-latency and high throug...
Pretzel: optimized Machine Learning framework for low-latency and high throug...Pretzel: optimized Machine Learning framework for low-latency and high throug...
Pretzel: optimized Machine Learning framework for low-latency and high throug...NECST Lab @ Politecnico di Milano
 

Similar to The price of similarity, or whether to say 'NO' to STL (20)

Stl
StlStl
Stl
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency Constructs
 
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben EvansJava Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
 
Presentation systemc
Presentation systemcPresentation systemc
Presentation systemc
 
Stl
StlStl
Stl
 
Bt0066 database management system2
Bt0066 database management system2Bt0066 database management system2
Bt0066 database management system2
 
Domain oriented development
Domain oriented developmentDomain oriented development
Domain oriented development
 
SoC-2012-pres-2
SoC-2012-pres-2SoC-2012-pres-2
SoC-2012-pres-2
 
Stl dich
Stl dichStl dich
Stl dich
 
Aca2 10 11
Aca2 10 11Aca2 10 11
Aca2 10 11
 
siemens-eda_technical-paper_the-missing-link-the-testbench-to-dut-connection.pdf
siemens-eda_technical-paper_the-missing-link-the-testbench-to-dut-connection.pdfsiemens-eda_technical-paper_the-missing-link-the-testbench-to-dut-connection.pdf
siemens-eda_technical-paper_the-missing-link-the-testbench-to-dut-connection.pdf
 
A Domain-Specific Embedded Language for Programming Parallel Architectures.
A Domain-Specific Embedded Language for Programming Parallel Architectures.A Domain-Specific Embedded Language for Programming Parallel Architectures.
A Domain-Specific Embedded Language for Programming Parallel Architectures.
 
[2017/2018] Architectural languages
[2017/2018] Architectural languages[2017/2018] Architectural languages
[2017/2018] Architectural languages
 
Friends let real friends use MySQL 8.0
Friends let real friends use MySQL 8.0Friends let real friends use MySQL 8.0
Friends let real friends use MySQL 8.0
 
[2016/2017] Architectural languages
[2016/2017] Architectural languages[2016/2017] Architectural languages
[2016/2017] Architectural languages
 
AEM Clean Code - Miklos Csere
AEM Clean Code - Miklos Csere AEM Clean Code - Miklos Csere
AEM Clean Code - Miklos Csere
 
Microservices in Clojure
Microservices in ClojureMicroservices in Clojure
Microservices in Clojure
 
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 
Pretzel: optimized Machine Learning framework for low-latency and high throug...
Pretzel: optimized Machine Learning framework for low-latency and high throug...Pretzel: optimized Machine Learning framework for low-latency and high throug...
Pretzel: optimized Machine Learning framework for low-latency and high throug...
 

Recently uploaded

George Lever - eCommerce Day Chile 2024
George Lever -  eCommerce Day Chile 2024George Lever -  eCommerce Day Chile 2024
George Lever - eCommerce Day Chile 2024eCommerce Institute
 
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesVVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesPooja Nehwal
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...henrik385807
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Pooja Nehwal
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxraffaeleoman
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfhenrik385807
 
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night EnjoyCall Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night EnjoyPooja Nehwal
 
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )Pooja Nehwal
 
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Kayode Fayemi
 
SaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, YardstickSaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, Yardsticksaastr
 
Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Vipesco
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...Sheetaleventcompany
 
Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Chameera Dedduwage
 
Microsoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AIMicrosoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AITatiana Gurgel
 
Presentation on Engagement in Book Clubs
Presentation on Engagement in Book ClubsPresentation on Engagement in Book Clubs
Presentation on Engagement in Book Clubssamaasim06
 
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...Hasting Chen
 
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxNikitaBankoti2
 
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxMohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxmohammadalnahdi22
 
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779Delhi Call girls
 
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024eCommerce Institute
 

Recently uploaded (20)

George Lever - eCommerce Day Chile 2024
George Lever -  eCommerce Day Chile 2024George Lever -  eCommerce Day Chile 2024
George Lever - eCommerce Day Chile 2024
 
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesVVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
 
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night EnjoyCall Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
 
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
 
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
 
SaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, YardstickSaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, Yardstick
 
Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
 
Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)
 
Microsoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AIMicrosoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AI
 
Presentation on Engagement in Book Clubs
Presentation on Engagement in Book ClubsPresentation on Engagement in Book Clubs
Presentation on Engagement in Book Clubs
 
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
 
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
 
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxMohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
 
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
 
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
 

The price of similarity, or whether to say 'NO' to STL

  • 1. Intel Dynamic Execution Environments Symposium Collaborate Innovate Strategize Lead Session III: Productization Issues The price of similarity, or whether to say ‘NO’ to STL Anton Malakhov Alexey Kukanov Arch Robison
  • 2. 2 IDEES’09 Outline Why STL similarity? Related works Issues with STL semantics for concurrency A possible solution: Dual Interfaces Summary
  • 3. 3 IDEES’09 Why STL similarity?  STL is C++ standard, authority, and a role model  Many libraries try STL similarity for parallelism:  TBB, PPL, STAPL, PSTL, Range Partition Adapters, Thrust, Glift  But only TBB and PPL try to closely follow STL requirements for concurrent containers  Now, we can sum up this experience
  • 4. 4 IDEES’09 STL is incompatible with concurrency: lack of atomicity  C++ standard prescribes interfaces for efficient serial manipulation of containers item = queue.front(); // Get the first item queue.pop(); // Remove it from the queue  front() returns a reference to avoid overhead of return-by-value  Interface precludes safe concurrent manipulation  Two threads cannot grab items from the queue concurrently  front() and pop() operations might race in unfortunate ways  Race is induced by the interface and can not be fixed by any implementation technique from inside The interface is too orthogonal to maintain level of atomicity required for correctness
  • 5. 5 IDEES’09 STL is incompatible with concurrency: Control of lifetime and access  Destruction and deallocation of an element is only safe if all other threads are done accessing it  Supporting concurrent erase() and following STL semantics is not feasible for concurrent containers  How we  ppl::concurrent_unordered_map drops concurrent erase()  tbb::concurrent_hash_map introduces accessor • a smart pointer to prevent premature destruction STL lacks support for synchronizing object access and lifetime
  • 6. 6 IDEES’09 Strict STL similarity is inefficient: Decomposition vs. Merge  Decomposition of entities is a key STL principle  C++0x expectedly follows it class shared_ptr { atomic ops }; class mutex { atomic ops }; function F { ptr = shared_ptr; ptr->lock(); } // 2 atomic ops  Merge of entities can be optimized for efficiency class shared_lockable_ptr { atomic ops }; function F { ptr = shared_lockable_ptr.lock(); } // 1 atomic op The interface is too orthogonal to maintain level of atomicity required for efficiency
  • 7. 7 IDEES’09 STL is not efficient for concurrency: Iterators vs. Ranges  4 of 5 iterator kinds are inherently serial  Abstraction of pointer bumping  Enabling concurrency-safe iteration is tricky  Concurrent modifications can invalidate iterators  STL ranges only defined implicitly  Abstraction of a linear sequence: [first, last)  Carried dependency precludes efficient parallel iteration • Only random-access iterators allow it  Generic recursively divisible range would be better  E.g. enable scalable parallelism in breadth-first tree traversal STL abstracted a serial idiom unsuitable for parallel programming
  • 8. 8 IDEES’09 Concurrent interface is not efficient for serial usage  Objects can be used both in serial and in parallel  Due to data sharing between program stages  It’s also desirable to add parallelism incrementally  Concurrent interface can require code changes  Due to semantic differences discussed earlier  Contradictory to incremental parallelization  Serial performance can suffer  Traded for better concurrency in implementations  Impacted by synchronization overhead (even without contention) Enabling concurrency imposes additional cost even to serial stages of a program
  • 9. 9 IDEES’09 Concurrency as an STL extension: The root of the problems  STL similarity bends concurrent interface  Concurrency is afterthought for serial world of STL?  Concurrency puts pressure on serial code  Undesired impact of parallelism adoption  Separate the interfaces  Release from straitjackets! STL requirements and principles STL-like class { Serial methods }; Concurrent methods Parallel principles Serial Parallel execution Serial Object lifetime
  • 10. 10 IDEES’09 Dual Interfaces  Same data structure, two interfaces  Concurrent and serial views  STL compatibility  Enables smooth migration  Enabled efficiency  Concurrent interface drops burden of STL similarity  Serial performance is available with serial interface Parallel principles and practices class ConcurrentFoo { Concurrent methods SerialViewOfFoo serial() }; STL requirements and principles class SerialViewOfFoo { Serial methods, up to 100% STL compatible! };
  • 11. 11 IDEES’09 Dual interfaces: the silver bullet?  Writing “concurrent”, thinking “STL”  Some C++ developers still expect STL behavior or guarantees • An example: • Const methods are expected to do no visible modification • Modifications might be undetectable by concurrent interface • BUT still visible by serial interface, e.g. as broken iterators  Can indirectly affect concurrent interface and implementation  Additional burden on users  Bigger “surface area” to learn  Special rules to remember & follow • E.g. switch between interfaces – when and how?  Will mainstream customers buy in the idea? Solves the problems but puts new questions
  • 12. 12 IDEES’09 Summary  STL compatibility is important for customers  STL similarity in concurrent interface has problems  Principles of STL and concurrency contradict  Separate interfaces for serial and concurrent access to the same object can do better  Still some questions remain open
  • 14. 14 IDEES’09 Dual interfaces: composability rules  General rule is: “Do not mix concurrent and serial interfaces”  Interfaces are not compatible with each other anyway  It enables smooth migration and efficiency  Only one reference using only one type must be passed to a function  If callers are unknown • Don’t switch interfaces inside  If subroutine is unknown • Don’t switch interfaces during its runtime  For mixed interface, composability is worse  It is unknown what interface to use  Or use concurrent by default, but • The whole access code must be changed • Serial code loses efficiency • e.g. in const-serial-access of a huge parallel region //Thread-safe R/W ConcurrentFoo crw; //Thread-safe R/O const SerialFoo cro; //Serial R/W SerialFoo srw;
  • 15. 15 IDEES’09 Links  Many libraries try STL similarity for parallelism:  TBB and PPL  STAPL  PSTL  Range Partition Adapters  Thrust: NVIDIA's STL  Glift