[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12677] branches/cloth/blender/intern/ elbeem/intern: New feature: Fluids internal subdiv (level >=2) uses OpenMP now

Daniel Genrich daniel.genrich at gmx.net
Mon Nov 26 03:41:07 CET 2007


Revision: 12677
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12677
Author:   genscher
Date:     2007-11-26 03:41:06 +0100 (Mon, 26 Nov 2007)

Log Message:
-----------
New feature: Fluids internal subdiv (level >=2) uses OpenMP now

Modified Paths:
--------------
    branches/cloth/blender/intern/elbeem/intern/isosurface.cpp
    branches/cloth/blender/intern/elbeem/intern/loop_tools.h

Modified: branches/cloth/blender/intern/elbeem/intern/isosurface.cpp
===================================================================
--- branches/cloth/blender/intern/elbeem/intern/isosurface.cpp	2007-11-26 01:52:48 UTC (rev 12676)
+++ branches/cloth/blender/intern/elbeem/intern/isosurface.cpp	2007-11-26 02:41:06 UTC (rev 12677)
@@ -18,6 +18,10 @@
 #define round(x) (x)
 #endif
 
+#if PARALLEL==1	
+#include <omp.h>
+#endif
+
 /******************************************************************************
  * Constructor
  *****************************************************************************/
@@ -132,7 +136,7 @@
 {
   double gsx,gsy,gsz; // grid spacing in x,y,z direction
   double px,py,pz;    // current position in grid in x,y,z direction
-  // IsoLevelCube cubie;    // struct for a small subcube
+  IsoLevelCube cubie;    // struct for a small subcube
 	myTime_t tritimestart = getTime(); 
 
 	if(!mpData) {
@@ -327,6 +331,16 @@
 				(   (fi))*(1.-(fj))*(   (fk))*orgval[5] + \
 				(   (fi))*(   (fj))*(   (fk))*orgval[6] + \
 				(1.-(fi))*(   (fj))*(   (fk))*orgval[7] )
+	
+#if PARALLEL==1
+#define LIST_POINT(x) calcPoints.push_back(x);
+#define LIST_POINT_SIZE calcPoints.size()
+#define LIST_INDEX(x) calcIndices.push_back(x);
+#else
+#define LIST_POINT(x) mPoints.push_back(x);
+#define LIST_POINT_SIZE mPoints.size()
+#define LIST_INDEX(x) mIndices.push_back(x);
+#endif
 
 		// use subdivisions
 		gfxReal subdfac = 1./(gfxReal)(mSubdivs);
@@ -400,12 +414,31 @@
 
 		debMsgStd("IsoSurface::triangulate",DM_MSG,"Starting. Parts in use:"<<pInUse<<", Subdivs:"<<mSubdivs, 9);
 		pz = mStart[2]-(double)(0.*gsz)-0.5*orgGsz;
+#if PARALLEL==1	
+#pragma omp parallel default(shared)
+{
+	vector<IsoLevelVertex> calcPoints;
+	vector<unsigned int> calcIndices;
+	const int id = omp_get_thread_num(); 
+	const int Nthrds = omp_get_num_threads(); 
+	
+	const int Nj = (mSizey-2);
+	
+	int jstart = 0+( id * (Nj / Nthrds) ); 
+	int jend   = 0+( (id+1) * (Nj / Nthrds) );
+
+	if(jstart<1) jstart = 1; 
+	if(jend>(mSizey-2)) jend = (mSizey-2); 
+#else
+	int jstart = 1; 
+	int jend   = (mSizey-2);
+#endif		
+	
 		for(int ok=1;ok<(mSizez-2)*mSubdivs;ok++) {
 			pz += gsz;
 			const int k = ok/mSubdivs;
 			if(k<=0) continue; // skip zero plane
-#pragma omp parallel for
-			for(int j=1;j<(mSizey-2);j++) {
+			for(int j=jstart;j<jend;j++) {
 				for(int i=1;i<(mSizex-2);i++) {
 					float value[8];
 					ntlVec3Gfx pos[8];
@@ -582,11 +615,8 @@
 
 										// init isolevel vertex
 										ilv.v = p1 + (p2-p1)*mu; // with subdivs
-#pragma omp critical 
-										{
-										mPoints.push_back( ilv );
-										triIndices[e] = (mPoints.size()-1);
-										}
+										LIST_POINT( ilv );
+										triIndices[e] = (LIST_POINT_SIZE-1);
 										// store vertex 
 										*eVert[ e ] = triIndices[e]; 
 									}	else {
@@ -596,24 +626,26 @@
 								} // along all edges 
 							}
 							// removed cutoff treatment...
-#pragma omp critical 
-							{
+							
 							// Create the triangles... 
 							for(int e=0; mcTriTable[cubeIndex][e]!=-1; e+=3) {
-								mIndices.push_back( triIndices[ mcTriTable[cubeIndex][e+0] ] );
-								mIndices.push_back( triIndices[ mcTriTable[cubeIndex][e+1] ] ); // with subdivs
-								mIndices.push_back( triIndices[ mcTriTable[cubeIndex][e+2] ] );
+								LIST_INDEX( triIndices[ mcTriTable[cubeIndex][e+0] ] );
+								LIST_INDEX( triIndices[ mcTriTable[cubeIndex][e+1] ] ); // with subdivs
+								LIST_INDEX( triIndices[ mcTriTable[cubeIndex][e+2] ] );
 								//errMsg("TTT"," i1"<<mIndices[mIndices.size()-3]<<" "<< " i2"<<mIndices[mIndices.size()-2]<<" "<< " i3"<<mIndices[mIndices.size()-1]<<" "<< mIndices.size() );
+							} // triangles in edge table?
 							}
-							}
-							} // triangles in edge table?
 							
 						}//si
 					}// sj
 
 				}//i
 			}// j
