← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-dev/yade/trunk] Rev 2573: 1. Assume cache line size 64 bytes in OpenMPAccumulator, if sysconf reports zero (should fix star...

 

------------------------------------------------------------
revno: 2573
committer: Václav Šmilauer <eu@xxxxxxxx>
branch nick: yade
timestamp: Thu 2010-11-25 21:20:58 +0100
message:
  1. Assume cache line size 64 bytes in OpenMPAccumulator, if sysconf reports zero (should fix startup FPU exception reported by Giulia)
modified:
  lib/base/openmp-accu.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-11-07 11:46:20 +0000
+++ lib/base/openmp-accu.hpp	2010-11-25 20:20:58 +0000
@@ -81,13 +81,17 @@
 */
 template<typename T>
 class OpenMPAccumulator{
+		// in the ctor, assume 64 bytes (arbitrary, but safe) if sysconf does not report anything meaningful
+		// that might happen on newer proc models not yet reported by sysconf (?)
+		// e.g. https://lists.launchpad.net/yade-dev/msg06294.html
+		// where zero was reported, leading to FPU exception at startup
 		int CLS; // cache line size
 		int nThreads;
 		int eSize; // size of an element, computed from cache line size and sizeof(T)
 		char* data; // use void* rather than T*, since with T* the pointer arithmetics has sizeof(T) as unit, which is confusing; char* takes one byte
 	public:
 	// initialize storage with _zeroValue, depending on muber of threads
-	OpenMPAccumulator(): CLS(sysconf(_SC_LEVEL1_DCACHE_LINESIZE)), nThreads(omp_get_max_threads()), eSize(CLS*(sizeof(T)/CLS+(sizeof(T)%CLS==0 ? 0 :1))) {
+	OpenMPAccumulator(): CLS(sysconf(_SC_LEVEL1_DCACHE_LINESIZE)>0 ? sysconf(_SC_LEVEL1_DCACHE_LINESIZE) : 64), nThreads(omp_get_max_threads()), eSize(CLS*(sizeof(T)/CLS+(sizeof(T)%CLS==0 ? 0 :1))) {
 		int succ=posix_memalign(/*where allocated*/(void**)&data,/*alignment*/CLS,/*size*/ nThreads*eSize);
 		if(succ!=0) throw std::runtime_error("OpenMPAccumulator: posix_memalign failed to allocate memory.");
 		reset();