Originally Posted by
überfuzz
Maybe i was unclear... Each thread is deleting entries in the assigned array interval. Well lets say Im interested in what to do after the code you posted.
I think ill go with memcpy. Ill monitor how many undeleted elements each thread puts into the local array so that i know how much to copy into the global array. Hmm, yea something like that would probably work...
OK, You have a "master" array of 12 numbers: master[12].
1,2,3,4,5,6,7,8,9,10,11,12
Each of 4 threads, will work with 3 numbers.
#1 thread will delete even numbers 1-3
#2 thread will delete odd numbers 4-6
#3 thread will delete the lowest number 7-9
#4 thread will delete the highest number 10-12
Final master[] now has:
1,3,4,6,8,9,10,11.
The only question is how to deal with the "deleted" numbers.
One way:
#define NIL -999 (some totally impossible value for your data). Replace the deleted numbers, with NIL, and set up your later functions to ignore NIL values - don't do computations or display them. Just adds one line to your print loop, for instance.
Code:
for(i=0;i<12;i++) {
if(master[i] != NIL)
printf("%d \n",master[i]);
}
Another way to do it:
Copy all the non-NIL values, to another array.
Another way:
Move the remaining numbers down to overwrite the deleted numbers, then work with only the 8 remaining numbers master[0] through master[7], in the case above.
This could be done inside the same loop that deletes numbers (just adds one extra variable to the loop to record the correct next [index] that will be over-written. It could also be done in a later loop (simpler but less effecient).