Skip to content

Commit

Permalink
Merge pull request #2914 from jougs/cleanup
Browse files Browse the repository at this point in the history
Add warning if local_num_threads set by user disagrees with OMP_NUM_THREADS
  • Loading branch information
jougs committed Sep 4, 2023
2 parents 75718a8 + e5b5d99 commit 913d0b2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions nestkernel/vp_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

#include "vp_manager.h"

// C++ includes:
#include <cstdlib>

// Includes from libnestutil:
#include "logging.h"

Expand Down Expand Up @@ -158,6 +161,19 @@ nest::VPManager::set_num_threads( size_t n_threads )
{
throw KernelException( "Multiple threads can not be used if structural plasticity is enabled" );
}

char* omp_num_threads = std::getenv( "OMP_NUM_THREADS" );
if ( omp_num_threads and static_cast< size_t >( std::atoi( omp_num_threads ) ) != n_threads )
{
const std::string tstr = ( n_threads > 1 ) ? "threads" : "thread";
const int ONT = std::atoi( omp_num_threads );
std::string msg = "The new number of threads disagrees with the environment variable OMP_NUM_THREADS.\n";
msg += "NEST only respects the kernel attributes /local_num_threads or /total_num_virtual_procs\n";
msg += String::compose( "and will now use %1 %2 and ignore OMP_NUM_THREADS (set to %3).", n_threads, tstr, ONT );

LOG( M_WARNING, "MPIManager::init_mpi()", msg );
}

n_threads_ = n_threads;

#ifdef _OPENMP
Expand Down

0 comments on commit 913d0b2

Please sign in to comment.