QDP++
qdp_dispatch.h
Go to the documentation of this file.
1#ifndef QDP_DISPATCH_H
2#define QDP_DISPATCH_H
3
4#include "qdp_diagnostics.h"
5
6#include "qdp_config.h"
7
8#if defined(QDP_USE_OMP_THREADS)
9QDPXX_MESSAGE("QDP using OpenMP threading")
10#include <omp.h>
11namespace QDP {
12/* OpenMP threading version of the dispatch.*/
13
14
15 inline
16 int qdpNumThreads()
17 {
18 return omp_get_max_threads();
19 }
20
21
22 inline
23 int qdpThreadNum()
24 {
25 return omp_get_thread_num();
26 }
27
28
29template<class Arg>
30void dispatch_to_threads(int numSiteTable, Arg a, void (*func)(int,int,int, Arg*)){
31
32
33#pragma omp parallel shared(numSiteTable, a)
34 {
35
36 int threads_num = omp_get_num_threads();
37 int myId = omp_get_thread_num();
38
39 int active_threads_num = threads_num > numSiteTable ? numSiteTable : threads_num;
40
41 if( myId < numSiteTable ) {
42 int low = (numSiteTable*myId)/active_threads_num;
43
44 // NB: high can never be too high since for the last thread
45 // myId + 1 = (threads_num - 1) + 1 = threads_num.
46 // So numSiteTable*(myId+1) will always be a strict multiple of threads_num
47 // and so truncation issues will not bite.
48 // I am addig in the parentheses tho to force the precedence
49 int high =(numSiteTable*(myId+1))/active_threads_num;
50
51 func(low, high, myId, &a);
52 }
53 }
54}
55}
56
57#else
58
59#if defined(QDP_USE_QMT_THREADS)
60QDPXX_MESSAGE("QDP using QMT threading")
61
62 /* QMT threading version of the dispatch. Call the qmt_call routine
63 with userfunc, numSiteTable, and argument */
64
65#include <qmt.h>
66
67namespace QDP {
68
69 inline
70 int qdpNumThreads()
71 {
72 return qmt_num_threads();
73 }
74
75 inline
76 int qdpThreadNum()
77 {
78 return qmt_thread_num();
79 }
80
81
82template<class Arg>
83void dispatch_to_threads(int numSiteTable, Arg a, void (*func)(int,int,int,Arg*)){
84
85 qmt_call((qmt_userfunc_t)func, numSiteTable, &a);
86
87}
88}
89#else
90namespace QDP {
91
92 inline
94 {
95 return 1;
96 }
97
98 inline
100 {
101 return 0;
102 }
103
104template<class Arg>
105void dispatch_to_threads(int numSiteTable, Arg a, void (*func)(int,int,int,Arg*)){
106
107 int low = 0;
108 int high = numSiteTable;
109
110 func(low, high, 0, &a);
111
112 }
113
114}
115#endif
116#endif
117
118#endif
Yet another random number generator.
void dispatch_to_threads(int numSiteTable, Arg a, void(*func)(int, int, int, Arg *))
int qdpThreadNum()
int qdpNumThreads()
#define QDPXX_MESSAGE(s)