Comments (8)
Good to know! And thanks again for this awesome work and all your help!
from parallel-hashmap.
Yes, if the map is not modified, it is perfectly safe to check whether it contains keys from multiple threads.
from parallel-hashmap.
Thanks Greg! Another question please: if I have a lot of (tens of millions maybe) simple <int, int>
pairs to insert into a hash map, is it a good idea to use a parallel_flat_hash_map
and insert using multiple threads? My concern is that the number of data to insert is huge, and a single insert operation is lightweight, which may make the mutex lock a overhead.
from parallel-hashmap.
Sure, it still would be much faster to use a parallel_flat_hash_map
and multiple threads, just make the N
template parameter larger than the default 4
, maybe 10
or something, and there will be very little mutex contention.
Another possibility. Where are all those pairs you want to insert coming from? If you can iterate very quickly over them, you can actually insert in a parallel_flat_hash_map
without locking at all.
from parallel-hashmap.
Another possibility. Where are all those pairs you want to insert coming from? If you can iterate very quickly over them, you can actually insert in a
parallel_flat_hash_map
without locking at all.
Hmm... I have an array storing m
offsets of a file. What I want to do is iterate over the array, read some bytes starting at the offset into memory, then store the pair <offset, index>
in the map. So I don't think it can be done quickly. But how can iterating quickly make the insertion lock-free anyway?
from parallel-hashmap.
Actually that would work well. The parallel-flat-hash internally has an array of submaps (When N=4 you have 16 submaps).
What you would do is start 16 threads, and each thread would populate its own submap (thread # 0 populate submap 0, etc.....
So each thread would:
- iterate over all the offsets in the file.
- for each offset, check which submap it would go to (using the submap function).
If not its target submap, it would do nothing.
If it is, it would read some bytes starting at the offset into memory, then store the pair <offset, index> in the map.
that's it, no locking necessary.
This is what the bench does here. I really should write a better example.
from parallel-hashmap.
That's cool! By the way, when using a lock-free parallel hash map, is there a difference among insertion methods, like operator[]/insert/emplace?
from parallel-hashmap.
If you use the method I indicated above, use emplace_with_hash
so you pass the hashval and it is not recomputed. Otherwise it doesn't make much difference when you insert a pair of integers.
from parallel-hashmap.
Related Issues (20)
- LLDB pretty-printer is buggy HOT 2
- Avoid Memory Reallocations in flat_hash_map clear for Trivial Classes HOT 3
- Suggestion: lazy_emplace_l without last argument HOT 12
- Unused variable warning HOT 2
- question about performance of `at(...)` HOT 4
- Iteration Order Differs on Arm64 Architecture HOT 4
- Very minor optimization: _mm_abs_epi8 instead of _mm_sign_epi8 HOT 1
- Slow in a specific case HOT 20
- asan build on linux failed with memory error HOT 3
- In template: constexpr variable 'kFirst' must be initialized by a constant expression HOT 6
- phmap_dump saving a lot more than needed HOT 4
- is it possible to miss the necessary .cmake in the conda packaging? HOT 1
- nvc++: integer conversion resulted in a change of sign HOT 9
- Need a tag about `reserve` bug HOT 3
- Need help speeding up large hash map HOT 6
- merging maps HOT 8
- Release memory after shrinking HOT 6
- Memory not reclaimed after calling map.clear() HOT 4
- Ability to reset the inner sub map HOT 64
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from parallel-hashmap.