From a9db9bdaf8827dad8a02c4fee33c9f788a3afe66 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Thu, 27 Aug 2009 10:53:09 +0000 Subject: [PATCH] make MElement and MVertex thread-safe by guarding _globalNum --- Geo/MElement.cpp | 15 +++++++++++++++ Geo/MElement.h | 12 +----------- Geo/MVertex.cpp | 25 +++++++++++++++++++++++++ Geo/MVertex.h | 19 ++----------------- 4 files changed, 43 insertions(+), 28 deletions(-) diff --git a/Geo/MElement.cpp b/Geo/MElement.cpp index a86138812c..e10d2864b9 100644 --- a/Geo/MElement.cpp +++ b/Geo/MElement.cpp @@ -29,6 +29,21 @@ int MElement::_globalNum = 0; double MElement::_isInsideTolerance = 1.e-6; double MElementLessThanLexicographic::tolerance = 1.e-6; +MElement::MElement(int num, int part) : _visible(1) +{ +#pragma omp critical + { + if(num){ + _num = num; + _globalNum = std::max(_globalNum, _num); + } + else{ + _num = ++_globalNum; + } + _partition = (short)part; + } +} + void MElement::_getEdgeRep(MVertex *v0, MVertex *v1, double *x, double *y, double *z, SVector3 *n, int faceIndex) diff --git a/Geo/MElement.h b/Geo/MElement.h index 4f90fc0f76..d768db0050 100644 --- a/Geo/MElement.h +++ b/Geo/MElement.h @@ -42,17 +42,7 @@ class MElement void _getFaceRep(MVertex *v0, MVertex *v1, MVertex *v2, double *x, double *y, double *z, SVector3 *n); public : - MElement(int num=0, int part=0) : _visible(1) - { - if(num){ - _num = num; - _globalNum = std::max(_globalNum, _num); - } - else{ - _num = ++_globalNum; - } - _partition = (short)part; - } + MElement(int num=0, int part=0); virtual ~MElement(){} // reset the global node number diff --git a/Geo/MVertex.cpp b/Geo/MVertex.cpp index d7cdd04859..7c7c5dab2e 100644 --- a/Geo/MVertex.cpp +++ b/Geo/MVertex.cpp @@ -26,6 +26,31 @@ bool MVertexLessThanLexicographic::operator()(const MVertex *v1, const MVertex * return false; } +MVertex::MVertex(double x, double y, double z, GEntity *ge, int num) + : _visible(1), _order(1), _x(x), _y(y), _z(z), _ge(ge) +{ +#pragma omp critical + { + if(num){ + _num = num; + _globalNum = std::max(_globalNum, _num); + } + else{ + _num = ++_globalNum; + } + _index = num; + } +} + +void MVertex::setNum(int num) +{ +#pragma omp critical + { + _num = num; + _globalNum = std::max(_globalNum, _num); + } +} + void MVertex::writeMSH(FILE *fp, bool binary, bool saveParametric, double scalingFactor) { if(_index < 0) return; // negative index vertices are never saved diff --git a/Geo/MVertex.h b/Geo/MVertex.h index d755cfb9a5..1cf422768f 100644 --- a/Geo/MVertex.h +++ b/Geo/MVertex.h @@ -43,18 +43,7 @@ class MVertex{ GEntity *_ge; public : - MVertex(double x, double y, double z, GEntity *ge=0, int num=0) - : _visible(1), _order(1), _x(x), _y(y), _z(z), _ge(ge) - { - if(num){ - _num = num; - _globalNum = std::max(_globalNum, _num); - } - else{ - _num = ++_globalNum; - } - _index = num; - } + MVertex(double x, double y, double z, GEntity *ge=0, int num=0); virtual ~MVertex(){} // get/reset the global node number @@ -84,11 +73,7 @@ class MVertex{ // get/set the number inline int getNum() const { return _num; } - inline void setNum(int num) - { - _num = num; - _globalNum = std::max(_globalNum, _num); - } + void setNum(int num); // get/set the index inline int getIndex() const { return _index; } -- GitLab