[mpich-discuss] [PATCH] Make the CS_ENTER/EXIT macros start using device code again.

Joe Ratterman jratt0 at gmail.com
Tue Nov 25 14:35:22 CST 2008


From: Joe Ratterman <jratt at us.ibm.com>

This adds more checks for "MPID_DEFINES_MPID_CS", successfully
removing the default macros from the compile.  Using the DCMFd device,
it also shows how to update an existing device to provide all the
required macro replacements.

Use "patch -p2" to apply from within the mpich2/ dir in SVN/tarball.

Signed-off-by: Joe Ratterman <jratt at us.ibm.com>
---
 mpich2/src/include/mpiimplthread.h         |    8 ++-
 mpich2/src/mpi/init/initthread.c           |    2 +-
 mpich2/src/mpid/dcmfd/include/mpidpre.h    |   32 +----------
 mpich2/src/mpid/dcmfd/include/mpidthread.h |   91 ++++++++++++++++++++++++++++
 4 files changed, 100 insertions(+), 33 deletions(-)
 create mode 100644 mpich2/src/mpid/dcmfd/include/mpidthread.h

diff --git a/mpich2/src/include/mpiimplthread.h b/mpich2/src/include/mpiimplthread.h
index 37afe7a..5c6dae4 100644
--- a/mpich2/src/include/mpiimplthread.h
+++ b/mpich2/src/include/mpiimplthread.h
@@ -221,6 +221,7 @@ int MPIR_Thread_CS_Finalize( void );
 #endif
 
 
+#if !defined(MPID_DEFINES_MPID_CS)
 #ifdef MPICH_IS_THREADED
 
 #ifdef HAVE_RUNTIME_THREADCHECK
@@ -287,12 +288,14 @@ int MPIR_Thread_CS_Finalize( void );
 #define MPIU_THREADSAFE_INIT_CLEAR(_var) _var=0
 #define MPIU_THREADSAFE_INIT_BLOCK_END(_var) 
 #endif  /* MPICH_IS_THREADED */
+#endif  /* !defined(MPID_DEFINES_MPID_CS) */
 
 /* ------------------------------------------------------------------------- */
 /*
  * New definitions for controling the granularity of thread atomicity
  *
  */
+#if !defined(MPID_DEFINES_MPID_CS)
 #ifdef MPICH_IS_THREADED
 
 /*M MPIU_THREAD_CS_ENTER - Enter a named critical section
@@ -371,8 +374,10 @@ M*/
 #define MPIU_THREAD_CHECK_END
 #define MPIU_ISTHREADED(_s) 
 
-#endif 
+#endif  /* MPICH_IS_THREADED */
+#endif  /* !defined(MPID_DEFINES_MPID_CS) */
 
+#if !defined(MPID_DEFINES_MPID_CS)
 #ifdef MPICH_IS_THREADED
 
 /* Helper definitions */
@@ -597,6 +602,7 @@ typedef struct MPIU_ThreadDebug {
 #define MPIU_THREAD_CS_EXIT(_name,_context)
 #define MPIU_THREAD_CS_YIELD(_name,_context)
 #endif /* MPICH_IS_THREADED */
+#endif /* !defined(MPID_DEFINES_MPID_CS)a */
 
 #endif /* !defined(MPIIMPLTHREAD_H_INCLUDED) */
 
diff --git a/mpich2/src/mpi/init/initthread.c b/mpich2/src/mpi/init/initthread.c
index 4a2a1d1..d79f5a1 100644
--- a/mpich2/src/mpi/init/initthread.c
+++ b/mpich2/src/mpi/init/initthread.c
@@ -97,7 +97,7 @@ MPICH_PerThread_t  MPIR_Thread = { 0 };
 MPICH_PerThread_t  MPIR_ThreadSingle = { 0 };
 #endif
 
-#if defined(MPICH_IS_THREADED)
+#if defined(MPICH_IS_THREADED) && !defined(MPID_DEFINES_MPID_CS)
 /* This routine is called when a thread exits; it is passed the value 
    associated with the key.  In our case, this is simply storage allocated
    with MPIU_Calloc */
diff --git a/mpich2/src/mpid/dcmfd/include/mpidpre.h b/mpich2/src/mpid/dcmfd/include/mpidpre.h
index 47ad308..08a7ff5 100644
--- a/mpich2/src/mpid/dcmfd/include/mpidpre.h
+++ b/mpich2/src/mpid/dcmfd/include/mpidpre.h
@@ -68,37 +68,7 @@ typedef DCQuad DCMF_CollectiveProtocol_t[1];
 }
 #endif /* !MPID_Dev_datatype_destroy_hook */
 
-/**
- * ******************************************************************
- * \brief Mutexes for interrupt driven mode
- * ******************************************************************
- */
-#ifdef MPID_CS_ENTER
-#error "MPID_CS_ENTER is already defined"
-#endif
-#define MPID_DEFINES_MPID_CS 1
-#if (MPICH_THREAD_LEVEL != MPI_THREAD_MULTIPLE)
-#define MPID_CS_INITIALIZE() {}
-#define MPID_CS_FINALIZE()   {}
-#define MPID_CS_ENTER()      {}
-#define MPID_CS_EXIT()       {}
-#define MPID_CS_CYCLE()      {}
-#else
-#define MPID_CS_INITIALIZE()                                          \
-{                                                                     \
-  /* Create thread local storage for nest count that MPICH uses */    \
-  MPID_Thread_tls_create(NULL, &MPIR_ThreadInfo.thread_storage, NULL);   \
-}
-#define MPID_CS_FINALIZE()                                            \
-{                                                                     \
-  /* Destroy thread local storage created during MPID_CS_INITIALIZE */\
-  MPID_Thread_tls_destroy(&MPIR_ThreadInfo.thread_storage, NULL);	      \
-}
-#define MPID_CS_ENTER()      DCMF_CriticalSection_enter(0);
-#define MPID_CS_EXIT()       DCMF_CriticalSection_exit(0);
-#define MPID_CS_CYCLE()      DCMF_CriticalSection_cycle(0);
-#endif
-
+#include <mpidthread.h>
 
 typedef int                 MPIDI_VCR;
 typedef struct MPIDI_VCRT * MPID_VCRT;
diff --git a/mpich2/src/mpid/dcmfd/include/mpidthread.h b/mpich2/src/mpid/dcmfd/include/mpidthread.h
new file mode 100644
index 0000000..eb49a30
--- /dev/null
+++ b/mpich2/src/mpid/dcmfd/include/mpidthread.h
@@ -0,0 +1,91 @@
+/*  (C)Copyright IBM Corp.  2007, 2008  */
+/**
+ * \file include/mpidthread.h
+ * \brief ???
+ *
+ */
+/*
+ *  (C) 2001 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+
+#ifndef MPICH_MPIDTHREAD_H_INCLUDED
+#define MPICH_MPIDTHREAD_H_INCLUDED
+
+/**
+ * ******************************************************************
+ * \brief Mutexes for thread/interrupt safety
+ * ******************************************************************
+ */
+
+
+#ifdef MPID_CS_ENTER
+#error "MPID_CS_ENTER is already defined"
+#endif
+#define MPID_DEFINES_MPID_CS 1
+#if (MPICH_THREAD_LEVEL != MPI_THREAD_MULTIPLE)
+
+
+#define MPID_CS_INITIALIZE() {}
+#define MPID_CS_FINALIZE()   {}
+#define MPID_CS_ENTER()      {}
+#define MPID_CS_EXIT()       {}
+#define MPID_CS_CYCLE()      {}
+
+#define MPIU_THREAD_CHECK_BEGIN
+#define MPIU_THREAD_CHECK_END
+#define MPIU_THREAD_CS_ENTER(_name,_context)
+#define MPIU_THREAD_CS_EXIT(_name,_context)
+#define MPIU_THREAD_CS_YIELD(_name,_context)
+#define MPIU_THREADSAFE_INIT_DECL(_var) static int _var=1
+#define MPIU_THREADSAFE_INIT_STMT(_var,_stmt) if (_var) { _stmt; _var = 0; }
+#define MPIU_THREADSAFE_INIT_BLOCK_BEGIN(_var)
+#define MPIU_THREADSAFE_INIT_CLEAR(_var) _var=0
+#define MPIU_THREADSAFE_INIT_BLOCK_END(_var)
+
+
+#else
+
+#define HAVE_RUNTIME_THREADCHECK
+#define MPIU_THREAD_CHECK_BEGIN if (MPIR_ThreadInfo.isThreaded) {
+#define MPIU_THREAD_CHECK_END   }
+#define MPIU_THREAD_CS_ENTER(_name,_context) DCMF_CriticalSection_enter(0);
+#define MPIU_THREAD_CS_EXIT(_name,_context)  DCMF_CriticalSection_exit(0);
+#define MPIU_THREAD_CS_YIELD(_name,_context) DCMF_CriticalSection_cycle(0);
+#define MPIU_THREADSAFE_INIT_DECL(_var) static volatile int _var=1
+#define MPIU_THREADSAFE_INIT_STMT(_var,_stmt)   \
+     if (_var) {                                \
+	 MPIU_THREAD_CS_ENTER(INITFLAG,);       \
+      _stmt; _var=0;                            \
+      MPIU_THREAD_CS_EXIT(INITFLAG,);           \
+     }
+#define MPIU_THREADSAFE_INIT_BLOCK_BEGIN(_var)  \
+    MPIU_THREAD_CS_ENTER(INITFLAG,);            \
+     if (_var) {
+#define MPIU_THREADSAFE_INIT_CLEAR(_var) _var=0
+#define MPIU_THREADSAFE_INIT_BLOCK_END(_var)    \
+      }                                         \
+	  MPIU_THREAD_CS_EXIT(INITFLAG,)
+
+
+#define MPID_CS_INITIALIZE()                                            \
+{                                                                       \
+  /* Create thread local storage for nest count that MPICH uses */      \
+  MPID_Thread_tls_create(NULL, &MPIR_ThreadInfo.thread_storage, NULL);  \
+}
+#define MPID_CS_FINALIZE()                                              \
+{                                                                       \
+  /* Destroy thread local storage created during MPID_CS_INITIALIZE */  \
+  MPID_Thread_tls_destroy(&MPIR_ThreadInfo.thread_storage, NULL);       \
+}
+#define MPID_CS_ENTER()      DCMF_CriticalSection_enter(0);
+#define MPID_CS_EXIT()       DCMF_CriticalSection_exit(0);
+#define MPID_CS_CYCLE()      DCMF_CriticalSection_cycle(0);
+
+
+#endif
+
+#define MPIU_ISTHREADED(_s) { MPIU_THREAD_CHECK_BEGIN _s MPIU_THREAD_CHECK_END }
+
+#endif /* !MPICH_MPIDTHREAD_H_INCLUDED */
-- 
1.6.0.4.1.g57b5




More information about the mpich-discuss mailing list