Commit cb63bc0b authored by Kirill Terekhov's avatar Kirill Terekhov

Fixes

Fixes for the features introduced in 635cc476 in the case USE_OMP was
not activated in cmake.
parent 635cc476
......@@ -131,6 +131,12 @@
#define INMOST_MPI_GROUP_EMPTY MPI_GROUP_EMPTY
#endif
#if !defined(USE_OMP)
#define INMOST_OMP_LOCK_T int
#else
#define INMOST_OMP_LOCK_T omp_lock_t
#endif
#define INMOST_MPI_SIZE int //in case MPI standard changes and compiler gives tons of warnings
......
......@@ -294,9 +294,7 @@ namespace INMOST
/// This class can be used for shared access to matrix with OpenMP.
class LockService
{
#if defined(USE_OMP)
interval<INMOST_DATA_ENUM_TYPE,omp_lock_t> locks;
#endif
interval<INMOST_DATA_ENUM_TYPE,INMOST_OMP_LOCK_T> locks;
void DestroyLocks();
public:
LockService(INMOST_DATA_ENUM_TYPE start = 0, INMOST_DATA_ENUM_TYPE end = 0) { if( end != start ) SetInterval(start,end); }
......
......@@ -269,7 +269,7 @@ namespace INMOST
for(INMOST_DATA_ENUM_TYPE i = 0; i < end; i++) rJ.GetValue(i) *= beta;
for(INMOST_DATA_ENUM_TYPE i = 0; i < end; i++)
{
index & ind = GetIndex(i);
const index & ind = GetIndex(i);
if( ind.first == ind.second )
rJ[ind.first] += alpha*rU.get_safe(ind.first)*GetValue(i);
else
......@@ -875,34 +875,40 @@ namespace INMOST
}
bool LockService::Lock(INMOST_DATA_ENUM_TYPE row)
{
assert( !locks.empty() );
#if defined(USE_OMP)
if( locks.empty() ) return false;
omp_set_lock(&locks[row]);
return true;
omp_set_lock(&locks[row]);
#else
locks[row] = 1;
#endif
return true;
}
bool LockService::TestLock(INMOST_DATA_ENUM_TYPE row)
{
#if defined(USE_OMP)
if( locks.empty() )
{
std::cout << "You have to call to LockService::SetInterval to use locks" << std::endl;
return false;
}
if( omp_test_lock(&locks[row]) )
return true;
else
return false;
#else
if( locks[row] == 1 )
return false;
else
{
locks[row] = 1;
return true;
}
#endif
return true; //Say that the lock has locked
}
bool LockService::UnLock(INMOST_DATA_ENUM_TYPE row)
{
assert( !locks.empty() );
#if defined(USE_OMP)
if( locks.empty() ) return false;
omp_unset_lock(&locks[row]);
return true;
#else
locks[row] = 0;
#endif
return true;
}
void LockService::SetInterval(INMOST_DATA_ENUM_TYPE beg, INMOST_DATA_ENUM_TYPE end)
{
......@@ -910,15 +916,23 @@ namespace INMOST
locks.set_interval_beg(beg);
locks.set_interval_end(end);
for(INMOST_DATA_ENUM_TYPE k = beg; k < end; ++k)
{
#if defined(USE_OMP)
omp_init_lock(&locks[k]);
#else
locks[k] = 0;
#endif
}
}
void LockService::DestroyLocks()
{
#if defined(USE_OMP)
INMOST_DATA_ENUM_TYPE kbeg,kend;
kbeg = locks.get_interval_beg();
kend = locks.get_interval_end();
for(INMOST_DATA_ENUM_TYPE k = kbeg; k < kend; ++k)
omp_destroy_lock(&locks[k]);
#endif
}
void HessianMatrix::MatVec(INMOST_DATA_REAL_TYPE alpha, const Sparse::Matrix & U, INMOST_DATA_REAL_TYPE beta, Sparse::Matrix & J) const //y = alpha*A*x + beta * y
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment