TraverseParallel.h 2.48 KB
Newer Older
1
2
3
4
5
6
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
7
// ==  TU Dresden                                                            ==
8
// ==                                                                        ==
9
10
11
// ==  Institut fr Wissenschaftliches Rechnen                               ==
// ==  Zellescher Weg 12-14                                                  ==
// ==  01069 Dresden                                                         ==
12
13
14
15
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
16
// ==  https://gforge.zih.tu-dresden.de/projects/amdis/                      ==
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// ==                                                                        ==
// ============================================================================

/** \file TraverseParallel.h */

#ifndef AMDIS_TRAVERSEPARALLEL_H
#define AMDIS_TRAVERSEPARALLEL_H

#ifdef _OPENMP

#include "OpenMP.h"
#include "Traverse.h"
#include <vector>

namespace AMDiS {

  /** \ingroup Traverse
   * \brief
   */
  class TraverseParallelStack 
  {
  public: 
39
    TraverseParallelStack(int nThreads = 0, int mode = 0);
40
41
42
43
44

    ~TraverseParallelStack();

    ElInfo* traverseFirst(Mesh *mesh, int level, Flag fill_flag);

45
    inline ElInfo* traverseNext(ElInfo* elInfoOld) 
46
    {
47
48
49
      if (parallelMode == 0) {
	return stacks[omp_get_thread_num()]->traverseNext(elInfoOld);
      } else {
50
51
52
53
54
55
56
	ElInfo *elInfo = stacks[omp_get_thread_num()]->traverseNext(elInfoOld);
	while (elInfo &&
	       elInfo->getElement()->getIndex() % nThreads != omp_get_thread_num()) {
	  elInfo = stacks[omp_get_thread_num()]->traverseNext(elInfo);
	}
	return elInfo;
      }      
57
58
59
    }

  private:
60
    /// Number of threads using the stack in parallel.
61
    int nThreads;
62

63
64
    int parallelMode;

65
    std::vector<TraverseStack*> stacks;
66
67
68
69
70
71
72
73
  };

}

#endif  // _OPENMP

#endif  // AMDIS_TRAVERSEPARALLEL_H