yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #10558
[Branch ~yade-pkg/yade/git-trunk] Rev 3831: Parallelize replaceByClumps(): drastically reduce generation time of clump replacement if discret...
------------------------------------------------------------
revno: 3831
committer: Christian Jakob <jakob@xxxxxxxxxxxxxxxxxxx>
timestamp: Fri 2014-02-28 17:34:58 +0100
message:
Parallelize replaceByClumps(): drastically reduce generation time of clump replacement if discretization>0
modified:
py/wrapper/yadeWrapper.cpp
--
lp:yade
https://code.launchpad.net/~yade-pkg/yade/git-trunk
Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-pkg/yade/git-trunk/+edit-subscription
=== modified file 'py/wrapper/yadeWrapper.cpp'
--- py/wrapper/yadeWrapper.cpp 2014-02-27 08:27:24 +0000
+++ py/wrapper/yadeWrapper.cpp 2014-02-28 16:34:58 +0000
@@ -315,7 +315,17 @@
}
//adapt position- and radii-informations and replace spheres from bpListTmp by clumps:
+ omp_lock_t locker;
+ #ifdef YADE_OPENMP
+ omp_init_lock(&locker);//since bodies are created and deleted in following sections, it is neccessary to lock critical parts of the code (avoid seg fault)
+ #pragma omp parallel for schedule(dynamic) shared(locker)
+ for(int i=0; i<numReplaceTmp; i++) {
+ while (! omp_test_lock(&locker)) usleep(1);
+ const shared_ptr<Body>& b = bpListTmp[i];
+ LOG_DEBUG("replaceByClumps: Started processing body "<<bpListTmp[i]->id<<" in parallel ...");
+ #else
FOREACH (const shared_ptr<Body>& b, bpListTmp) {
+ #endif
//get sphere, that should be replaced:
const Sphere* sphere = YADE_CAST<Sphere*> (b->shape.get());
shared_ptr<Material> matTmp = b->material;
@@ -359,6 +369,8 @@
LOG_DEBUG("New body (sphere) "<<newSphere->id<<" added.");
idsTmp[jj] = newSphere->id;
}
+ //cout << "thread " << omp_get_thread_num() << " unsets locker" << endl;
+ omp_unset_lock(&locker);//end of critical section
Body::id_t newClumpId = clump(idsTmp, discretization);
ret.append(python::make_tuple(newClumpId,idsTmp));
erase(b->id);