/**************************************************************************** ** TAU Portable Profiling Package ** ** http://www.cs.uoregon.edu/research/tau ** ***************************************************************************** ** Copyright 1997 ** ** Department of Computer and Information Science, University of Oregon ** ** Advanced Computing Laboratory, Los Alamos National Laboratory ** ****************************************************************************/ /*************************************************************************** ** File : OpenMPLayer.cpp ** ** Description : TAU Profiling Package RTS Layer definitions ** ** for supporting OpenMP Threads ** ** Contact : tau-team@cs.uoregon.edu ** ** Documentation : See http://www.cs.uoregon.edu/research/tau ** ***************************************************************************/ ////////////////////////////////////////////////////////////////////// // Include Files ////////////////////////////////////////////////////////////////////// //#define DEBUG_PROF #ifdef TAU_DOT_H_LESS_HEADERS #include using namespace std; #else /* TAU_DOT_H_LESS_HEADERS */ #include #endif /* TAU_DOT_H_LESS_HEADERS */ #include "Profile/OpenMPLayer.h" ///////////////////////////////////////////////////////////////////////// // Member Function Definitions For class OpenMPLayer // This allows us to get thread ids from 0..N-1 and lock and unlock DB ///////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////// // Define the static private members of OpenMPLayer ///////////////////////////////////////////////////////////////////////// omp_lock_t OpenMPLayer::tauDBmutex; omp_lock_t OpenMPLayer::tauEnvmutex; #ifdef TAU_OPENMP_NESTED static int threadId = -1; #pragma omp threadprivate(threadId) static int threadCount = 0; #endif /* TAU_OPENMP_NESTED */ //////////////////////////////////////////////////////////////////////// // RegisterThread() should be called before any profiling routines are // invoked. This routine sets the thread id that is used by the code in // FunctionInfo and Profiler classes. This should be the first routine a // thread should invoke from its wrapper. Note: main() thread shouldn't // call this routine. //////////////////////////////////////////////////////////////////////// int OpenMPLayer::RegisterThread(void) { // Not needed for OpenMP programs! return 0; } //////////////////////////////////////////////////////////////////////// // GetThreadId returns an id in the range 0..N-1 by looking at the // thread specific data. Since a getspecific has to be preceeded by a // setspecific (that all threads besides main do), we get a null for the // main thread that lets us identify it as thread 0. It is the only // thread that doesn't do a OpenMPLayer::RegisterThread(). //////////////////////////////////////////////////////////////////////// int OpenMPLayer::GetThreadId(void) { #ifdef TAU_OPENMP #ifdef TAU_OPENMP_NESTED if (threadId == -1) { #pragma omp critical(threadLock) { threadId = threadCount++; } } return threadId; #else return omp_get_thread_num(); #endif /* TAU_OPENMP_NESTED */ #endif /* TAU_OPENMP */ } //////////////////////////////////////////////////////////////////////// // TotalThreads returns the total number of threads running // The user typically sets this by setting the environment variable // OMP_NUM_THREADS or by using the routine omp_set_num_threads(int); //////////////////////////////////////////////////////////////////////// int OpenMPLayer::TotalThreads(void) { #ifdef TAU_OPENMP // Note: this doesn't work for nested parallelism return omp_get_num_threads(); #endif /* TAU_OPENMP */ } //////////////////////////////////////////////////////////////////////// // InitializeThreadData is called before any thread operations are performed. // It sets the default values for static private data members of the // OpenMPLayer class. //////////////////////////////////////////////////////////////////////// int OpenMPLayer::InitializeThreadData(void) { return 1; } //////////////////////////////////////////////////////////////////////// int OpenMPLayer::InitializeDBMutexData(void) { // For locking functionDB // Initialize the mutex omp_init_lock(&OpenMPLayer::tauDBmutex); //cout <<" Initialized the functionDB Mutex data " <