mirror of
https://github.com/NGSolve/netgen.git
synced 2025-01-26 21:00:34 +05:00
get rid of OpenMP
This commit is contained in:
parent
da5e5dbdac
commit
1b4f596446
@ -144,12 +144,6 @@ if(APPLE)
|
|||||||
# set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
|
# set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
|
||||||
endif(APPLE)
|
endif(APPLE)
|
||||||
|
|
||||||
#######################################################################
|
|
||||||
if(NOT INTEL_MIC AND NOT WIN32 AND NOT APPLE)
|
|
||||||
find_package(OpenMP)
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
|
|
||||||
endif(NOT INTEL_MIC AND NOT WIN32 AND NOT APPLE)
|
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
find_package(ZLIB REQUIRED)
|
find_package(ZLIB REQUIRED)
|
||||||
include_directories(${ZLIB_INCLUDE_DIRS})
|
include_directories(${ZLIB_INCLUDE_DIRS})
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
namespace netgen
|
namespace netgen
|
||||||
{
|
{
|
||||||
|
static mutex block_allocator_mutex;
|
||||||
|
|
||||||
BlockAllocator :: BlockAllocator (unsigned asize, unsigned ablocks)
|
BlockAllocator :: BlockAllocator (unsigned asize, unsigned ablocks)
|
||||||
: bablocks (0)
|
: bablocks (0)
|
||||||
@ -36,8 +37,8 @@ namespace netgen
|
|||||||
void * BlockAllocator :: Alloc ()
|
void * BlockAllocator :: Alloc ()
|
||||||
{
|
{
|
||||||
void * p;
|
void * p;
|
||||||
#pragma omp critical (BlockAllocator)
|
|
||||||
{
|
{
|
||||||
|
lock_guard<mutex> guard(block_allocator_mutex);
|
||||||
// return new char[size];
|
// return new char[size];
|
||||||
if (!freelist)
|
if (!freelist)
|
||||||
{
|
{
|
||||||
@ -60,8 +61,8 @@ namespace netgen
|
|||||||
|
|
||||||
void BlockAllocator :: Free (void * p)
|
void BlockAllocator :: Free (void * p)
|
||||||
{
|
{
|
||||||
#pragma omp critical (BlockAllocator)
|
|
||||||
{
|
{
|
||||||
|
lock_guard<mutex> guard(block_allocator_mutex);
|
||||||
if (bablocks.Size())
|
if (bablocks.Size())
|
||||||
{
|
{
|
||||||
*(void**)p = freelist;
|
*(void**)p = freelist;
|
||||||
|
@ -187,6 +187,27 @@ public:
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Simple ParallelFor function to replace OpenMP
|
||||||
|
template<typename TFunc>
|
||||||
|
void ParallelFor( int first, int next, const TFunc & f )
|
||||||
|
{
|
||||||
|
int nthreads = thread::hardware_concurrency();
|
||||||
|
thread * threads = new thread[nthreads];
|
||||||
|
for (int i=0; i<nthreads; i++)
|
||||||
|
{
|
||||||
|
threads[i] = std::thread( [&] ()
|
||||||
|
{
|
||||||
|
int myfirst = first + (next-first)*i/nthreads;
|
||||||
|
int mynext = first + (next-first)*(i+1)/nthreads;
|
||||||
|
f(myfirst, mynext);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i=0; i<nthreads; i++)
|
||||||
|
threads[i].join();
|
||||||
|
delete [] threads;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
#include <climits>
|
#include <climits>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <thread>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
|
||||||
#include <new>
|
#include <new>
|
||||||
@ -35,9 +37,6 @@
|
|||||||
#include <unistd.h> // for usleep (only for parallel)
|
#include <unistd.h> // for usleep (only for parallel)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _OPENMP
|
|
||||||
#include <omp.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -2363,8 +2363,6 @@ void LinkFunction ()
|
|||||||
|
|
||||||
void Ng_TclCmd(string cmd)
|
void Ng_TclCmd(string cmd)
|
||||||
{
|
{
|
||||||
#pragma omp critical(tcltodo)
|
lock_guard<mutex> guard(tcl_todo_mutex);
|
||||||
{
|
*(multithread.tcl_todo) += cmd;
|
||||||
*(multithread.tcl_todo) += cmd;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -68,6 +68,8 @@ namespace netgen
|
|||||||
|
|
||||||
Array<int> tets_in_qualclass;
|
Array<int> tets_in_qualclass;
|
||||||
|
|
||||||
|
mutex tcl_todo_mutex;
|
||||||
|
|
||||||
int h_argc = 0;
|
int h_argc = 0;
|
||||||
char ** h_argv = NULL;
|
char ** h_argv = NULL;
|
||||||
|
|
||||||
|
@ -29,6 +29,8 @@ namespace netgen
|
|||||||
|
|
||||||
DLL_HEADER extern Array<int> tets_in_qualclass;
|
DLL_HEADER extern Array<int> tets_in_qualclass;
|
||||||
|
|
||||||
|
DLL_HEADER extern mutex tcl_todo_mutex;
|
||||||
|
|
||||||
class multithreadt
|
class multithreadt
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
namespace netgen
|
namespace netgen
|
||||||
{
|
{
|
||||||
|
|
||||||
|
static mutex buildsearchtree_mutex;
|
||||||
|
|
||||||
Mesh :: Mesh ()
|
Mesh :: Mesh ()
|
||||||
: surfarea(*this)
|
: surfarea(*this)
|
||||||
{
|
{
|
||||||
@ -4101,8 +4103,8 @@ namespace netgen
|
|||||||
{
|
{
|
||||||
if (elementsearchtreets == GetTimeStamp()) return;
|
if (elementsearchtreets == GetTimeStamp()) return;
|
||||||
|
|
||||||
#pragma omp critical (buildsearchtree)
|
|
||||||
{
|
{
|
||||||
|
std::lock_guard<std::mutex> guard(buildsearchtree_mutex);
|
||||||
if (elementsearchtreets != GetTimeStamp())
|
if (elementsearchtreets != GetTimeStamp())
|
||||||
{
|
{
|
||||||
NgLock lock(mutex);
|
NgLock lock(mutex);
|
||||||
|
@ -2138,13 +2138,13 @@ int STLGeometry :: CheckGeometryOverlapping()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#pragma omp parallel
|
|
||||||
{
|
{
|
||||||
Array<int> inters;
|
Array<int> inters;
|
||||||
|
mutex inters_mutex;
|
||||||
|
|
||||||
#pragma omp for
|
ParallelFor( 1, GetNT()+1, [&] (int first, int next)
|
||||||
for (int i = 1; i <= GetNT(); i++)
|
{
|
||||||
{
|
for (int i=first; i<next; i++) {
|
||||||
const STLTriangle & tri = GetTriangle(i);
|
const STLTriangle & tri = GetTriangle(i);
|
||||||
|
|
||||||
Point<3> tpmin = tri.box.PMin();
|
Point<3> tpmin = tri.box.PMin();
|
||||||
@ -2176,7 +2176,7 @@ int STLGeometry :: CheckGeometryOverlapping()
|
|||||||
|
|
||||||
if (IntersectTriangleTriangle (&trip1[0], &trip2[0]))
|
if (IntersectTriangleTriangle (&trip1[0], &trip2[0]))
|
||||||
{
|
{
|
||||||
#pragma omp critical
|
lock_guard<mutex> guard(inters_mutex);
|
||||||
{
|
{
|
||||||
oltrigs++;
|
oltrigs++;
|
||||||
PrintMessage(5,"Intersecting Triangles: trig ",i," with ",inters.Get(j),"!");
|
PrintMessage(5,"Intersecting Triangles: trig ",i," with ",inters.Get(j),"!");
|
||||||
@ -2186,6 +2186,7 @@ int STLGeometry :: CheckGeometryOverlapping()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
PrintMessage(3,"Check overlapping geometry ... ", oltrigs, " triangles overlap");
|
PrintMessage(3,"Check overlapping geometry ... ", oltrigs, " triangles overlap");
|
||||||
return oltrigs;
|
return oltrigs;
|
||||||
|
@ -2474,27 +2474,36 @@ namespace netgen
|
|||||||
NgProfiler::RegionTimer reg1 (timer1);
|
NgProfiler::RegionTimer reg1 (timer1);
|
||||||
|
|
||||||
int ne = mesh->GetNE();
|
int ne = mesh->GetNE();
|
||||||
double hminv = numeric_limits<double>::max();
|
|
||||||
double hmaxv = -numeric_limits<double>::max();
|
|
||||||
bool hhasit = false;
|
|
||||||
#if defined _OPENMP && _OPENMP >= 201107
|
|
||||||
#pragma omp parallel for reduction (max : hmaxv) reduction (min : hminv) reduction (|| : hhasit)
|
|
||||||
#endif
|
|
||||||
for (int i = 0; i < ne; i++)
|
|
||||||
{
|
|
||||||
double val;
|
|
||||||
bool considerElem = GetValue (sol, i, 0.333, 0.333, 0.333, comp, val);
|
|
||||||
if (considerElem)
|
|
||||||
{
|
|
||||||
if (val > hmaxv) hmaxv = val;
|
|
||||||
if (val < hminv) hminv = val;
|
|
||||||
hhasit = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
minv = min(minv, hminv);
|
mutex min_mutex;
|
||||||
maxv = max(maxv, hmaxv);
|
mutex max_mutex;
|
||||||
hasit |= hhasit;
|
|
||||||
|
ParallelFor(0, ne, [&] (int first, int next)
|
||||||
|
{
|
||||||
|
double minv_local = numeric_limits<double>::max();
|
||||||
|
double maxv_local = -numeric_limits<double>::max();
|
||||||
|
for (int i=first; i<next; i++)
|
||||||
|
{
|
||||||
|
double val;
|
||||||
|
bool considerElem = GetValue (sol, i, 0.333, 0.333, 0.333, comp, val);
|
||||||
|
if (considerElem)
|
||||||
|
{
|
||||||
|
if (val > maxv_local) maxv_local = val;
|
||||||
|
if (val < minv_local) minv_local = val;
|
||||||
|
hasit = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(minv_local < minv)
|
||||||
|
{
|
||||||
|
lock_guard<mutex> guard(min_mutex);
|
||||||
|
minv = minv_local;
|
||||||
|
}
|
||||||
|
if(maxv_local > maxv)
|
||||||
|
{
|
||||||
|
lock_guard<mutex> guard(max_mutex);
|
||||||
|
maxv = maxv_local;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sol->draw_surface)
|
if (sol->draw_surface)
|
||||||
|
@ -710,8 +710,8 @@ namespace netgen
|
|||||||
strcat (lstring, " 0");
|
strcat (lstring, " 0");
|
||||||
Tcl_SetVar (interp, "::status_tetqualclasses", lstring, 0);
|
Tcl_SetVar (interp, "::status_tetqualclasses", lstring, 0);
|
||||||
|
|
||||||
#pragma omp critical(tcltodo)
|
|
||||||
{
|
{
|
||||||
|
lock_guard<mutex> guard(tcl_todo_mutex);
|
||||||
if (multithread.tcl_todo->length())
|
if (multithread.tcl_todo->length())
|
||||||
{
|
{
|
||||||
Tcl_Eval (interp, multithread.tcl_todo->c_str());
|
Tcl_Eval (interp, multithread.tcl_todo->c_str());
|
||||||
|
Loading…
Reference in New Issue
Block a user