Merging revisions 14838-14945 of https://svn.blender.org/svnroot/bf-blender/trunk...
[blender.git] / intern / elbeem / intern / loop_tools.h
1
2 // advance pointer in main loop
3 #define ADVANCE_POINTERS(p)     \
4         ccel += (QCELLSTEP*(p));        \
5         tcel += (QCELLSTEP*(p));        \
6         pFlagSrc+= (p); \
7         pFlagDst+= (p); \
8         i+= (p);
9
10 #define MAX_CALC_ARR 4
11
12 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
13 // init region vars
14 #define  GRID_REGION_INIT()   \
15         const int istart = -1+gridLoopBound; \
16         const int iend   = mLevel[mMaxRefine].lSizex-1-gridLoopBound; \
17         LbmFloat calcCurrentMass=0; \
18         LbmFloat calcCurrentVolume=0; \
19         int      calcCellsFilled=0; \
20         int      calcCellsEmptied=0; \
21         int      calcNumUsedCells=0; \
22
23
24
25
26 //  -----------------------------------------------------------------------------------
27 // serial stuff
28 #if PARALLEL!=1
29
30 #define PERFORM_USQRMAXCHECK USQRMAXCHECK(usqr,ux,uy,uz, mMaxVlen, mMxvx,mMxvy,mMxvz);
31 #define LIST_EMPTY(x) mListEmpty.push_back( x );
32 #define LIST_FULL(x)  mListFull.push_back( x );
33 #define FSGR_ADDPART(x)  mpParticles->addFullParticle( x );
34
35 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
36 #define  GRID_REGION_START()  \
37 { /* main_region */ \
38         int kstart=getForZMinBnd(), kend=getForZMaxBnd(mMaxRefine); \
39         if(gridLoopBound>0){ kstart=getForZMin1(), kend=getForZMax1(mMaxRefine); } \
40         int kdir = 1; \
41         int jstart = gridLoopBound; \
42         int jend   = mLevel[mMaxRefine].lSizey-gridLoopBound; \
43         const int id=0; \
44         LbmFloat *ccel = NULL, *tcel = NULL; \
45         CellFlagType *pFlagSrc=NULL, *pFlagDst=NULL; \
46         if(mLevel[mMaxRefine].setCurr==1) { \
47         kdir = -1; \
48         int temp = kend; \
49         kend = kstart-1; \
50         kstart = temp-1; \
51         temp = id; /* dummy remove warning */ \
52 } \
53
54
55
56         
57
58 //  -----------------------------------------------------------------------------------
59 #else // PARALLEL==1
60
61 //#include "paraloop.h"
62 #define PERFORM_USQRMAXCHECK USQRMAXCHECK(usqr,ux,uy,uz, calcMaxVlen, calcMxvx,calcMxvy,calcMxvz);
63 #define LIST_EMPTY(x)    calcListEmpty.push_back( x );
64 #define LIST_FULL(x)     calcListFull.push_back( x );
65 #define FSGR_ADDPART(x)  calcListParts.push_back( x );
66
67
68 // parallel region
69 //was: # pragma omp parallel default(shared) 
70 #if COMPRESSGRIDS!=1
71         // requires compressed grids...!
72         ERROR!
73 #endif
74
75 // loop start
76 #define  GRID_REGION_START()  \
77 { \
78          \
79          \
80         if(mSizez<2) { \
81         mPanic = 1; \
82         errFatal("ParaLoop::2D","Not valid...!", SIMWORLD_GENERICERROR); \
83 } \
84          \
85          \
86         vector<LbmPoint> calcListFull; \
87         vector<LbmPoint> calcListEmpty; \
88         vector<ParticleObject> calcListParts; \
89         LbmFloat calcMxvx, calcMxvy, calcMxvz, calcMaxVlen; \
90         calcMxvx = calcMxvy = calcMxvz = calcMaxVlen = 0.0; \
91         calcListEmpty.reserve(mListEmpty.capacity() / omp_get_num_threads() ); \
92         calcListFull.reserve( mListFull.capacity()  / omp_get_num_threads() ); \
93         calcListParts.reserve(mSizex); \
94          \
95          \
96         const int id = omp_get_thread_num(); \
97         const int Nthrds = omp_get_num_threads(); \
98          \
99          \
100          \
101          \
102          \
103         int kdir = 1; \
104          \
105         int kstart=getForZMinBnd(), kend=getForZMaxBnd(mMaxRefine); \
106         if(gridLoopBound>0){ kstart=getForZMin1(); kend=getForZMax1(mMaxRefine); } \
107         LbmFloat *ccel = NULL, *tcel = NULL; \
108         CellFlagType *pFlagSrc=NULL, *pFlagDst=NULL; \
109          \
110          \
111         if(mLevel[mMaxRefine].setCurr==1) { \
112         kdir = -1; \
113         int temp = kend; \
114         kend = kstart-1; \
115         kstart = temp-1; \
116 } \
117          \
118         const int Nj = mLevel[mMaxRefine].lSizey; \
119         int jstart = 0+( id * (Nj / Nthrds) ); \
120         int jend   = 0+( (id+1) * (Nj / Nthrds) ); \
121         if( ((Nj/Nthrds) *Nthrds) != Nj) { \
122         errMsg("LbmFsgrSolver","Invalid domain size Nj="<<Nj<<" Nthrds="<<Nthrds); \
123 } \
124          \
125         if(jstart<gridLoopBound) jstart = gridLoopBound; \
126         if(jend>mLevel[mMaxRefine].lSizey-gridLoopBound) jend = mLevel[mMaxRefine].lSizey-gridLoopBound; \
127          \
128         debMsgStd("ParaLoop::OMP",DM_MSG,"Thread:"<<id<<" i:"<<istart<<"-"<<iend<<" j:"<<jstart<<"-"<<jend<<", k:"<<kstart<<"-"<<kend<<"  ", 1); \
129          \
130
131
132
133
134 // para GRID LOOP END is parainc3 
135
136 #endif // PARALLEL==1
137
138
139 //  -----------------------------------------------------------------------------------
140
141 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
142 #define  GRID_LOOP_START()   \
143         for(int k=kstart;k!=kend;k+=kdir) { \
144         pFlagSrc = &RFLAG(lev, istart, jstart, k, SRCS(lev)); \
145         pFlagDst = &RFLAG(lev, istart, jstart, k, TSET(lev)); \
146         ccel = RACPNT(lev,     istart, jstart, k, SRCS(lev)); \
147         tcel = RACPNT(lev,     istart, jstart, k, TSET(lev)); \
148         for(int j=jstart;j!=jend;++j) { \
149         /* for(int i=0;i<mLevel[lev].lSizex-2;   ) { */ \
150         for(int i=istart;i!=iend;   ) { \
151         ADVANCE_POINTERS(1); \
152
153
154
155
156 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
157 #define  GRID_LOOPREG_END()  \
158          \
159 } /* i */ \
160         int i=0; \
161         ADVANCE_POINTERS(2*gridLoopBound); \
162 } /* j */ \
163         /* COMPRESSGRIDS!=1 */ \
164         /* int i=0;  */ \
165         /* ADVANCE_POINTERS(mLevel[lev].lSizex*2);  */ \
166 } /* all cell loop k,j,i */ \
167         if(doReduce) { } /* dummy remove warning */ \
168 } /* main_region */ \
169          \
170
171
172
173
174 // old loop for COMPRESSGRIDS==0
175 #define old__GRID_LOOP_START() \
176   for(int k=kstart;k<kend;++k) { \
177           for(int j=1;j<mLevel[lev].lSizey-1;++j) { \
178                 for(int i=0;i<mLevel[lev].lSizex-2;   ) {
179
180