4 #ifndef ASTSHAREDMEMORYPARALLELPROCESSING_C
5 #define ASTSHAREDMEMORYPARALLELPROCESSING_C
13 #pragma message ("Error: pthread.h is unavailable on MSVC, we might want to use boost.thread library.")
25 template <
class I,
class S>
32 visitedNodes(0), runningParallelTraversal(false),
33 synchronizationWindowSize(syncInfo.synchronizationWindowSize)
37 template <
class I,
class S>
44 template <
class I,
class S>
60 template <
class I,
class S>
79 template <
class I,
class S>
90 : traversal(traversal), basenode(basenode), inheritedValues(inheritedValues)
99 template <
class I,
class S>
114 return traversal->
traverse(basenode, inheritedValues);
117 template <
class I,
class S>
124 const typename Superclass::TraversalPtrList &traversals = Superclass::traversals;
126 size_t numberOfTraversals = traversals.size();
134 std::vector<InheritedAttributeTypeList *> parallelInheritedValues(numberOfThreads);
135 size_t begin = 0, end;
136 for (i = 0; i < numberOfThreads; i++)
138 end = begin + numberOfTraversals / numberOfThreads;
139 if (end > numberOfTraversals)
140 end = numberOfTraversals;
142 parallelTraversals[i]
144 std::vector<TraversalPtr>(traversals.begin() + begin, traversals.begin() + end));
145 parallelInheritedValues[i]
147 inheritedValues->begin() + begin, inheritedValues->begin() + end);
154 pthread_t *threads =
new pthread_t[numberOfThreads];
155 for (i = 0; i < numberOfThreads; i++)
157 pthread_create(&threads[i], NULL,
158 parallelTopDownBottomUpProcessingThread<I, S>,
160 parallelTraversals[i], basenode, parallelInheritedValues[i]));
166 pthread_mutex_lock(syncInfo.
mutex);
169 pthread_mutex_unlock(syncInfo.
mutex);
172 std::vector<SynthesizedAttributeTypeList *> finalResults(numberOfThreads);
173 for (i = 0; i < numberOfThreads; i++)
174 pthread_join(threads[i], (
void **) &finalResults[i]);
180 for (i = 0; i < numberOfThreads; i++)
181 std::copy(finalResults[i]->begin(), finalResults[i]->end(), std::back_inserter(*flatFinalResults));
184 return flatFinalResults;
187 template <
class I,
class S>
189 : numberOfThreads(2), synchronizationWindowSize(100000)
193 template <
class I,
class S>
200 template <
class I,
class S>
208 numberOfThreads = threads;
212 template <
class I,
class S>
220 synchronizationWindowSize = windowSize;
233 visitedNodes(0), runningParallelTraversal(false),
234 synchronizationWindowSize(syncInfo.synchronizationWindowSize)
291 : traversal(traversal), basenode(basenode), inheritedValues(inheritedValues)
315 traversal->
traverse(basenode, inheritedValues);
329 size_t numberOfTraversals = traversals.size();
337 std::vector<InheritedAttributeTypeList *> parallelInheritedValues(numberOfThreads);
338 size_t begin = 0, end;
339 for (i = 0; i < numberOfThreads; i++)
341 end = begin + numberOfTraversals / numberOfThreads;
342 if (end > numberOfTraversals)
343 end = numberOfTraversals;
345 parallelTraversals[i]
347 std::vector<TraversalPtr>(traversals.begin() + begin, traversals.begin() + end));
348 parallelInheritedValues[i]
350 inheritedValues->begin() + begin, inheritedValues->begin() + end);
356 pthread_t *threads =
new pthread_t[numberOfThreads];
357 for (i = 0; i < numberOfThreads; i++)
359 pthread_create(&threads[i], NULL,
360 parallelTopDownProcessingThread<I>,
362 parallelTraversals[i], basenode, parallelInheritedValues[i]));
368 pthread_mutex_lock(syncInfo.
mutex);
371 pthread_mutex_unlock(syncInfo.
mutex);
374 std::vector<void *> finalResults(numberOfThreads);
375 for (i = 0; i < numberOfThreads; i++)
376 pthread_join(threads[i], &finalResults[i]);
384 : numberOfThreads(2), synchronizationWindowSize(100000)
403 numberOfThreads = threads;
415 synchronizationWindowSize = windowSize;
428 visitedNodes(0), runningParallelTraversal(false),
429 synchronizationWindowSize(syncInfo.synchronizationWindowSize)
484 : traversal(traversal), basenode(basenode)
506 return traversal->
traverse(basenode);
513 const typename Superclass::TraversalPtrList &traversals = Superclass::traversals;
515 size_t numberOfTraversals = traversals.size();
523 size_t begin = 0, end;
524 for (i = 0; i < numberOfThreads; i++)
526 end = begin + numberOfTraversals / numberOfThreads;
527 if (end > numberOfTraversals)
528 end = numberOfTraversals;
530 parallelTraversals[i]
532 std::vector<TraversalPtr>(traversals.begin() + begin, traversals.begin() + end));
537 pthread_t *threads =
new pthread_t[numberOfThreads];
538 for (i = 0; i < numberOfThreads; i++)
540 pthread_create(&threads[i], NULL,
541 parallelBottomUpProcessingThread<S>,
543 parallelTraversals[i], basenode));
549 pthread_mutex_lock(syncInfo.
mutex);
552 pthread_mutex_unlock(syncInfo.
mutex);
555 std::vector<SynthesizedAttributeTypeList *> finalResults(numberOfThreads);
556 for (i = 0; i < numberOfThreads; i++)
557 pthread_join(threads[i], (
void **) &finalResults[i]);
562 for (i = 0; i < numberOfThreads; i++)
563 std::copy(finalResults[i]->begin(), finalResults[i]->end(), std::back_inserter(*flatFinalResults));
566 return flatFinalResults;
571 : numberOfThreads(2), synchronizationWindowSize(100000)
590 numberOfThreads = threads;
602 synchronizationWindowSize = windowSize;