OpenMP parallelisation of linked list

Hello friends of C/C++,

I am a beginner in OpenMp which I use to parallelise my numerical simulations code. I am working on particle based simulations with a non-constant number of particles (particles can be "created" or "killed").
To avoid reallocation of memory I allocate a huge container in the beginning,
 
double* particle_data = new double[LargeUpperBound];

and save the information about the indices of the currently "dead" particles in a linked list.
Assume we have ten particles, first 3 are living, rest is dead, my list looks like this:
1
2
i      : 0  1  2  3  4  5  6  7  8  9
list[i]: -1 -1 -1 4  5  6  7  8  9  -2

The sentinel would point to 3, "-1" indicates occupation, "-2" the end of the list.
This list is very convenient to sequentially "create" or "delete" particles in my simulations without reallocation or copy operations. I only need to rewire my list a little bit.
Creating/Killing looks then like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
for(int i = 0; i < MaxOccupiedIndex; ++i)
{

if(list[i]==-1) // particle exists
{
if(KillCondition(i))
{
 KillParticle(i);
}

// creation branch in another loop would like like this:
// if(CreateCondition(i))
// {
// 		CreateNewParticleAt(i);
// }

}

}

Now I struggle a little bit to parallelise this idea. Every thread needs to know about a subset of indices of
(1) occupied slots (living particles, operations are performed on these)
(2) free slots (to put newly created particles in)
which is disjoint to the sets of all other threads. The subsets should be approximately of the same size for every thread to guarantee equal workload.

My idea so far was to create a second linked list for tracking the living particles and then to chop the lists into chunks which are then distributed to the threads. However, this involves much bookkeeping and I am not sure how to do it efficient.

I do not stick to the linked list implementation, so my questions are
(1) Can you think of a different approach to solve this problem ?
(2) How would you parallelise your solution using OpenMP ?

Thanks in advance!
Last edited on
Topic archived. No new replies allowed.