← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-dev/yade/trunk] Rev 2114: 1. Uniformize accumulator interface for open and openmp-less builds.

 

------------------------------------------------------------
revno: 2114
committer: Václav Šmilauer <eudoxos@xxxxxxxx>
branch nick: trunk
timestamp: Mon 2010-03-29 17:48:04 +0200
message:
  1. Uniformize accumulator interface for open and openmp-less builds.
modified:
  lib/base/openmp-accu.hpp
  pkg/dem/Engine/Callback/UnbalancedForceCallbacks.cpp
  pkg/dem/Engine/Callback/UnbalancedForceCallbacks.hpp


--
lp:yade
https://code.launchpad.net/~yade-dev/yade/trunk

Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-dev/yade/trunk/+edit-subscription.
=== modified file 'lib/base/openmp-accu.hpp'
--- lib/base/openmp-accu.hpp	2010-03-16 15:34:25 +0000
+++ lib/base/openmp-accu.hpp	2010-03-29 15:48:04 +0000
@@ -25,12 +25,12 @@
 };
 #else 
 // single-threaded version of the accumulator above
-template<typename T>
+template<typename T, T* zeroValue>
 class OpenMPAccumulator{
 	T data;
 public:
 	void operator+=(const T& val){ data+=val; }
 	operator T(){ return data; }
-	void reset(const T& zeroValue){ data=zeroValue; }
+	void reset(){ data=*zeroValue; }
 };
 #endif

=== modified file 'pkg/dem/Engine/Callback/UnbalancedForceCallbacks.cpp'
--- pkg/dem/Engine/Callback/UnbalancedForceCallbacks.cpp	2010-03-29 14:23:42 +0000
+++ pkg/dem/Engine/Callback/UnbalancedForceCallbacks.cpp	2010-03-29 15:48:04 +0000
@@ -14,11 +14,7 @@
 
 	cerr<<"("<<(Real)force<<","<<(int)numIntr<<")";
 	// reset accumulators
-#ifdef YADE_OPENMP
 	force.reset(); numIntr.reset();
-#else
-	force.reset(0);numIntr.reset(0);
-#endif
 	// return function pointer
 	return &SumIntrForcesCb::go;
 }
@@ -36,11 +32,7 @@
 
 BodyCallback::FuncPtr SumBodyForcesCb::stepInit(){
 	cerr<<"{"<<(Real)force<<","<<(int)numBodies<<",this="<<this<<",scene="<<scene<<",forces="<<&(scene->forces)<<"}";
-#ifdef YADE_OPENMP
 	force.reset(); numBodies.reset(); // reset accumulators
-#else
-	force.reset(0);numBodies.reset(0);
-#endif
 	return &SumBodyForcesCb::go;
 }
 void SumBodyForcesCb::go(BodyCallback* _self, Body* b){

=== modified file 'pkg/dem/Engine/Callback/UnbalancedForceCallbacks.hpp'
--- pkg/dem/Engine/Callback/UnbalancedForceCallbacks.hpp	2010-03-29 14:23:42 +0000
+++ pkg/dem/Engine/Callback/UnbalancedForceCallbacks.hpp	2010-03-29 15:48:04 +0000
@@ -8,13 +8,8 @@
 		// zero values, so that we can pass pointers to them to OpenMPAccumulator
 		static int int0;
 		static Real Real0;
-#ifdef YADE_OPENMP
 		OpenMPAccumulator<int,&SumIntrForcesCb::int0> numIntr;
 		OpenMPAccumulator<Real,&SumIntrForcesCb::Real0> force;
-#else
-		OpenMPAccumulator<int> numIntr;
-		OpenMPAccumulator<Real> force;
-#endif
 		static void go(IntrCallback*,Interaction*);
 		virtual IntrCallback::FuncPtr stepInit();
 	YADE_CLASS_BASE_DOC(SumIntrForcesCb,IntrCallback,"Callback summing magnitudes of forces over all interactions. :yref:`InteractionPhysics` of interactions must derive from :yref:`NormShearPhys` (responsability fo the user).");
@@ -24,13 +19,8 @@
 class SumBodyForcesCb: public BodyCallback{
 	Scene* scene;
 	public:
-#ifdef YADE_OPENMP
 		OpenMPAccumulator<int,&SumIntrForcesCb::int0> numBodies;
 		OpenMPAccumulator<Real,&SumIntrForcesCb::Real0> force;
-#else
-		OpenMPAccumulator<int> numBodies;
-		OpenMPAccumulator<Real> force;
-#endif
 		static void go(BodyCallback*,Body*);
 		virtual BodyCallback::FuncPtr stepInit();
 	YADE_CLASS_BASE_DOC(SumBodyForcesCb,BodyCallback,"Callback summing magnitudes of resultant forces over :yref:`dynamic<Body::isDynamic>` bodies.");