Skip to content

Commit

Permalink
omp_locks: Avoid extern global variable
Browse files Browse the repository at this point in the history
Make `omp_locks` a variable in an unnamed namespace instead of an extern
global variable.

This might potentially fix the Windows symbol issue (AMReX-Codes#3795).
  • Loading branch information
WeiqunZhang committed Mar 11, 2024
1 parent d4dcb01 commit 56aa49a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Src/Base/AMReX_BaseFab.H
Expand Up @@ -3362,7 +3362,7 @@ BaseFab<T>::lockAdd (const BaseFab<T>& src, const Box& srcbox, const Box& destbo
auto const m = mm + plo;
int ilock = m % OpenMP::nlocks;
if (ilock < 0) { ilock += OpenMP::nlocks; }
auto* lock = &(OpenMP::omp_locks[ilock]);
auto* lock = OpenMP::get_lock(ilock);
if (omp_test_lock(lock))
{
auto lo = dlo;
Expand Down
3 changes: 1 addition & 2 deletions Src/Base/AMReX_OpenMP.H
Expand Up @@ -17,8 +17,7 @@ namespace amrex::OpenMP {
void Initialize ();
void Finalize ();

static constexpr int nlocks = 128;
extern AMREX_EXPORT omp_lock_t omp_locks[nlocks];
omp_lock_t* get_lock (int ilock);
}

#else // AMREX_USE_OMP
Expand Down
5 changes: 3 additions & 2 deletions Src/Base/AMReX_OpenMP.cpp
Expand Up @@ -135,9 +135,8 @@ namespace amrex
#ifdef AMREX_USE_OMP
namespace amrex::OpenMP
{
omp_lock_t omp_locks[nlocks];

namespace {
omp_lock_t omp_locks[128];
unsigned int initialized = 0;
}

Expand Down Expand Up @@ -204,5 +203,7 @@ namespace amrex::OpenMP
}
}

omp_lock_t* get_lock (int ilock) { return omp_locks + ilock; }

} // namespace amrex::OpenMP
#endif // AMREX_USE_OMP

0 comments on commit 56aa49a

Please sign in to comment.