+#if PARALLEL==1	
 #pragma omp barrier
+#pragma omp critical 
+#endif
+			{
 			// copy edge arrays
 			for(int j=0;j<(mSizey-0)*mSubdivs;j++) 
 				for(int i=0;i<(mSizex-0)*mSubdivs;i++) {
@@ -627,10 +659,27 @@
 					mpEdgeVerticesY[ src ]=-1; // with subdivs
 					mpEdgeVerticesZ[ src ]=-1;
 				}
+			}
 			// */
 
 		} // ok, k subdiv loop
-
+#if PARALLEL==1	
+#pragma omp critical
+		{
+			unsigned int size = mPoints.size();
+			
+			// remap indices
+			for(unsigned int j=0; j<calcIndices.size(); j++) 
+			{
+				mIndices.push_back(calcIndices[j]+size);
+			}
+			for(unsigned int j=0; j<calcPoints.size(); j++) 
+			{
+				mPoints.push_back(calcPoints[j]);
+			}	
+		}
+}
+#endif
 		//delete [] subdAr;
 		delete [] arppnt;
 		computeNormals();

Modified: branches/cloth/blender/intern/elbeem/intern/loop_tools.h
===================================================================
--- branches/cloth/blender/intern/elbeem/intern/loop_tools.h	2007-11-26 01:52:48 UTC (rev 12676)
+++ branches/cloth/blender/intern/elbeem/intern/loop_tools.h	2007-11-26 02:41:06 UTC (rev 12677)
@@ -91,8 +91,8 @@
 	calcListEmpty.reserve(mListEmpty.capacity() / omp_get_num_threads() ); \
 	calcListFull.reserve( mListFull.capacity()  / omp_get_num_threads() ); \
 	calcListParts.reserve(mSizex); \
-	printf("omp_get_num_threads: %d\n", omp_get_num_threads()); \
 	 \
+	 \
 	const int id = omp_get_thread_num(); \
 	const int Nthrds = omp_get_num_threads(); \
 	 \





More information about the Bf-blender-cvs mailing list