[mpich-commits] [mpich] MPICH primary repository branch, master, updated. v3.2b4-163-g0d5760a

Service Account noreply at mpich.org
Tue Aug 18 21:03:00 CDT 2015


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "MPICH primary repository".

The branch, master has been updated
       via  0d5760ae5eccc0db7c2559909f75ada30ee4bb33 (commit)
       via  fa11ecd3c995d3b4cc86a58366ac90ae814f2f9d (commit)
       via  d484022edb5f865760b063b9908895bdbfbef7fb (commit)
       via  da4f2e5f73ed4dcfff87fe11ec49b602da9c9447 (commit)
       via  78413c55c4820a50cd31f0df6ec009891ff42917 (commit)
      from  88affa5941155e68ead5eedd59ce093f6d2fb625 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.mpich.org/mpich.git/commitdiff/0d5760ae5eccc0db7c2559909f75ada30ee4bb33

commit 0d5760ae5eccc0db7c2559909f75ada30ee4bb33
Author: Pavan Balaji <balaji at anl.gov>
Date:   Tue Aug 18 14:34:57 2015 -0500

    Simplify threading code.
    
    There were unnecessary intermediate macros which didn't serve any
    purpose.  This patch removes them and directly calls the mutex
    acquire/release functions.
    
    Signed-off-by: Rob Latham <robl at mcs.anl.gov>

diff --git a/src/util/thread/mpiu_thread_global.h b/src/util/thread/mpiu_thread_global.h
index 371c26b..567331a 100644
--- a/src/util/thread/mpiu_thread_global.h
+++ b/src/util/thread/mpiu_thread_global.h
@@ -7,33 +7,15 @@
 #if !defined(MPIU_THREAD_GLOBAL_H_INCLUDED)
 #define MPIU_THREAD_GLOBAL_H_INCLUDED
 
-/* There is a single, global lock, held for the duration of an MPI call */
-#define MPIU_THREAD_CS_ENTER_GLOBAL(_context)                           \
-    do {                                                                \
-        MPIU_THREAD_CHECK_BEGIN;                                        \
-        MPIU_THREAD_CS_ENTER_LOCKNAME(GLOBAL,_context);                 \
-        MPIU_THREAD_CHECK_END;                                          \
-    } while (0)
-
-#define MPIU_THREAD_CS_EXIT_GLOBAL(_context)                            \
-    do {                                                                \
-        MPIU_THREAD_CHECK_BEGIN;                                        \
-        MPIU_THREAD_CS_EXIT_LOCKNAME(GLOBAL,_context);                  \
-        MPIU_THREAD_CHECK_END;                                          \
-    } while (0)
-
-#define MPIU_THREAD_CS_YIELD_GLOBAL(_context)                           \
-    do {                                                                \
-        MPIU_THREAD_CHECK_BEGIN;                                        \
-        MPIU_THREAD_CS_YIELD_LOCKNAME(GLOBAL,_context);                 \
-        MPIU_THREAD_CHECK_END;                                          \
-    } while (0)
-
+/* GLOBAL locks are all real ops */
+#define MPIU_THREAD_CS_ENTER_GLOBAL(mutex) MPIU_THREAD_CS_ENTER_REAL("GLOBAL", mutex)
+#define MPIU_THREAD_CS_EXIT_GLOBAL(mutex) MPIU_THREAD_CS_EXIT_REAL("GLOBAL", mutex)
+#define MPIU_THREAD_CS_YIELD_GLOBAL(mutex) MPIU_THREAD_CS_YIELD_REAL("GLOBAL", mutex)
 
 /* POBJ locks are all NO-OPs */
-#define MPIU_THREAD_CS_ENTER_POBJ(_context)
-#define MPIU_THREAD_CS_EXIT_POBJ(_context)
-#define MPIU_THREAD_CS_YIELD_POBJ(_context)
+#define MPIU_THREAD_CS_ENTER_POBJ(mutex)
+#define MPIU_THREAD_CS_EXIT_POBJ(mutex)
+#define MPIU_THREAD_CS_YIELD_POBJ(mutex)
 
 
 /* define a type for the completion counter */
diff --git a/src/util/thread/mpiu_thread_multiple.h b/src/util/thread/mpiu_thread_multiple.h
index 834a69a..a4e88c1 100644
--- a/src/util/thread/mpiu_thread_multiple.h
+++ b/src/util/thread/mpiu_thread_multiple.h
@@ -12,28 +12,35 @@
 #define MPIU_THREAD_CHECK_BEGIN if (MPIR_ThreadInfo.isThreaded) {
 #define MPIU_THREAD_CHECK_END   }
 
-#define MPIU_THREAD_CS_ENTER(_name,_context) MPIU_THREAD_CS_ENTER_##_name(_context)
-#define MPIU_THREAD_CS_EXIT(_name,_context) MPIU_THREAD_CS_EXIT_##_name(_context)
-#define MPIU_THREAD_CS_YIELD(_name,_context) MPIU_THREAD_CS_YIELD_##_name(_context)
-
-#define MPIU_THREAD_CS_ENTER_LOCKNAME(name_,mutex_)                     \
+#define MPIU_THREAD_CS_ENTER_REAL(lockname, mutex)                      \
     do {                                                                \
-        MPIU_DBG_MSG_S(THREAD,VERBOSE,"attempting to ENTER lockname=%s", #name_); \
-        MPIU_Thread_CS_enter_lockname_impl_(#name_, &mutex_);           \
+        int err_;                                                       \
+        MPIU_THREAD_CHECK_BEGIN;                                        \
+        MPIU_DBG_MSG_S(THREAD, TYPICAL, "locking %s", lockname);        \
+        MPIU_Thread_mutex_lock(&mutex, &err_);                          \
+        MPIU_THREAD_CHECK_END;                                          \
     } while (0)
 
-#define MPIU_THREAD_CS_EXIT_LOCKNAME(name_,mutex_)                      \
+#define MPIU_THREAD_CS_EXIT_REAL(lockname, mutex)                       \
     do {                                                                \
-        MPIU_DBG_MSG_S(THREAD,VERBOSE,"attempting to EXIT lockname=%s", #name_); \
-        MPIU_Thread_CS_exit_lockname_impl_(#name_, &mutex_);            \
+        int err_;                                                       \
+        MPIU_THREAD_CHECK_BEGIN;                                        \
+        MPIU_DBG_MSG_S(THREAD, TYPICAL, "unlocking %s", lockname);      \
+        MPIU_Thread_mutex_unlock(&mutex, &err_);                        \
+        MPIU_THREAD_CHECK_END;                                          \
     } while (0)
 
-#define MPIU_THREAD_CS_YIELD_LOCKNAME(name_,mutex_)                     \
+#define MPIU_THREAD_CS_YIELD_REAL(lockname, mutex)                      \
     do {                                                                \
-        MPIU_DBG_MSG_S(THREAD,VERBOSE,"attempting to YIELD lockname=%s", #name_); \
-        MPIU_Thread_CS_yield_lockname_impl_(#name_, &mutex_);           \
+        MPIU_THREAD_CHECK_BEGIN;                                        \
+        MPIU_DBG_MSG_S(THREAD, TYPICAL, "yielding %s", lockname);       \
+        MPIU_Thread_yield(&mutex);                                      \
+        MPIU_THREAD_CHECK_END;                                          \
     } while (0)
 
+#define MPIU_THREAD_CS_ENTER(name, mutex) MPIU_THREAD_CS_ENTER_##name(mutex)
+#define MPIU_THREAD_CS_EXIT(name, mutex) MPIU_THREAD_CS_EXIT_##name(mutex)
+#define MPIU_THREAD_CS_YIELD(name, mutex) MPIU_THREAD_CS_YIELD_##name(mutex)
 
 /* Definitions of the thread support for various levels of thread granularity */
 #if MPICH_THREAD_GRANULARITY == MPIR_THREAD_GRANULARITY_GLOBAL
@@ -46,49 +53,4 @@
 #error Unrecognized thread granularity
 #endif
 
-
-#undef FUNCNAME
-#define FUNCNAME MPIU_Thread_CS_enter_lockname_impl_
-#undef FCNAME
-#define FCNAME MPL_QUOTE(FUNCNAME)
-/* these are inline functions instead of macros to avoid some of the
- * MPIU_THREADPRIV_DECL scoping issues */
-MPL_DBG_ATTRIBUTE_NOINLINE ATTRIBUTE((unused))
-static MPL_DBG_INLINE_KEYWORD void
-MPIU_Thread_CS_enter_lockname_impl_(const char *lockname, MPIU_Thread_mutex_t * mutex)
-{
-    int err;
-    MPIU_DBG_MSG_S(THREAD, TYPICAL, "locking %s", lockname);
-    MPIU_Thread_mutex_lock(mutex, &err);
-}
-
-#undef FUNCNAME
-#define FUNCNAME MPIU_Thread_CS_exit_lockname_impl_
-#undef FCNAME
-#define FCNAME MPL_QUOTE(FUNCNAME)
-MPL_DBG_ATTRIBUTE_NOINLINE ATTRIBUTE((unused))
-static MPL_DBG_INLINE_KEYWORD void
-MPIU_Thread_CS_exit_lockname_impl_(const char *lockname, MPIU_Thread_mutex_t * mutex)
-{
-    int err;
-    MPIU_DBG_MSG_S(THREAD, TYPICAL, "unlocking %s", lockname);
-    MPIU_Thread_mutex_unlock(mutex, &err);
-}
-
-#undef FUNCNAME
-#define FUNCNAME MPIU_Thread_CS_yield_lockname_impl_
-#undef FCNAME
-#define FCNAME MPL_QUOTE(FUNCNAME)
-MPL_DBG_ATTRIBUTE_NOINLINE ATTRIBUTE((unused))
-static MPL_DBG_INLINE_KEYWORD void
-MPIU_Thread_CS_yield_lockname_impl_(const char *lockname, MPIU_Thread_mutex_t * mutex)
-{
-    MPIU_DBG_MSG_S(THREAD, TYPICAL, "yielding %s", lockname);
-    MPIU_Thread_yield(mutex);
-}
-
-/* undef for safety, this is a commonly-included header */
-#undef FUNCNAME
-#undef FCNAME
-
 #endif /* !defined(MPIU_THREAD_MULTIPLE_H_INCLUDED) */
diff --git a/src/util/thread/mpiu_thread_pobj.h b/src/util/thread/mpiu_thread_pobj.h
index 40b287c..5145303 100644
--- a/src/util/thread/mpiu_thread_pobj.h
+++ b/src/util/thread/mpiu_thread_pobj.h
@@ -74,31 +74,15 @@
  * the order should be to acquire MPIDCOMM first, then MSGQUEUE.  Release in
  * reverse order. */
 
-#define MPIU_THREAD_CS_ENTER_GLOBAL(_context)
-#define MPIU_THREAD_CS_EXIT_GLOBAL(_context)
-#define MPIU_THREAD_CS_YIELD_GLOBAL(_context)
-
-#define MPIU_THREAD_CS_ENTER_POBJ(_context)             \
-    do {                                                \
-        MPIU_THREAD_CHECK_BEGIN;                        \
-        MPIU_THREAD_CS_ENTER_LOCKNAME(POBJ,_context);   \
-        MPIU_THREAD_CHECK_END;                          \
-    } while (0)
-
-#define MPIU_THREAD_CS_EXIT_POBJ(_context)              \
-    do {                                                \
-        MPIU_THREAD_CHECK_BEGIN;                        \
-        MPIU_THREAD_CS_EXIT_LOCKNAME(POBJ,_context);    \
-        MPIU_THREAD_CHECK_END;                          \
-    } while (0)
-
-#define MPIU_THREAD_CS_YIELD_POBJ(_context)             \
-    do {                                                \
-        MPIU_THREAD_CHECK_BEGIN;                        \
-        MPIU_THREAD_CS_YIELD_LOCKNAME(POBJ,_context);   \
-        MPIU_THREAD_CHECK_END;                          \
-    } while (0)
-
+/* POBJ locks are all real ops */
+#define MPIU_THREAD_CS_ENTER_POBJ(mutex) MPIU_THREAD_CS_ENTER_REAL("POBJ", mutex)
+#define MPIU_THREAD_CS_EXIT_POBJ(mutex) MPIU_THREAD_CS_EXIT_REAL("POBJ", mutex)
+#define MPIU_THREAD_CS_YIELD_POBJ(mutex) MPIU_THREAD_CS_YIELD_REAL("POBJ", mutex)
+
+/* GLOBAL locks are all NO-OPs */
+#define MPIU_THREAD_CS_ENTER_GLOBAL(mutex)
+#define MPIU_THREAD_CS_EXIT_GLOBAL(mutex)
+#define MPIU_THREAD_CS_YIELD_GLOBAL(mutex)
 
 /* define a type for the completion counter */
 #include "opa_primitives.h"

http://git.mpich.org/mpich.git/commitdiff/fa11ecd3c995d3b4cc86a58366ac90ae814f2f9d

commit fa11ecd3c995d3b4cc86a58366ac90ae814f2f9d
Author: Pavan Balaji <balaji at anl.gov>
Date:   Tue Aug 18 14:13:27 2015 -0500

    Get rid of recursive locks.
    
    Now that ROMIO internally maintains thread safety for its pieces, we
    no longer need recursive locks.
    
    Signed-off-by: Rob Latham <robl at mcs.anl.gov>

diff --git a/src/mpi/init/initthread.c b/src/mpi/init/initthread.c
index 3c5da8c..03af8d0 100644
--- a/src/mpi/init/initthread.c
+++ b/src/mpi/init/initthread.c
@@ -168,8 +168,6 @@ static int thread_cs_init( void )
     int err;
     MPIU_THREADPRIV_DECL;
 
-    MPIU_Assert(MPICH_MAX_LOCKS >= MPIU_NEST_NUM_MUTEXES);
-
     /* we create this at all granularities right now */
     MPID_Thread_mutex_create(&MPIR_THREAD_MEMALLOC_MUTEX, &err);
     MPIU_Assert(err == 0);
diff --git a/src/util/thread/mpiu_thread.h b/src/util/thread/mpiu_thread.h
index fc07114..83b8e3d 100644
--- a/src/util/thread/mpiu_thread.h
+++ b/src/util/thread/mpiu_thread.h
@@ -125,7 +125,6 @@ typedef struct MPICH_ThreadInfo_t {
 #if MPICH_THREAD_GRANULARITY == MPIR_THREAD_GRANULARITY_GLOBAL || \
     MPICH_THREAD_GRANULARITY == MPIR_THREAD_GRANULARITY_PER_OBJECT
     MPIU_Thread_mutex_t global_mutex;
-    /* We need the handle mutex to avoid problems with lock nesting */
     MPIU_Thread_mutex_t handle_mutex;
 #endif
 
@@ -161,9 +160,6 @@ extern MPICH_ThreadInfo_t MPIR_ThreadInfo;
  * destruction time */
 #define MPIU_STRERROR_BUF_SIZE (1024)
 
-/* FIXME should really be MPIU_NEST_NUM_MUTEXES, but it's defined later */
-#define MPICH_MAX_LOCKS (6)
-
 /* This structure contains all thread-local variables and will be zeroed at
  * allocation time.
  *
@@ -175,10 +171,6 @@ typedef struct MPICH_PerThread_t {
 
     /* error string storage for MPIU_Strerror */
     char strerrbuf[MPIU_STRERROR_BUF_SIZE];
-
-#if (MPICH_THREAD_LEVEL >= MPI_THREAD_SERIALIZED)
-    int lock_depth[MPICH_MAX_LOCKS];
-#endif
 } MPICH_PerThread_t;
 
 #if defined (MPICH_IS_THREADED)
diff --git a/src/util/thread/mpiu_thread_global.h b/src/util/thread/mpiu_thread_global.h
index d99944f..371c26b 100644
--- a/src/util/thread/mpiu_thread_global.h
+++ b/src/util/thread/mpiu_thread_global.h
@@ -8,28 +8,24 @@
 #define MPIU_THREAD_GLOBAL_H_INCLUDED
 
 /* There is a single, global lock, held for the duration of an MPI call */
-/* FIXME this shouldn't need to be recursive, but using a recursive mutex here
- * greatly simplifies thread safety in ROMIO right now.  In the long term we
- * should make ROMIO internally thread safe and then this can go back to being a
- * non-recursive mutex. [goodell@ 2010-10-15] */
 #define MPIU_THREAD_CS_ENTER_GLOBAL(_context)                           \
     do {                                                                \
         MPIU_THREAD_CHECK_BEGIN;                                        \
-        MPIU_THREAD_CS_ENTER_LOCKNAME_RECURSIVE(GLOBAL,_context);       \
+        MPIU_THREAD_CS_ENTER_LOCKNAME(GLOBAL,_context);                 \
         MPIU_THREAD_CHECK_END;                                          \
     } while (0)
 
 #define MPIU_THREAD_CS_EXIT_GLOBAL(_context)                            \
     do {                                                                \
         MPIU_THREAD_CHECK_BEGIN;                                        \
-        MPIU_THREAD_CS_EXIT_LOCKNAME_RECURSIVE(GLOBAL,_context);        \
+        MPIU_THREAD_CS_EXIT_LOCKNAME(GLOBAL,_context);                  \
         MPIU_THREAD_CHECK_END;                                          \
     } while (0)
 
 #define MPIU_THREAD_CS_YIELD_GLOBAL(_context)                           \
     do {                                                                \
         MPIU_THREAD_CHECK_BEGIN;                                        \
-        MPIU_THREAD_CS_YIELD_LOCKNAME_RECURSIVE(GLOBAL,_context);       \
+        MPIU_THREAD_CS_YIELD_LOCKNAME(GLOBAL,_context);                 \
         MPIU_THREAD_CHECK_END;                                          \
     } while (0)
 
diff --git a/src/util/thread/mpiu_thread_multiple.h b/src/util/thread/mpiu_thread_multiple.h
index 20ec810..834a69a 100644
--- a/src/util/thread/mpiu_thread_multiple.h
+++ b/src/util/thread/mpiu_thread_multiple.h
@@ -16,26 +16,6 @@
 #define MPIU_THREAD_CS_EXIT(_name,_context) MPIU_THREAD_CS_EXIT_##_name(_context)
 #define MPIU_THREAD_CS_YIELD(_name,_context) MPIU_THREAD_CS_YIELD_##_name(_context)
 
-/* recursive locks */
-#define MPIU_THREAD_CS_ENTER_LOCKNAME_RECURSIVE(name_,mutex_)           \
-    do {                                                                \
-        MPIU_DBG_MSG_S(THREAD,VERBOSE,"attempting to recursively ENTER lockname=%s", #name_); \
-        MPIU_Thread_CS_enter_lockname_recursive_impl_(MPIU_NEST_##name_, #name_, &mutex_); \
-    } while (0)
-
-#define MPIU_THREAD_CS_EXIT_LOCKNAME_RECURSIVE(name_,mutex_)            \
-    do {                                                                \
-        MPIU_DBG_MSG_S(THREAD,VERBOSE,"attempting to recursively EXIT lockname=%s", #name_); \
-        MPIU_Thread_CS_exit_lockname_recursive_impl_(MPIU_NEST_##name_, #name_, &mutex_); \
-    } while (0)
-
-#define MPIU_THREAD_CS_YIELD_LOCKNAME_RECURSIVE(name_,mutex_)           \
-    do {                                                                \
-        MPIU_DBG_MSG_S(THREAD,VERBOSE,"attempting to recursively YIELD lockname=%s", #name_); \
-        MPIU_Thread_CS_yield_lockname_recursive_impl_(MPIU_NEST_##name_, #name_, &mutex_); \
-    } while (0)
-
-/* regular locks */
 #define MPIU_THREAD_CS_ENTER_LOCKNAME(name_,mutex_)                     \
     do {                                                                \
         MPIU_DBG_MSG_S(THREAD,VERBOSE,"attempting to ENTER lockname=%s", #name_); \
@@ -55,13 +35,6 @@
     } while (0)
 
 
-enum MPIU_Nest_mutexes {
-    MPIU_NEST_GLOBAL = 0,
-    MPIU_NEST_POBJ,     /* Nesting does not really make sense for POBJ */
-    MPIU_NEST_NUM_MUTEXES
-};
-
-
 /* Definitions of the thread support for various levels of thread granularity */
 #if MPICH_THREAD_GRANULARITY == MPIR_THREAD_GRANULARITY_GLOBAL
 #include "mpiu_thread_global.h"
@@ -114,85 +87,6 @@ MPIU_Thread_CS_yield_lockname_impl_(const char *lockname, MPIU_Thread_mutex_t *
     MPIU_Thread_yield(mutex);
 }
 
-/* ------------------------------------------------------------------- */
-/* recursive versions, these are for the few locks where it is difficult or
- * impossible to eliminate recursive locking usage */
-
-#undef FUNCNAME
-#define FUNCNAME MPIU_Thread_CS_enter_lockname_recursive_impl_
-#undef FCNAME
-#define FCNAME MPL_QUOTE(FUNCNAME)
-/* these are inline functions instead of macros to avoid some of the
- * MPIU_THREADPRIV_DECL scoping issues */
-MPL_DBG_ATTRIBUTE_NOINLINE ATTRIBUTE((unused))
-static MPL_DBG_INLINE_KEYWORD void
-MPIU_Thread_CS_enter_lockname_recursive_impl_(enum MPIU_Nest_mutexes kind,
-                                              const char *lockname, MPIU_Thread_mutex_t * mutex)
-{
-    int depth, err;
-    MPIU_THREADPRIV_DECL;
-    MPIU_THREADPRIV_GET;
-    depth = MPIU_THREADPRIV_FIELD(lock_depth)[kind];
-    MPIU_DBG_MSG_D(THREAD, TYPICAL, "recursive enter, depth=%d", depth);
-
-    MPIU_Assert(depth >= 0 && depth < 10);      /* probably a mismatch if we hit this */
-
-    if (depth == 0) {
-        MPIU_DBG_MSG_S(THREAD, TYPICAL, "locking %s", lockname);
-        MPIU_Thread_mutex_lock(mutex, &err);
-    }
-    MPIU_THREADPRIV_FIELD(lock_depth)[kind] += 1;
-}
-
-#undef FUNCNAME
-#define FUNCNAME MPIU_Thread_CS_exit_lockname_recursive_impl_
-#undef FCNAME
-#define FCNAME MPL_QUOTE(FUNCNAME)
-MPL_DBG_ATTRIBUTE_NOINLINE ATTRIBUTE((unused))
-static MPL_DBG_INLINE_KEYWORD void
-MPIU_Thread_CS_exit_lockname_recursive_impl_(enum MPIU_Nest_mutexes kind,
-                                             const char *lockname, MPIU_Thread_mutex_t * mutex)
-{
-    int depth, err;
-    MPIU_THREADPRIV_DECL;
-    MPIU_THREADPRIV_GET;
-    depth = MPIU_THREADPRIV_FIELD(lock_depth)[kind];
-    MPIU_DBG_MSG_D(THREAD, TYPICAL, "recursive exit, depth=%d", depth);
-
-    MPIU_Assert(depth > 0 && depth < 10);       /* probably a mismatch if we hit this */
-
-    if (depth == 1) {
-        MPIU_DBG_MSG_S(THREAD, TYPICAL, "unlocking %s", lockname);
-        MPIU_Thread_mutex_unlock(mutex, &err);
-        MPIU_Assert_fmt_msg(err == MPIU_THREAD_SUCCESS,
-                            ("mutex_unlock failed, err=%d (%s)", err, MPIU_Strerror(err)));
-
-    }
-    MPIU_THREADPRIV_FIELD(lock_depth)[kind] -= 1;
-}
-
-#undef FUNCNAME
-#define FUNCNAME MPIU_Thread_CS_yield_lockname_recursive_impl_
-#undef FCNAME
-#define FCNAME MPL_QUOTE(FUNCNAME)
-MPL_DBG_ATTRIBUTE_NOINLINE ATTRIBUTE((unused))
-static MPL_DBG_INLINE_KEYWORD void
-MPIU_Thread_CS_yield_lockname_recursive_impl_(enum MPIU_Nest_mutexes kind,
-                                              const char *lockname, MPIU_Thread_mutex_t * mutex)
-{
-    int depth ATTRIBUTE((unused));
-    MPIU_THREADPRIV_DECL;
-    MPIU_THREADPRIV_GET;
-    depth = MPIU_THREADPRIV_FIELD(lock_depth)[kind];
-    MPIU_DBG_MSG_D(THREAD, TYPICAL, "recursive yield, depth=%d", depth);
-
-    MPIU_Assert(depth > 0 && depth < 10);       /* we must hold the mutex */
-    /* no need to update depth, this is a thread-local value */
-
-    MPIU_DBG_MSG_S(THREAD, TYPICAL, "yielding %s", lockname);
-    MPIU_Thread_yield(mutex);
-}
-
 /* undef for safety, this is a commonly-included header */
 #undef FUNCNAME
 #undef FCNAME

http://git.mpich.org/mpich.git/commitdiff/d484022edb5f865760b063b9908895bdbfbef7fb

commit d484022edb5f865760b063b9908895bdbfbef7fb
Author: Rob Latham <robl at mcs.anl.gov>
Date:   Tue Aug 18 14:53:32 2015 -0500

    sync ROMIO locations that touch global state
    
    Lock entry/ unlock exit points for those parts of ROMIO touching global
    state.  Global state appears to be
    - flattened datatype representation
    - the cb_config_list
    - the error handler
    - user define data representation
    - some f2c and c2f bookeeping structures
    
    This patch also assumes that ROMIO always resides within MPICH.  We
    are dropping support for non-MPICH builds of ROMIO.
    
    Signed-off-by: Pavan Balaji <balaji at anl.gov>

diff --git a/src/mpi/romio/adio/common/ad_end.c b/src/mpi/romio/adio/common/ad_end.c
index 76712ae..2350f0a 100644
--- a/src/mpi/romio/adio/common/ad_end.c
+++ b/src/mpi/romio/adio/common/ad_end.c
@@ -61,6 +61,8 @@ void ADIO_End(int *error_code)
 int ADIOI_End_call(MPI_Comm comm, int keyval, void *attribute_val, void
 		  *extra_state)
 {
+    /* though we are touching global variables here, only one thread can call
+     * MPI_Finalize so we can be less carefuil w. r. t. critical sections */
     int error_code;
 
     ADIOI_UNREFERENCED_ARG(comm);
diff --git a/src/mpi/romio/adio/common/cb_config_list.c b/src/mpi/romio/adio/common/cb_config_list.c
index 626709f..60cb6c1 100644
--- a/src/mpi/romio/adio/common/cb_config_list.c
+++ b/src/mpi/romio/adio/common/cb_config_list.c
@@ -133,6 +133,7 @@ int ADIOI_cb_gather_name_array(MPI_Comm comm,
     ADIO_cb_name_array array = NULL;
     int alloc_size;
 
+    MPIR_Ext_cs_enter(ADIO_THREAD_MUTEX);
     if (ADIOI_cb_config_list_keyval == MPI_KEYVAL_INVALID) {
         /* cleaned up by ADIOI_End_call */
 	MPI_Keyval_create((MPI_Copy_function *) ADIOI_cb_copy_name_array, 
@@ -147,6 +148,7 @@ int ADIOI_cb_gather_name_array(MPI_Comm comm,
 	    return 0;
 	}
     }
+    MPIR_Ext_cs_exit(ADIO_THREAD_MUTEX);
 
     MPI_Comm_size(dupcomm, &commsize);
     MPI_Comm_rank(dupcomm, &commrank);
diff --git a/src/mpi/romio/adio/common/flatten.c b/src/mpi/romio/adio/common/flatten.c
index db13a7b..1fb7f54 100644
--- a/src/mpi/romio/adio/common/flatten.c
+++ b/src/mpi/romio/adio/common/flatten.c
@@ -25,6 +25,8 @@ void ADIOI_Flatten_datatype(MPI_Datatype datatype)
     int is_contig;
     ADIOI_Flatlist_node *flat, *prev=0;
 
+    MPIR_Ext_cs_enter(ADIO_THREAD_MUTEX);
+
     /* check if necessary to flatten. */
  
     /* is it entirely contiguous? */
@@ -98,6 +100,7 @@ void ADIOI_Flatten_datatype(MPI_Datatype datatype)
              );
   }
 #endif
+    MPIR_Ext_cs_exit(ADIO_THREAD_MUTEX);
 
 }
 
@@ -1182,6 +1185,7 @@ void ADIOI_Optimize_flattened(ADIOI_Flatlist_node *flat_type)
 void ADIOI_Delete_flattened(MPI_Datatype datatype)
 {
     ADIOI_Flatlist_node *flat, *prev;
+    MPIR_Ext_cs_enter(ADIO_THREAD_MUTEX);
 
     prev = flat = ADIOI_Flatlist;
     while (flat && (flat->type != datatype)) {
@@ -1194,13 +1198,16 @@ void ADIOI_Delete_flattened(MPI_Datatype datatype)
 	if (flat->indices) ADIOI_Free(flat->indices);
 	ADIOI_Free(flat);
     }
+    MPIR_Ext_cs_exit(ADIO_THREAD_MUTEX);
 }
 
 ADIOI_Flatlist_node * ADIOI_Flatten_and_find(MPI_Datatype datatype)
 {
     ADIOI_Flatlist_node *node;
+    MPIR_Ext_cs_enter(ADIO_THREAD_MUTEX);
     ADIOI_Flatten_datatype(datatype);
     node = ADIOI_Flatlist;
     while (node->type != datatype) node = node->next;
+    MPIR_Ext_cs_exit(ADIO_THREAD_MUTEX);
     return node;
 }
diff --git a/src/mpi/romio/mpi-io/glue/mpich/mpio_file.c b/src/mpi/romio/mpi-io/glue/mpich/mpio_file.c
index 6f6c902..0aabe27 100644
--- a/src/mpi/romio/mpi-io/glue/mpich/mpio_file.c
+++ b/src/mpi/romio/mpi-io/glue/mpich/mpio_file.c
@@ -69,6 +69,7 @@ MPI_Fint MPIO_File_c2f(MPI_File fh)
     if (fh->fortran_handle != -1)
 	return fh->fortran_handle;
 
+    MPIR_Ext_cs_enter(ADIO_THREAD_MUTEX);
     if (!ADIOI_Ftable) {
 	ADIOI_Ftable_max = 1024;
 	ADIOI_Ftable = (MPI_File *)
@@ -87,6 +88,7 @@ MPI_Fint MPIO_File_c2f(MPI_File fh)
     ADIOI_Ftable_ptr++;
     ADIOI_Ftable[ADIOI_Ftable_ptr] = fh;
     fh->fortran_handle = ADIOI_Ftable_ptr;
+    MPIR_Ext_cs_exit(ADIO_THREAD_MUTEX);
     return (MPI_Fint) ADIOI_Ftable_ptr;
 #endif
 }

http://git.mpich.org/mpich.git/commitdiff/da4f2e5f73ed4dcfff87fe11ec49b602da9c9447

commit da4f2e5f73ed4dcfff87fe11ec49b602da9c9447
Author: Rob Latham <robl at mcs.anl.gov>
Date:   Tue Aug 18 14:06:01 2015 -0500

    move flattend resolution to a separate function
    
    if we do this "flatten type, then find it in the global linked list" in
    a separate function, we can make that function thread-safe instead of
    sprinking lock/unlock code through 50 locations in ROMIO
    
    Signed-off-by: Pavan Balaji <balaji at anl.gov>

diff --git a/src/mpi/romio/adio/ad_gpfs/ad_gpfs_rdcoll.c b/src/mpi/romio/adio/ad_gpfs/ad_gpfs_rdcoll.c
index 355ad22..dd71643 100644
--- a/src/mpi/romio/adio/ad_gpfs/ad_gpfs_rdcoll.c
+++ b/src/mpi/romio/adio/ad_gpfs/ad_gpfs_rdcoll.c
@@ -534,9 +534,7 @@ static void ADIOI_Read_and_exch(ADIO_File fd, void *buf, MPI_Datatype
 
     ADIOI_Datatype_iscontig(datatype, &buftype_is_contig);
     if (!buftype_is_contig) {
-	ADIOI_Flatten_datatype(datatype);
-	flat_buf = ADIOI_Flatlist;
-        while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(datatype);
     }
     MPI_Type_extent(datatype, &buftype_extent);
 
diff --git a/src/mpi/romio/adio/ad_gpfs/ad_gpfs_wrcoll.c b/src/mpi/romio/adio/ad_gpfs/ad_gpfs_wrcoll.c
index b5b7be6..b8d4366 100644
--- a/src/mpi/romio/adio/ad_gpfs/ad_gpfs_wrcoll.c
+++ b/src/mpi/romio/adio/ad_gpfs/ad_gpfs_wrcoll.c
@@ -658,9 +658,7 @@ static void ADIOI_Exch_and_write(ADIO_File fd, const void *buf, MPI_Datatype
 
     ADIOI_Datatype_iscontig(datatype, &buftype_is_contig);
     if (!buftype_is_contig) {
-	ADIOI_Flatten_datatype(datatype);
-	flat_buf = ADIOI_Flatlist;
-        while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(dataype);
     }
     MPI_Type_extent(datatype, &buftype_extent);
 
diff --git a/src/mpi/romio/adio/ad_gridftp/ad_gridftp_read.c b/src/mpi/romio/adio/ad_gridftp/ad_gridftp_read.c
index 6a0fc9c..19351b7 100644
--- a/src/mpi/romio/adio/ad_gridftp/ad_gridftp_read.c
+++ b/src/mpi/romio/adio/ad_gridftp/ad_gridftp_read.c
@@ -241,10 +241,7 @@ void ADIOI_GRIDFTP_ReadDiscontig(ADIO_File fd, void *buf, int count,
     /* from here we can assume btype_extent==btype_size */
 
     /* Flatten out fd->filetype so we know which blocks to skip */
-    ADIOI_Flatten_datatype(fd->filetype);
-    flat_file = ADIOI_Flatlist;
-    while (flat_file->type != fd->filetype && flat_file->next!=NULL)
-	flat_file = flat_file->next;
+    flat_file = ADIOI_Flatten_and_find(fd->filetype);
 
     /* Figure out how big the area to read is */
     start=(globus_off_t)(offset*etype_size);
diff --git a/src/mpi/romio/adio/ad_gridftp/ad_gridftp_write.c b/src/mpi/romio/adio/ad_gridftp/ad_gridftp_write.c
index 0400dae..22e2523 100644
--- a/src/mpi/romio/adio/ad_gridftp/ad_gridftp_write.c
+++ b/src/mpi/romio/adio/ad_gridftp/ad_gridftp_write.c
@@ -242,10 +242,7 @@ void ADIOI_GRIDFTP_WriteDiscontig(ADIO_File fd, void *buf, int count,
     /* from here we can assume btype_extent==btype_size */
 
     /* Flatten out fd->filetype so we know which blocks to skip */
-    ADIOI_Flatten_datatype(fd->filetype);
-    flat_file = ADIOI_Flatlist;
-    while (flat_file->type != fd->filetype && flat_file->next!=NULL)
-	flat_file = flat_file->next;
+    flat_file = ADIOI_Flatten_and_find(fd->filetype);
 
     /* Figure out how big the area to write is */
     /* ASSUMPTION: ftype_size is an integer multiple of btype_size or vice versa. */
diff --git a/src/mpi/romio/adio/ad_lustre/ad_lustre_wrcoll.c b/src/mpi/romio/adio/ad_lustre/ad_lustre_wrcoll.c
index 774cb53..9dca62d 100644
--- a/src/mpi/romio/adio/ad_lustre/ad_lustre_wrcoll.c
+++ b/src/mpi/romio/adio/ad_lustre/ad_lustre_wrcoll.c
@@ -415,10 +415,7 @@ static void ADIOI_LUSTRE_Exch_and_write(ADIO_File fd, const void *buf,
 
     ADIOI_Datatype_iscontig(datatype, &buftype_is_contig);
     if (!buftype_is_contig) {
-	ADIOI_Flatten_datatype(datatype);
-	flat_buf = ADIOI_Flatlist;
-	while (flat_buf->type != datatype)
-	    flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(datatype);
     }
     MPI_Type_extent(datatype, &buftype_extent);
     /* I need to check if there are any outstanding nonblocking writes to
diff --git a/src/mpi/romio/adio/ad_lustre/ad_lustre_wrstr.c b/src/mpi/romio/adio/ad_lustre/ad_lustre_wrstr.c
index 2f1ffb9..071c51e 100644
--- a/src/mpi/romio/adio/ad_lustre/ad_lustre_wrstr.c
+++ b/src/mpi/romio/adio/ad_lustre/ad_lustre_wrstr.c
@@ -209,10 +209,7 @@ void ADIOI_LUSTRE_WriteStrided(ADIO_File fd, const void *buf, int count,
     /* Different buftype to different filetype */
     if (!buftype_is_contig && filetype_is_contig) {
         /* noncontiguous in memory, contiguous in file. */
-	ADIOI_Flatten_datatype(datatype);
-	flat_buf = ADIOI_Flatlist;
-	while (flat_buf->type != datatype)
-	    flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(datatype);
 
 	off = (file_ptr_type == ADIO_INDIVIDUAL) ? fd->fp_ind :
             fd->disp + (ADIO_Offset)etype_size * offset;
@@ -436,10 +433,7 @@ void ADIOI_LUSTRE_WriteStrided(ADIO_File fd, const void *buf, int count,
         }
         else {
 /* noncontiguous in memory as well as in file */
-
-	        ADIOI_Flatten_datatype(datatype);
-	        flat_buf = ADIOI_Flatlist;
-            while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	    flat_buf = ADIOI_Flatten_and_find(datatype);
 
 		k = num = buf_count = 0;
             i_offset = flat_buf->indices[0];
diff --git a/src/mpi/romio/adio/ad_nfs/ad_nfs_read.c b/src/mpi/romio/adio/ad_nfs/ad_nfs_read.c
index 18dfde7..dd2f1c8 100644
--- a/src/mpi/romio/adio/ad_nfs/ad_nfs_read.c
+++ b/src/mpi/romio/adio/ad_nfs/ad_nfs_read.c
@@ -215,9 +215,7 @@ void ADIOI_NFS_ReadStrided(ADIO_File fd, void *buf, int count,
 
 /* noncontiguous in memory, contiguous in file. */
 
-	ADIOI_Flatten_datatype(datatype);
-	flat_buf = ADIOI_Flatlist;
-	while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(datatype);
 
         off = (file_ptr_type == ADIO_INDIVIDUAL) ? fd->fp_ind : 
                  fd->disp + etype_size * offset;
@@ -460,9 +458,7 @@ void ADIOI_NFS_ReadStrided(ADIO_File fd, void *buf, int count,
 	else {
 /* noncontiguous in memory as well as in file */
 
-	    ADIOI_Flatten_datatype(datatype);
-	    flat_buf = ADIOI_Flatlist;
-	    while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	    flat_buf = ADIOI_Flatten_and_find(datatype);
 
 	    k = num = buf_count = 0;
 	    i = (int) (flat_buf->indices[0]);
diff --git a/src/mpi/romio/adio/ad_nfs/ad_nfs_write.c b/src/mpi/romio/adio/ad_nfs/ad_nfs_write.c
index 660e868..d9ee5d2 100644
--- a/src/mpi/romio/adio/ad_nfs/ad_nfs_write.c
+++ b/src/mpi/romio/adio/ad_nfs/ad_nfs_write.c
@@ -318,9 +318,7 @@ void ADIOI_NFS_WriteStrided(ADIO_File fd, const void *buf, int count,
 
 /* noncontiguous in memory, contiguous in file. */
 
-	ADIOI_Flatten_datatype(datatype);
-	flat_buf = ADIOI_Flatlist;
-	while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(datatype);
 
         off = (file_ptr_type == ADIO_INDIVIDUAL) ? fd->fp_ind : 
                  fd->disp + etype_size * offset;
@@ -565,9 +563,7 @@ void ADIOI_NFS_WriteStrided(ADIO_File fd, const void *buf, int count,
 	else {
 /* noncontiguous in memory as well as in file */
 
-	    ADIOI_Flatten_datatype(datatype);
-	    flat_buf = ADIOI_Flatlist;
-	    while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	    flat_buf = ADIOI_Flatten_and_find(datatype);
 
 	    k = num = buf_count = 0;
 	    i = (int) (flat_buf->indices[0]);
diff --git a/src/mpi/romio/adio/ad_piofs/ad_piofs_write.c b/src/mpi/romio/adio/ad_piofs/ad_piofs_write.c
index 4e1c7f1..4da38ba 100644
--- a/src/mpi/romio/adio/ad_piofs/ad_piofs_write.c
+++ b/src/mpi/romio/adio/ad_piofs/ad_piofs_write.c
@@ -112,9 +112,7 @@ void ADIOI_PIOFS_WriteStrided(ADIO_File fd, void *buf, int count,
 
 /* noncontiguous in memory, contiguous in file. use writev */
 
-	ADIOI_Flatten_datatype(datatype);
-	flat_buf = ADIOI_Flatlist;
-	while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(datatype);
 
 /* There is a limit of 16 on the number of iovecs for readv/writev! */
 
@@ -258,9 +256,7 @@ void ADIOI_PIOFS_WriteStrided(ADIO_File fd, void *buf, int count,
 	else {
 /* noncontiguous in memory as well as in file */
 
-	    ADIOI_Flatten_datatype(datatype);
-	    flat_buf = ADIOI_Flatlist;
-	    while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	    flat_buf = ADIOI_Flatten_and_find(datatype);
 
 	    k = num = buf_count = 0;
 	    indx = flat_buf->indices[0];
diff --git a/src/mpi/romio/adio/ad_pvfs/ad_pvfs_read.c b/src/mpi/romio/adio/ad_pvfs/ad_pvfs_read.c
index 71b558a..1d294ea 100644
--- a/src/mpi/romio/adio/ad_pvfs/ad_pvfs_read.c
+++ b/src/mpi/romio/adio/ad_pvfs/ad_pvfs_read.c
@@ -171,9 +171,7 @@ void ADIOI_PVFS_ReadStridedListIO(ADIO_File fd, void *buf, int count,
         int64_t file_offsets;
 	int32_t file_lengths;
 
-	ADIOI_Flatten_datatype(datatype);
-	flat_buf = ADIOI_Flatlist;
-	while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(datatype);
 
 	off = (file_ptr_type == ADIO_INDIVIDUAL) ? fd->fp_ind : 
 	    fd->disp + etype_size * offset;
@@ -415,9 +413,7 @@ void ADIOI_PVFS_ReadStridedListIO(ADIO_File fd, void *buf, int count,
     else {
 /* noncontiguous in memory as well as in file */
       
-        ADIOI_Flatten_datatype(datatype);
-	flat_buf = ADIOI_Flatlist;
-	while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(datatype);
 
 	size_read = 0;
 	n_filetypes = st_n_filetypes;
diff --git a/src/mpi/romio/adio/ad_pvfs/ad_pvfs_write.c b/src/mpi/romio/adio/ad_pvfs/ad_pvfs_write.c
index 4e874d9..5388de4 100644
--- a/src/mpi/romio/adio/ad_pvfs/ad_pvfs_write.c
+++ b/src/mpi/romio/adio/ad_pvfs/ad_pvfs_write.c
@@ -150,9 +150,7 @@ void ADIOI_PVFS_WriteStrided(ADIO_File fd, void *buf, int count,
 	ADIO_Offset combine_buf_remain;
 /* noncontiguous in memory, contiguous in file. use writev */
 
-	ADIOI_Flatten_datatype(datatype);
-	flat_buf = ADIOI_Flatlist;
-	while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(datatype);
 
 	/* allocate our "combine buffer" to pack data into before writing */
 	combine_buf = (char *) ADIOI_Malloc(fd->hints->ind_wr_buffer_size);
@@ -366,9 +364,7 @@ void ADIOI_PVFS_WriteStrided(ADIO_File fd, void *buf, int count,
 	else {
 /* noncontiguous in memory as well as in file */
 
-	    ADIOI_Flatten_datatype(datatype);
-	    flat_buf = ADIOI_Flatlist;
-	    while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	    flat_buf = ADIOI_Flatten_and_find(datatype);
 
 	    k = num = buf_count = 0;
 	    indx = flat_buf->indices[0];
@@ -539,9 +535,7 @@ void ADIOI_PVFS_WriteStridedListIO(ADIO_File fd, void *buf, int count,
         int64_t file_offsets;
 	int32_t file_lengths;
 
-	ADIOI_Flatten_datatype(datatype);
-	flat_buf = ADIOI_Flatlist;
-	while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(datatype);
 	
 	if (file_ptr_type == ADIO_EXPLICIT_OFFSET) {
 	    off = fd->disp + etype_size * offset;
@@ -808,9 +802,7 @@ void ADIOI_PVFS_WriteStridedListIO(ADIO_File fd, void *buf, int count,
     else {
         /* noncontiguous in memory as well as in file */
 
-        ADIOI_Flatten_datatype(datatype);
-	flat_buf = ADIOI_Flatlist;
-	while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(datatype);
 
 	size_wrote = 0;
 	n_filetypes = st_n_filetypes;
diff --git a/src/mpi/romio/adio/ad_pvfs2/ad_pvfs2_io_list.c b/src/mpi/romio/adio/ad_pvfs2/ad_pvfs2_io_list.c
index c5d03d1..39befcc 100644
--- a/src/mpi/romio/adio/ad_pvfs2/ad_pvfs2_io_list.c
+++ b/src/mpi/romio/adio/ad_pvfs2/ad_pvfs2_io_list.c
@@ -82,10 +82,7 @@ int ADIOI_PVFS2_StridedListIO(ADIO_File fd, void *buf, int count,
     ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
     if (buftype_is_contig == 0)
     {
-	ADIOI_Flatten_datatype(datatype);
-	flat_buf_p = ADIOI_Flatlist;
-	while (flat_buf_p->type != datatype) 
-	    flat_buf_p = flat_buf_p->next;
+	flat_buf_p = ADIOI_Flatten_and_find(datatype);
     }
     else 
     {
@@ -108,10 +105,7 @@ int ADIOI_PVFS2_StridedListIO(ADIO_File fd, void *buf, int count,
 	    /* TODO: why does avery say this should already have been
 	     * flattened in Open, but also says contig types don't get
 	     * flattened */
-	ADIOI_Flatten_datatype(fd->filetype);
-	flat_file_p = ADIOI_Flatlist;
-	while (flat_file_p->type != fd->filetype) 
-	    flat_file_p = flat_file_p->next;
+	flat_file_p = ADIOI_Flatten_and_find(fd->filetype);
     }
     else
     {
diff --git a/src/mpi/romio/adio/ad_pvfs2/ad_pvfs2_read_list_classic.c b/src/mpi/romio/adio/ad_pvfs2/ad_pvfs2_read_list_classic.c
index 2aee893..40ff2c1 100644
--- a/src/mpi/romio/adio/ad_pvfs2/ad_pvfs2_read_list_classic.c
+++ b/src/mpi/romio/adio/ad_pvfs2/ad_pvfs2_read_list_classic.c
@@ -93,9 +93,7 @@ void ADIOI_PVFS2_OldReadStrided(ADIO_File fd, void *buf, int count,
        int64_t file_offset;
 	int32_t file_length;
 
-	ADIOI_Flatten_datatype(datatype);
-	flat_buf = ADIOI_Flatlist;
-	while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(datatype);
 
 	off = (file_ptr_type == ADIO_INDIVIDUAL) ? fd->fp_ind : 
 	    fd->disp + etype_size * offset;
@@ -469,9 +467,7 @@ void ADIOI_PVFS2_OldReadStrided(ADIO_File fd, void *buf, int count,
     else {
 /* noncontiguous in memory as well as in file */
       
-        ADIOI_Flatten_datatype(datatype);
-	flat_buf = ADIOI_Flatlist;
-	while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(datatype);
 
 	size_read = 0;
 	n_filetypes = st_n_filetypes;
diff --git a/src/mpi/romio/adio/ad_pvfs2/ad_pvfs2_write_list_classic.c b/src/mpi/romio/adio/ad_pvfs2/ad_pvfs2_write_list_classic.c
index f51bf79..5adae31 100644
--- a/src/mpi/romio/adio/ad_pvfs2/ad_pvfs2_write_list_classic.c
+++ b/src/mpi/romio/adio/ad_pvfs2/ad_pvfs2_write_list_classic.c
@@ -109,9 +109,7 @@ void ADIOI_PVFS2_OldWriteStrided(ADIO_File fd, const void *buf, int count,
        int64_t file_offset;
 	int32_t file_length;
 
-	ADIOI_Flatten_datatype(datatype);
-	flat_buf = ADIOI_Flatlist;
-	while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(datatype);
 	
 	if (file_ptr_type == ADIO_EXPLICIT_OFFSET) {
 	    off = fd->disp + etype_size * offset;
@@ -515,9 +513,7 @@ void ADIOI_PVFS2_OldWriteStrided(ADIO_File fd, const void *buf, int count,
     else {
         /* noncontiguous in memory as well as in file */
 
-        ADIOI_Flatten_datatype(datatype);
-	flat_buf = ADIOI_Flatlist;
-	while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(datatype);
 
 	size_wrote = 0;
 	n_filetypes = st_n_filetypes;
diff --git a/src/mpi/romio/adio/ad_zoidfs/ad_zoidfs_read_list.c b/src/mpi/romio/adio/ad_zoidfs/ad_zoidfs_read_list.c
index d48a06c..3541072 100644
--- a/src/mpi/romio/adio/ad_zoidfs/ad_zoidfs_read_list.c
+++ b/src/mpi/romio/adio/ad_zoidfs/ad_zoidfs_read_list.c
@@ -95,9 +95,7 @@ void ADIOI_ZOIDFS_ReadStrided(ADIO_File fd, void *buf, int count,
         uint64_t file_offsets;
 	uint64_t file_lengths;
 
-	ADIOI_Flatten_datatype(datatype);
-	flat_buf = ADIOI_Flatlist;
-	while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(datatype);
 
 	off = (file_ptr_type == ADIO_INDIVIDUAL) ? fd->fp_ind : 
 	    fd->disp + etype_size * offset;
@@ -410,9 +408,7 @@ void ADIOI_ZOIDFS_ReadStrided(ADIO_File fd, void *buf, int count,
     else {
 /* noncontiguous in memory as well as in file */
       
-        ADIOI_Flatten_datatype(datatype);
-	flat_buf = ADIOI_Flatlist;
-	while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(datatype);
 
 	size_read = 0;
 	n_filetypes = st_n_filetypes;
diff --git a/src/mpi/romio/adio/ad_zoidfs/ad_zoidfs_write_list.c b/src/mpi/romio/adio/ad_zoidfs/ad_zoidfs_write_list.c
index 8ca0594..040d92a 100644
--- a/src/mpi/romio/adio/ad_zoidfs/ad_zoidfs_write_list.c
+++ b/src/mpi/romio/adio/ad_zoidfs/ad_zoidfs_write_list.c
@@ -109,9 +109,7 @@ void ADIOI_ZOIDFS_WriteStrided(ADIO_File fd, void *buf, int count,
         uint64_t file_offsets;
 	uint64_t file_lengths;
 
-	ADIOI_Flatten_datatype(datatype);
-	flat_buf = ADIOI_Flatlist;
-	while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(datatype);
 	
 	if (file_ptr_type == ADIO_EXPLICIT_OFFSET) {
 	    off = fd->disp + etype_size * offset;
@@ -441,9 +439,7 @@ void ADIOI_ZOIDFS_WriteStrided(ADIO_File fd, void *buf, int count,
     else {
         /* noncontiguous in memory as well as in file */
 
-        ADIOI_Flatten_datatype(datatype);
-	flat_buf = ADIOI_Flatlist;
-	while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(datatype);
 
 	size_wrote = 0;
 	n_filetypes = st_n_filetypes;
diff --git a/src/mpi/romio/adio/common/ad_coll_exch_new.c b/src/mpi/romio/adio/common/ad_coll_exch_new.c
index d121589..cbc6454 100644
--- a/src/mpi/romio/adio/common/ad_coll_exch_new.c
+++ b/src/mpi/romio/adio/common/ad_coll_exch_new.c
@@ -150,10 +150,7 @@ void ADIOI_Exch_file_views(int myrank, int nprocs, int file_ptr_type,
 	flat_mem_p->blocklens[0] = memtype_sz*count;
     }
     else {
-	ADIOI_Flatten_datatype(datatype);
-        flat_mem_p = ADIOI_Flatlist;
-        while (flat_mem_p->type != datatype)
-            flat_mem_p = flat_mem_p->next;
+	flat_mem_p = ADIOI_Flatten_and_find(datatype);
     }
 
     MPI_Type_extent(fd->filetype, &filetype_extent);
diff --git a/src/mpi/romio/adio/common/ad_iread_coll.c b/src/mpi/romio/adio/common/ad_iread_coll.c
index 605d0db..1cd8ed9 100644
--- a/src/mpi/romio/adio/common/ad_iread_coll.c
+++ b/src/mpi/romio/adio/common/ad_iread_coll.c
@@ -589,7 +589,6 @@ static void ADIOI_Iread_and_exch(ADIOI_NBC_Request *nbc_req, int *error_code)
 
     int i, j;
     ADIO_Offset st_loc = -1, end_loc = -1;
-    ADIOI_Flatlist_node *flat_buf = NULL;
     int coll_bufsize;
 
     *error_code = MPI_SUCCESS;  /* changed below if error */
@@ -671,10 +670,7 @@ static void ADIOI_Iread_and_exch(ADIOI_NBC_Request *nbc_req, int *error_code)
 
     ADIOI_Datatype_iscontig(datatype, &vars->buftype_is_contig);
     if (!vars->buftype_is_contig) {
-        ADIOI_Flatten_datatype(datatype);
-        flat_buf = ADIOI_Flatlist;
-        while (flat_buf->type != datatype) flat_buf = flat_buf->next;
-        vars->flat_buf = flat_buf;
+	vars->flat_buf = ADIOI_Flatten_and_find(datatype);
     }
     MPI_Type_extent(datatype, &vars->buftype_extent);
 
diff --git a/src/mpi/romio/adio/common/ad_iwrite_coll.c b/src/mpi/romio/adio/common/ad_iwrite_coll.c
index 11b26c0..c5ac8b4 100644
--- a/src/mpi/romio/adio/common/ad_iwrite_coll.c
+++ b/src/mpi/romio/adio/common/ad_iwrite_coll.c
@@ -636,7 +636,6 @@ static void ADIOI_Iexch_and_write(ADIOI_NBC_Request *nbc_req, int *error_code)
 
     int i, j;
     ADIO_Offset st_loc = -1, end_loc = -1;
-    ADIOI_Flatlist_node *flat_buf = NULL;
     int info_flag, coll_bufsize;
     char *value;
 
@@ -719,10 +718,7 @@ static void ADIOI_Iexch_and_write(ADIOI_NBC_Request *nbc_req, int *error_code)
 
     ADIOI_Datatype_iscontig(datatype, &vars->buftype_is_contig);
     if (!vars->buftype_is_contig) {
-        ADIOI_Flatten_datatype(datatype);
-        flat_buf = ADIOI_Flatlist;
-        while (flat_buf->type != datatype) flat_buf = flat_buf->next;
-        vars->flat_buf = flat_buf;
+	vars->flat_buf = ADIOI_Flatten_and_find(datatype);
     }
     MPI_Type_extent(datatype, &vars->buftype_extent);
 
diff --git a/src/mpi/romio/adio/common/ad_read_coll.c b/src/mpi/romio/adio/common/ad_read_coll.c
index 5aa38e4..4cd481b 100644
--- a/src/mpi/romio/adio/common/ad_read_coll.c
+++ b/src/mpi/romio/adio/common/ad_read_coll.c
@@ -601,9 +601,7 @@ static void ADIOI_Read_and_exch(ADIO_File fd, void *buf, MPI_Datatype
 
     ADIOI_Datatype_iscontig(datatype, &buftype_is_contig);
     if (!buftype_is_contig) {
-	ADIOI_Flatten_datatype(datatype);
-	flat_buf = ADIOI_Flatlist;
-        while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(datatype);
     }
     MPI_Type_extent(datatype, &buftype_extent);
 
diff --git a/src/mpi/romio/adio/common/ad_read_str.c b/src/mpi/romio/adio/common/ad_read_str.c
index bec361b..9b22a44 100644
--- a/src/mpi/romio/adio/common/ad_read_str.c
+++ b/src/mpi/romio/adio/common/ad_read_str.c
@@ -115,9 +115,7 @@ void ADIOI_GEN_ReadStrided(ADIO_File fd, void *buf, int count,
 
 /* noncontiguous in memory, contiguous in file. */
 
-	ADIOI_Flatten_datatype(datatype);
-	flat_buf = ADIOI_Flatlist;
-	while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(datatype);
 
         off = (file_ptr_type == ADIO_INDIVIDUAL) ? fd->fp_ind : 
                  fd->disp + (ADIO_Offset)etype_size * offset;
@@ -321,9 +319,7 @@ void ADIOI_GEN_ReadStrided(ADIO_File fd, void *buf, int count,
 	else {
 /* noncontiguous in memory as well as in file */
 
-	    ADIOI_Flatten_datatype(datatype);
-	    flat_buf = ADIOI_Flatlist;
-	    while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	    flat_buf = ADIOI_Flatten_and_find(datatype);
 
 	    k = num = buf_count = 0;
 	    i_offset = flat_buf->indices[0];
diff --git a/src/mpi/romio/adio/common/ad_read_str_naive.c b/src/mpi/romio/adio/common/ad_read_str_naive.c
index 93dc0ea..44abee7 100644
--- a/src/mpi/romio/adio/common/ad_read_str_naive.c
+++ b/src/mpi/romio/adio/common/ad_read_str_naive.c
@@ -57,9 +57,7 @@ void ADIOI_GEN_ReadStrided_naive(ADIO_File fd, void *buf, int count,
     	int b_count;
 	/* noncontiguous in memory, contiguous in file. */
 
-	ADIOI_Flatten_datatype(buftype);
-	flat_buf = ADIOI_Flatlist;
-	while (flat_buf->type != buftype) flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(buftype);
 
         off = (file_ptr_type == ADIO_INDIVIDUAL) ? fd->fp_ind : 
               fd->disp + etype_size * offset;
@@ -289,9 +287,7 @@ void ADIOI_GEN_ReadStrided_naive(ADIO_File fd, void *buf, int count,
 	    ADIO_Offset i_offset, tmp_bufsize = 0;
 	    /* noncontiguous in memory as well as in file */
 
-	    ADIOI_Flatten_datatype(buftype);
-	    flat_buf = ADIOI_Flatlist;
-	    while (flat_buf->type != buftype) flat_buf = flat_buf->next;
+	    flat_buf = ADIOI_Flatten_and_find(buftype);
 
 	    b_index = buf_count = 0;
 	    i_offset = flat_buf->indices[0];
diff --git a/src/mpi/romio/adio/common/ad_write_coll.c b/src/mpi/romio/adio/common/ad_write_coll.c
index 3207085..ce4d620 100644
--- a/src/mpi/romio/adio/common/ad_write_coll.c
+++ b/src/mpi/romio/adio/common/ad_write_coll.c
@@ -402,9 +402,7 @@ static void ADIOI_Exch_and_write(ADIO_File fd, void *buf, MPI_Datatype
 
     ADIOI_Datatype_iscontig(datatype, &buftype_is_contig);
     if (!buftype_is_contig) {
-	ADIOI_Flatten_datatype(datatype);
-	flat_buf = ADIOI_Flatlist;
-        while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(datatype);
     }
     MPI_Type_extent(datatype, &buftype_extent);
 
diff --git a/src/mpi/romio/adio/common/ad_write_nolock.c b/src/mpi/romio/adio/common/ad_write_nolock.c
index f22ba7f..e26474c 100644
--- a/src/mpi/romio/adio/common/ad_write_nolock.c
+++ b/src/mpi/romio/adio/common/ad_write_nolock.c
@@ -84,9 +84,7 @@ void ADIOI_NOLOCK_WriteStrided(ADIO_File fd, const void *buf, int count,
 	ADIO_Offset combine_buf_remain;
 /* noncontiguous in memory, contiguous in file. use writev */
 
-	ADIOI_Flatten_datatype(datatype);
-	flat_buf = ADIOI_Flatlist;
-	while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(datatype);
 
 	/* allocate our "combine buffer" to pack data into before writing */
 	combine_buf = (char *) ADIOI_Malloc(fd->hints->ind_wr_buffer_size);
@@ -311,9 +309,7 @@ void ADIOI_NOLOCK_WriteStrided(ADIO_File fd, const void *buf, int count,
 	else {
 /* noncontiguous in memory as well as in file */
 
-	    ADIOI_Flatten_datatype(datatype);
-	    flat_buf = ADIOI_Flatlist;
-	    while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	    flat_buf = ADIOI_Flatten_and_find(datatype);
 
 	    k = num = buf_count = 0;
 	    indx = flat_buf->indices[0];
diff --git a/src/mpi/romio/adio/common/ad_write_str.c b/src/mpi/romio/adio/common/ad_write_str.c
index f3b6c89..6c62a7c 100644
--- a/src/mpi/romio/adio/common/ad_write_str.c
+++ b/src/mpi/romio/adio/common/ad_write_str.c
@@ -180,9 +180,7 @@ void ADIOI_GEN_WriteStrided(ADIO_File fd, const void *buf, int count,
 
 /* noncontiguous in memory, contiguous in file. */
 
-	ADIOI_Flatten_datatype(datatype);
-	flat_buf = ADIOI_Flatlist;
-	while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(datatype);
 
         off = (file_ptr_type == ADIO_INDIVIDUAL) ? fd->fp_ind : 
                  fd->disp + (ADIO_Offset)etype_size * offset;
@@ -395,9 +393,7 @@ void ADIOI_GEN_WriteStrided(ADIO_File fd, const void *buf, int count,
 	else {
 /* noncontiguous in memory as well as in file */
 
-	    ADIOI_Flatten_datatype(datatype);
-	    flat_buf = ADIOI_Flatlist;
-	    while (flat_buf->type != datatype) flat_buf = flat_buf->next;
+	    flat_buf = ADIOI_Flatten_and_find(datatype);
 
 	    k = num = buf_count = 0;
 	    i_offset = flat_buf->indices[0];
diff --git a/src/mpi/romio/adio/common/ad_write_str_naive.c b/src/mpi/romio/adio/common/ad_write_str_naive.c
index 935753d..f004cd8 100644
--- a/src/mpi/romio/adio/common/ad_write_str_naive.c
+++ b/src/mpi/romio/adio/common/ad_write_str_naive.c
@@ -58,9 +58,7 @@ void ADIOI_GEN_WriteStrided_naive(ADIO_File fd, const void *buf, int count,
     	int b_count;
 	/* noncontiguous in memory, contiguous in file. */
 
-	ADIOI_Flatten_datatype(buftype);
-	flat_buf = ADIOI_Flatlist;
-	while (flat_buf->type != buftype) flat_buf = flat_buf->next;
+	flat_buf = ADIOI_Flatten_and_find(buftype);
 
         off = (file_ptr_type == ADIO_INDIVIDUAL) ? fd->fp_ind : 
               fd->disp + (ADIO_Offset)etype_size * offset;
@@ -289,9 +287,7 @@ void ADIOI_GEN_WriteStrided_naive(ADIO_File fd, const void *buf, int count,
 	    ADIO_Offset i_offset, tmp_bufsize = 0;
 	    /* noncontiguous in memory as well as in file */
 
-	    ADIOI_Flatten_datatype(buftype);
-	    flat_buf = ADIOI_Flatlist;
-	    while (flat_buf->type != buftype) flat_buf = flat_buf->next;
+	    flat_buf = ADIOI_Flatten_and_find(buftype);
 
 	    b_index = buf_count = 0;
 	    i_offset = flat_buf->indices[0];
diff --git a/src/mpi/romio/adio/common/flatten.c b/src/mpi/romio/adio/common/flatten.c
index 1a2bf1a..db13a7b 100644
--- a/src/mpi/romio/adio/common/flatten.c
+++ b/src/mpi/romio/adio/common/flatten.c
@@ -1195,3 +1195,12 @@ void ADIOI_Delete_flattened(MPI_Datatype datatype)
 	ADIOI_Free(flat);
     }
 }
+
+ADIOI_Flatlist_node * ADIOI_Flatten_and_find(MPI_Datatype datatype)
+{
+    ADIOI_Flatlist_node *node;
+    ADIOI_Flatten_datatype(datatype);
+    node = ADIOI_Flatlist;
+    while (node->type != datatype) node = node->next;
+    return node;
+}
diff --git a/src/mpi/romio/adio/common/onesided_aggregation.c b/src/mpi/romio/adio/common/onesided_aggregation.c
index 84d8333..f4ae0de 100644
--- a/src/mpi/romio/adio/common/onesided_aggregation.c
+++ b/src/mpi/romio/adio/common/onesided_aggregation.c
@@ -109,9 +109,7 @@ void ADIOI_OneSidedWriteAggregation(ADIO_File fd,
     if (!bufTypeIsContig) {
     /* Flatten the non-contiguous source datatype.
      */
-      ADIOI_Flatten_datatype(datatype);
-      flatBuf = ADIOI_Flatlist;
-      while (flatBuf->type != datatype) flatBuf = flatBuf->next;
+      flatBuf = ADIOI_Flatten_and_find(datatype);
       MPI_Type_extent(datatype, &bufTypeExtent);
 #ifdef onesidedtrace
       printf("flatBuf->count is %d bufTypeExtent is %d\n", flatBuf->count,bufTypeExtent);
@@ -1126,9 +1124,7 @@ void ADIOI_OneSidedReadAggregation(ADIO_File fd,
     if (!bufTypeIsContig) {
     /* Flatten the non-contiguous source datatype.
      */
-      ADIOI_Flatten_datatype(datatype);
-      flatBuf = ADIOI_Flatlist;
-      while (flatBuf->type != datatype) flatBuf = flatBuf->next;
+      flatBuf = ADIOI_Flatten_and_find(datatype);
       MPI_Type_extent(datatype, &bufTypeExtent);
     }
 #ifdef onesidedtrace
diff --git a/src/mpi/romio/adio/include/adioi.h b/src/mpi/romio/adio/include/adioi.h
index dc045c3..4ac7d81 100644
--- a/src/mpi/romio/adio/include/adioi.h
+++ b/src/mpi/romio/adio/include/adioi.h
@@ -351,6 +351,7 @@ void ADIOI_Flatten_datatype(MPI_Datatype type);
 void ADIOI_Flatten(MPI_Datatype type, ADIOI_Flatlist_node *flat,
 		  ADIO_Offset st_offset, MPI_Count *curr_index);
 void ADIOI_Delete_flattened(MPI_Datatype datatype);
+ADIOI_Flatlist_node * ADIOI_Flatten_and_find(MPI_Datatype);
 MPI_Count ADIOI_Count_contiguous_blocks(MPI_Datatype type, MPI_Count *curr_index);
 void ADIOI_Complete_async(int *error_code);
 void *ADIOI_Malloc_fn(size_t size, int lineno, const char *fname);

http://git.mpich.org/mpich.git/commitdiff/78413c55c4820a50cd31f0df6ec009891ff42917

commit 78413c55c4820a50cd31f0df6ec009891ff42917
Author: Pavan Balaji <balaji at anl.gov>
Date:   Tue Aug 18 13:16:17 2015 -0500

    Initial draft of ROMIO managed thread locks.
    
    ROMIO was implicitly sharing MPICH locks, which is incorrect.
    
    Signed-off-by: Rob Latham <robl at mcs.anl.gov>

diff --git a/src/glue/romio/glue_romio.c b/src/glue/romio/glue_romio.c
index fa327ab..f78afc3 100644
--- a/src/glue/romio/glue_romio.c
+++ b/src/glue/romio/glue_romio.c
@@ -35,27 +35,50 @@ int MPIR_Ext_assert_fail(const char *cond, const char *file_name, int line_num)
     return MPIR_Assert_fail(cond, file_name, line_num);
 }
 
+void MPIR_Ext_thread_mutex_create(void **mutex_p_p)
+{
+    int err;
+    MPID_Thread_mutex_t *m;
+
+    m = (MPID_Thread_mutex_t *) MPIU_Malloc(sizeof(MPID_Thread_mutex_t));
+    MPID_Thread_mutex_create(m, &err);
+    MPIU_Assert(err == 0);
+
+    *mutex_p_p = (void *) m;
+}
+
+void MPIR_Ext_thread_mutex_destroy(void *mutex_p)
+{
+    int err;
+    MPID_Thread_mutex_t *m = (MPID_Thread_mutex_t *) mutex_p;
+
+    MPID_Thread_mutex_destroy(m, &err);
+    MPIU_Assert(err == 0);
+
+    MPIU_Free(mutex_p);
+}
+
 /* These two routines export the GLOBAL CS_ENTER/EXIT macros as functions so
  * that ROMIO can use them.  These routines only support the GLOBAL granularity
  * of MPICH threading; other accommodations must be made for finer-grained
  * threading strategies. */
-void MPIR_Ext_cs_enter(void)
+void MPIR_Ext_cs_enter(void *mutex_p)
 {
-    MPID_THREAD_CS_ENTER(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
+    MPID_THREAD_CS_ENTER(GLOBAL, *((MPID_Thread_mutex_t *) mutex_p));
 }
 
-void MPIR_Ext_cs_exit(void)
+void MPIR_Ext_cs_exit(void *mutex_p)
 {
-    MPID_THREAD_CS_EXIT(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
+    MPID_THREAD_CS_EXIT(GLOBAL, *((MPID_Thread_mutex_t *) mutex_p));
 }
 
 /* This routine is for a thread to yield control when the thread is waiting for
  * the completion of communication inside a ROMIO routine but the progress
  * engine is blocked by another thread. */
-void MPIR_Ext_cs_yield(void)
+void MPIR_Ext_cs_yield(void *mutex_p)
 {
     /* TODO: check whether the progress engine is blocked */
-    MPID_THREAD_CS_YIELD(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
+    MPID_THREAD_CS_YIELD(GLOBAL, *((MPID_Thread_mutex_t *) mutex_p));
 }
 
 /* will consider MPI_DATATYPE_NULL to be an error */
diff --git a/src/include/glue_romio.h.in b/src/include/glue_romio.h.in
index 9623833..72ce3ac 100644
--- a/src/include/glue_romio.h.in
+++ b/src/include/glue_romio.h.in
@@ -51,9 +51,11 @@ extern int MPIR_Ext_dbg_romio_verbose_enabled;
  * glue code that cannot be initialized statically */
 int MPIR_Ext_init(void);
 
-void MPIR_Ext_cs_enter(void);
-void MPIR_Ext_cs_exit(void);
-void MPIR_Ext_cs_yield(void);
+void MPIR_Ext_thread_mutex_create(void **mutex_p_p);
+void MPIR_Ext_thread_mutex_destroy(void *mutex_p);
+void MPIR_Ext_cs_enter(void *mutex_p);
+void MPIR_Ext_cs_exit(void *mutex_p);
+void MPIR_Ext_cs_yield(void *mutex_p);
 
 /* to facilitate error checking */
 int MPIR_Ext_datatype_iscommitted(MPI_Datatype datatype);
diff --git a/src/mpi/romio/adio/common/ad_end.c b/src/mpi/romio/adio/common/ad_end.c
index ea4dfeb..76712ae 100644
--- a/src/mpi/romio/adio/common/ad_end.c
+++ b/src/mpi/romio/adio/common/ad_end.c
@@ -76,5 +76,8 @@ int ADIOI_End_call(MPI_Comm comm, int keyval, void *attribute_val, void
         MPI_Keyval_free(&ADIOI_cb_config_list_keyval);
 
     ADIO_End(&error_code);
+
+    MPIR_Ext_thread_mutex_destroy((void *) ADIO_THREAD_MUTEX);
+
     return error_code;
 }
diff --git a/src/mpi/romio/adio/common/ad_iread_coll.c b/src/mpi/romio/adio/common/ad_iread_coll.c
index b1c05d8..605d0db 100644
--- a/src/mpi/romio/adio/common/ad_iread_coll.c
+++ b/src/mpi/romio/adio/common/ad_iread_coll.c
@@ -1333,10 +1333,6 @@ static int ADIOI_GEN_irc_wait_fn(int count, void **array_of_states,
 
             if ((timeout > 0) && (timeout < (MPI_Wtime() - starttime)))
                 goto fn_exit;
-
-            /* If the progress engine is blocked, we have to yield for another
-               thread to be able to unblock the progress engine. */
-            ROMIO_THREAD_CS_YIELD();
         }
     }
 
diff --git a/src/mpi/romio/adio/common/ad_iwrite_coll.c b/src/mpi/romio/adio/common/ad_iwrite_coll.c
index 47c73ba..11b26c0 100644
--- a/src/mpi/romio/adio/common/ad_iwrite_coll.c
+++ b/src/mpi/romio/adio/common/ad_iwrite_coll.c
@@ -1558,10 +1558,6 @@ static int ADIOI_GEN_iwc_wait_fn(int count, void **array_of_states,
 
             if ((timeout > 0) && (timeout < (MPI_Wtime() - starttime)))
                 goto fn_exit;
-
-            /* If the progress engine is blocked, we have to yield for another
-               thread to be able to unblock the progress engine. */
-            ROMIO_THREAD_CS_YIELD();
         }
     }
 
diff --git a/src/mpi/romio/adio/include/adioi.h b/src/mpi/romio/adio/include/adioi.h
index 96a63f9..dc045c3 100644
--- a/src/mpi/romio/adio/include/adioi.h
+++ b/src/mpi/romio/adio/include/adioi.h
@@ -1084,4 +1084,6 @@ ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
 
 #endif
 
+extern void *ADIO_THREAD_MUTEX;
+
 #endif  /* ADIOI_INCLUDE */
diff --git a/src/mpi/romio/mpi-io/close.c b/src/mpi/romio/mpi-io/close.c
index 3f2b0b1..57b2019 100644
--- a/src/mpi/romio/mpi-io/close.c
+++ b/src/mpi/romio/mpi-io/close.c
@@ -44,8 +44,6 @@ int MPI_File_close(MPI_File *fh)
     HPMP_IO_WSTART(fl_xmpi, BLKMPIFILECLOSE, TRDTBLOCK, *adio_fh);
 #endif /* MPI_hpux */
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(*fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -90,7 +88,6 @@ int MPI_File_close(MPI_File *fh)
 #endif /* MPI_hpux */
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
     return error_code;
 fn_fail:
     /* --BEGIN ERROR HANDLING-- */
diff --git a/src/mpi/romio/mpi-io/delete.c b/src/mpi/romio/mpi-io/delete.c
index 47b52a0..d9a3e0f 100644
--- a/src/mpi/romio/mpi-io/delete.c
+++ b/src/mpi/romio/mpi-io/delete.c
@@ -48,8 +48,6 @@ int MPI_File_delete(ROMIO_CONST char *filename, MPI_Info info)
 
     MPIU_UNREFERENCED_ARG(info);
 
-    ROMIO_THREAD_CS_ENTER();
-
     MPIR_MPIOInit(&error_code);
     if (error_code != MPI_SUCCESS) goto fn_exit;
 
@@ -90,6 +88,5 @@ int MPI_File_delete(ROMIO_CONST char *filename, MPI_Info info)
 #endif /* MPI_hpux */
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
     return error_code;
 }
diff --git a/src/mpi/romio/mpi-io/fsync.c b/src/mpi/romio/mpi-io/fsync.c
index 7b2ef12..03a2138 100644
--- a/src/mpi/romio/mpi-io/fsync.c
+++ b/src/mpi/romio/mpi-io/fsync.c
@@ -45,7 +45,6 @@ int MPI_File_sync(MPI_File fh)
     HPMP_IO_START(fl_xmpi, BLKMPIFILESYNC, TRDTBLOCK, adio_fh,
 		  MPI_DATATYPE_NULL, -1);
 #endif /* MPI_hpux */
-    ROMIO_THREAD_CS_ENTER();
 
     adio_fh = MPIO_File_resolve(fh);
     /* --BEGIN ERROR HANDLING-- */
@@ -71,6 +70,5 @@ int MPI_File_sync(MPI_File fh)
 #endif /* MPI_hpux */
  
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
     return error_code;
 }
diff --git a/src/mpi/romio/mpi-io/get_errh.c b/src/mpi/romio/mpi-io/get_errh.c
index 985dcb5..0f46ab5 100644
--- a/src/mpi/romio/mpi-io/get_errh.c
+++ b/src/mpi/romio/mpi-io/get_errh.c
@@ -44,8 +44,6 @@ int MPI_File_get_errhandler(MPI_File mpi_fh, MPI_Errhandler *errhandler)
     static char myname[] = "MPI_FILE_GET_ERRHANDLER";
     MPIU_THREADPRIV_DECL;
 
-    ROMIO_THREAD_CS_ENTER();
-
     if (mpi_fh == MPI_FILE_NULL) {
 	*errhandler = ADIOI_DFLT_ERR_HANDLER;
     }
@@ -66,6 +64,5 @@ int MPI_File_get_errhandler(MPI_File mpi_fh, MPI_Errhandler *errhandler)
     }
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
     return MPI_SUCCESS;
 }
diff --git a/src/mpi/romio/mpi-io/get_group.c b/src/mpi/romio/mpi-io/get_group.c
index 2b3077c..75475c3 100644
--- a/src/mpi/romio/mpi-io/get_group.c
+++ b/src/mpi/romio/mpi-io/get_group.c
@@ -43,8 +43,6 @@ int MPI_File_get_group(MPI_File fh, MPI_Group *group)
     ADIO_File adio_fh;
     static char myname[] = "MPI_FILE_GET_GROUP";
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -59,6 +57,5 @@ int MPI_File_get_group(MPI_File fh, MPI_Group *group)
     error_code = MPI_Comm_group(adio_fh->comm, group);
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
     return error_code;
 }
diff --git a/src/mpi/romio/mpi-io/get_info.c b/src/mpi/romio/mpi-io/get_info.c
index e923e2b..c3df84f 100644
--- a/src/mpi/romio/mpi-io/get_info.c
+++ b/src/mpi/romio/mpi-io/get_info.c
@@ -42,8 +42,6 @@ int MPI_File_get_info(MPI_File fh, MPI_Info *info_used)
     ADIO_File adio_fh;
     static char myname[] = "MPI_FILE_GET_INFO";
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -57,6 +55,5 @@ int MPI_File_get_info(MPI_File fh, MPI_Info *info_used)
     /* --END ERROR HANDLING-- */
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
     return  error_code;
 }
diff --git a/src/mpi/romio/mpi-io/get_view.c b/src/mpi/romio/mpi-io/get_view.c
index 46b0926..38ed63c 100644
--- a/src/mpi/romio/mpi-io/get_view.c
+++ b/src/mpi/romio/mpi-io/get_view.c
@@ -52,8 +52,6 @@ int MPI_File_get_view(MPI_File fh, MPI_Offset *disp, MPI_Datatype *etype,
     int i, j, k, combiner;
     MPI_Datatype copy_etype, copy_filetype;
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -96,7 +94,5 @@ int MPI_File_get_view(MPI_File fh, MPI_Offset *disp, MPI_Datatype *etype,
     }
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
-
     return MPI_SUCCESS;
 }
diff --git a/src/mpi/romio/mpi-io/ioreq_c2f.c b/src/mpi/romio/mpi-io/ioreq_c2f.c
index c21c967..37f129e 100644
--- a/src/mpi/romio/mpi-io/ioreq_c2f.c
+++ b/src/mpi/romio/mpi-io/ioreq_c2f.c
@@ -56,7 +56,6 @@ MPI_Fint MPIO_Request_c2f(MPIO_Request request)
 	    return (MPI_Fint) 0;
     }
 
-    ROMIO_THREAD_CS_ENTER();
     if (!ADIOI_Reqtable) {
 	ADIOI_Reqtable_max = 1024;
 	ADIOI_Reqtable = (MPIO_Request *)
@@ -75,7 +74,6 @@ MPI_Fint MPIO_Request_c2f(MPIO_Request request)
     ADIOI_Reqtable_ptr++;
     ADIOI_Reqtable[ADIOI_Reqtable_ptr] = request;
 
-    ROMIO_THREAD_CS_EXIT();
     return (MPI_Fint) ADIOI_Reqtable_ptr;
 #endif
 }
diff --git a/src/mpi/romio/mpi-io/ioreq_f2c.c b/src/mpi/romio/mpi-io/ioreq_f2c.c
index 4d3e509..1a4b628 100644
--- a/src/mpi/romio/mpi-io/ioreq_f2c.c
+++ b/src/mpi/romio/mpi-io/ioreq_f2c.c
@@ -49,8 +49,6 @@ MPIO_Request MPIO_Request_f2c(MPI_Fint request)
     return (MPIO_Request) request;
 #else
 
-    ROMIO_THREAD_CS_ENTER();
-    
     if (!request) {
 	return MPIO_REQUEST_NULL;
     }
@@ -65,7 +63,6 @@ MPIO_Request MPIO_Request_f2c(MPI_Fint request)
     /* --END ERROR HANDLING-- */
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
     return ADIOI_Reqtable[request];
 #endif
 }
diff --git a/src/mpi/romio/mpi-io/iotest.c b/src/mpi/romio/mpi-io/iotest.c
index f019626..708638a 100644
--- a/src/mpi/romio/mpi-io/iotest.c
+++ b/src/mpi/romio/mpi-io/iotest.c
@@ -56,8 +56,6 @@ int MPIO_Test(MPIO_Request *request, int *flag, MPI_Status *status)
     }
 #endif /* MPI_hpux */
 
-    ROMIO_THREAD_CS_ENTER();
-
     if (*request == MPIO_REQUEST_NULL) {
 	    error_code = MPI_SUCCESS;
 	    goto fn_exit;
@@ -89,7 +87,6 @@ int MPIO_Test(MPIO_Request *request, int *flag, MPI_Status *status)
 #endif /* MPI_hpux */
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
     return error_code;
 }
 #endif
diff --git a/src/mpi/romio/mpi-io/iotestall.c b/src/mpi/romio/mpi-io/iotestall.c
index 21ff93d..a5bacb2 100644
--- a/src/mpi/romio/mpi-io/iotestall.c
+++ b/src/mpi/romio/mpi-io/iotestall.c
@@ -34,7 +34,6 @@ int MPIO_Testall(int count, MPIO_Request requests[], int *flag,
     int done, i, err; 
     MPIU_THREADPRIV_DECL;
 
-    ROMIO_THREAD_CS_ENTER();
     if (count == 1)  {
 	    err = MPIO_Test( requests, flag, statuses );
 	    goto fn_exit;
@@ -71,7 +70,6 @@ int MPIO_Testall(int count, MPIO_Request requests[], int *flag,
 
     err = MPI_SUCCESS;
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
     return err;
 }
 
diff --git a/src/mpi/romio/mpi-io/iotestany.c b/src/mpi/romio/mpi-io/iotestany.c
index 3f9d7af..3586a7b 100644
--- a/src/mpi/romio/mpi-io/iotestany.c
+++ b/src/mpi/romio/mpi-io/iotestany.c
@@ -34,8 +34,6 @@ int MPIO_Testany(int count, MPIO_Request requests[], int *index,
     int i, err; 
     MPIU_THREADPRIV_DECL;
 
-    ROMIO_THREAD_CS_ENTER();
-
     if (count == 1) {
 	err = MPIO_Test( requests, flag, status );
 	if (!err) *index = 0;
@@ -76,6 +74,5 @@ int MPIO_Testany(int count, MPIO_Request requests[], int *index,
 
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
     return err;
 }
diff --git a/src/mpi/romio/mpi-io/iotestsome.c b/src/mpi/romio/mpi-io/iotestsome.c
index 4cc603c..4288d1b 100644
--- a/src/mpi/romio/mpi-io/iotestsome.c
+++ b/src/mpi/romio/mpi-io/iotestsome.c
@@ -35,8 +35,6 @@ int MPIO_Testsome(int count, MPIO_Request requests[], int *outcount,
     int flag;
     MPIU_THREADPRIV_DECL;
 
-    ROMIO_THREAD_CS_ENTER();
-
     if (count == 1) {
 	err = MPIO_Test( requests, &flag, statuses );
 	if (!err) {
@@ -80,7 +78,5 @@ int MPIO_Testsome(int count, MPIO_Request requests[], int *outcount,
     }
 
 fn_exit:
-
-    ROMIO_THREAD_CS_EXIT();
     return err;
 }
diff --git a/src/mpi/romio/mpi-io/iowait.c b/src/mpi/romio/mpi-io/iowait.c
index 40801c5..4c2ad20 100644
--- a/src/mpi/romio/mpi-io/iowait.c
+++ b/src/mpi/romio/mpi-io/iowait.c
@@ -56,8 +56,6 @@ int MPIO_Wait(MPIO_Request *request, MPI_Status *status)
     }
 #endif /* MPI_hpux */
 
-    ROMIO_THREAD_CS_ENTER();
-
     if (*request == MPIO_REQUEST_NULL) {
 	    error_code = MPI_SUCCESS;
 	    goto fn_exit;
@@ -90,7 +88,6 @@ int MPIO_Wait(MPIO_Request *request, MPI_Status *status)
 #endif /* MPI_hpux */
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
     return error_code;
 }
 #endif
diff --git a/src/mpi/romio/mpi-io/iowaitall.c b/src/mpi/romio/mpi-io/iowaitall.c
index e51768c..aeb10ed 100644
--- a/src/mpi/romio/mpi-io/iowaitall.c
+++ b/src/mpi/romio/mpi-io/iowaitall.c
@@ -33,8 +33,6 @@ int MPIO_Waitall( int count, MPIO_Request requests[], MPI_Status statuses[] )
     int notdone, i, flag, err; 
     MPIU_THREADPRIV_DECL;
 
-    ROMIO_THREAD_CS_ENTER();
-
     if (count == 1)  {
 	    err = MPIO_Wait(requests, statuses);
 	    goto fn_exit;
@@ -67,8 +65,6 @@ int MPIO_Waitall( int count, MPIO_Request requests[], MPI_Status statuses[] )
 
     err = MPI_SUCCESS;
 fn_exit:
-
-    ROMIO_THREAD_CS_EXIT();
     return err;
 }
 
diff --git a/src/mpi/romio/mpi-io/iowaitany.c b/src/mpi/romio/mpi-io/iowaitany.c
index fa80f96..402266b 100644
--- a/src/mpi/romio/mpi-io/iowaitany.c
+++ b/src/mpi/romio/mpi-io/iowaitany.c
@@ -34,8 +34,6 @@ int MPIO_Waitany(int count, MPIO_Request requests[], int *index,
     int i, flag, err; 
     MPIU_THREADPRIV_DECL;
 
-    ROMIO_THREAD_CS_ENTER();
-
     if (count == 1) {
 	err = MPIO_Wait( requests, status );
 	if (!err) *index = 0;
@@ -78,7 +76,5 @@ int MPIO_Waitany(int count, MPIO_Request requests[], int *index,
     } while (flag == 0);
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
-
     return err;
 }
diff --git a/src/mpi/romio/mpi-io/iowaitsome.c b/src/mpi/romio/mpi-io/iowaitsome.c
index bfa3976..05fed29 100644
--- a/src/mpi/romio/mpi-io/iowaitsome.c
+++ b/src/mpi/romio/mpi-io/iowaitsome.c
@@ -34,8 +34,6 @@ int MPIO_Waitsome(int count, MPIO_Request requests[], int *outcount,
     int i, flag, err; 
     MPIU_THREADPRIV_DECL;
 
-    ROMIO_THREAD_CS_ENTER();
-
     if (count == 1) {
 	err = MPIO_Wait( requests, statuses );
 	if (!err) {
@@ -76,6 +74,5 @@ int MPIO_Waitsome(int count, MPIO_Request requests[], int *outcount,
     } while (*outcount == 0);
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
     return err;
 }
diff --git a/src/mpi/romio/mpi-io/iread.c b/src/mpi/romio/mpi-io/iread.c
index 4b23a11..0ff2a3e 100644
--- a/src/mpi/romio/mpi-io/iread.c
+++ b/src/mpi/romio/mpi-io/iread.c
@@ -83,8 +83,6 @@ int MPIOI_File_iread(MPI_File fh, MPI_Offset offset, int file_ptr_type, void *bu
     ADIO_Offset off, bufsize;
     MPI_Offset nbytes=0;
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -154,8 +152,6 @@ int MPIOI_File_iread(MPI_File fh, MPI_Offset offset, int file_ptr_type, void *bu
 			   offset, request, &error_code); 
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
-
     return error_code;
 }
 #endif
diff --git a/src/mpi/romio/mpi-io/iread_all.c b/src/mpi/romio/mpi-io/iread_all.c
index afe44f6..f0959f8 100644
--- a/src/mpi/romio/mpi-io/iread_all.c
+++ b/src/mpi/romio/mpi-io/iread_all.c
@@ -89,8 +89,6 @@ int MPIOI_File_iread_all(MPI_File fh,
     ADIO_File adio_fh;
     void *xbuf=NULL, *e32_buf=NULL;
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -142,8 +140,6 @@ int MPIOI_File_iread_all(MPI_File fh,
     }
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
-
     return error_code;
 }
 #endif
diff --git a/src/mpi/romio/mpi-io/iread_sh.c b/src/mpi/romio/mpi-io/iread_sh.c
index bd64313..1fac1bc 100644
--- a/src/mpi/romio/mpi-io/iread_sh.c
+++ b/src/mpi/romio/mpi-io/iread_sh.c
@@ -55,8 +55,6 @@ int MPI_File_iread_shared(MPI_File fh, void *buf, int count,
     ADIO_Offset off, shared_fp;
     MPI_Offset nbytes=0;
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -134,7 +132,6 @@ int MPI_File_iread_shared(MPI_File fh, void *buf, int count,
     /* --END ERROR HANDLING-- */
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
     return error_code;
 }
 #endif
diff --git a/src/mpi/romio/mpi-io/iwrite.c b/src/mpi/romio/mpi-io/iwrite.c
index ae6c6ae..1103b09 100644
--- a/src/mpi/romio/mpi-io/iwrite.c
+++ b/src/mpi/romio/mpi-io/iwrite.c
@@ -90,7 +90,6 @@ int MPIOI_File_iwrite(MPI_File fh,
     ADIO_File adio_fh;
     MPI_Offset nbytes=0;
 
-    ROMIO_THREAD_CS_ENTER();
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -162,7 +161,6 @@ int MPIOI_File_iwrite(MPI_File fh,
 			   offset, request, &error_code);
     }
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
     return error_code;
 }
 #endif
diff --git a/src/mpi/romio/mpi-io/iwrite_all.c b/src/mpi/romio/mpi-io/iwrite_all.c
index 9f486e7..a6de14d 100644
--- a/src/mpi/romio/mpi-io/iwrite_all.c
+++ b/src/mpi/romio/mpi-io/iwrite_all.c
@@ -84,8 +84,6 @@ int MPIOI_File_iwrite_all(MPI_File fh,
     void *e32buf=NULL;
     const void *xbuf=NULL;
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -131,8 +129,6 @@ int MPIOI_File_iwrite_all(MPI_File fh,
 
 fn_exit:
     if (e32buf != NULL) ADIOI_Free(e32buf);
-    ROMIO_THREAD_CS_EXIT();
-
     return error_code;
 }
 #endif
diff --git a/src/mpi/romio/mpi-io/iwrite_sh.c b/src/mpi/romio/mpi-io/iwrite_sh.c
index 3f9612a..67bdfd9 100644
--- a/src/mpi/romio/mpi-io/iwrite_sh.c
+++ b/src/mpi/romio/mpi-io/iwrite_sh.c
@@ -55,8 +55,6 @@ int MPI_File_iwrite_shared(MPI_File fh, ROMIO_CONST void *buf, int count,
     ADIO_Offset off, shared_fp;
     static char myname[] = "MPI_FILE_IWRITE_SHARED";
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -114,7 +112,5 @@ int MPI_File_iwrite_shared(MPI_File fh, ROMIO_CONST void *buf, int count,
 			   shared_fp, request, &error_code); 
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
-
     return error_code;
 }
diff --git a/src/mpi/romio/mpi-io/mpioimpl.h b/src/mpi/romio/mpi-io/mpioimpl.h
index 074ad42..c96ec64 100644
--- a/src/mpi/romio/mpi-io/mpioimpl.h
+++ b/src/mpi/romio/mpi-io/mpioimpl.h
@@ -18,9 +18,9 @@
 #ifdef ROMIO_INSIDE_MPICH
 #include "glue_romio.h"
 
-#define ROMIO_THREAD_CS_ENTER() MPIR_Ext_cs_enter()
-#define ROMIO_THREAD_CS_EXIT() MPIR_Ext_cs_exit()
-#define ROMIO_THREAD_CS_YIELD() MPIR_Ext_cs_yield()
+#define ROMIO_THREAD_CS_ENTER(mutex) MPIR_Ext_cs_enter(mutex)
+#define ROMIO_THREAD_CS_EXIT(mutex) MPIR_Ext_cs_exit(mutex)
+#define ROMIO_THREAD_CS_YIELD(mutex) MPIR_Ext_cs_yield(mutex)
 
 /* committed datatype checking support in ROMIO */
 #define MPIO_DATATYPE_ISCOMMITTED(dtype_, err_)        \
@@ -33,9 +33,9 @@
    error reporting features provided by MPICH must implement these 
    four functions.  Defining these as empty should not change the behavior 
    of correct programs */
-#define ROMIO_THREAD_CS_ENTER()
-#define ROMIO_THREAD_CS_EXIT()
-#define ROMIO_THREAD_CS_YIELD()
+#define ROMIO_THREAD_CS_ENTER(mutex)
+#define ROMIO_THREAD_CS_EXIT(mutex)
+#define ROMIO_THREAD_CS_YIELD(mutex)
 #define MPIO_DATATYPE_ISCOMMITTED(dtype_, err_) do {} while (0)
 #ifdef HAVE_WINDOWS_H
 #define MPIU_UNREFERENCED_ARG(a) a
diff --git a/src/mpi/romio/mpi-io/mpir-mpioinit.c b/src/mpi/romio/mpi-io/mpir-mpioinit.c
index be78b45..a7f9d08 100644
--- a/src/mpi/romio/mpi-io/mpir-mpioinit.c
+++ b/src/mpi/romio/mpi-io/mpir-mpioinit.c
@@ -13,6 +13,7 @@
 #endif
 
 extern int ADIO_Init_keyval;
+void *ADIO_THREAD_MUTEX = NULL;
 
 /* common code to stuff an attribute on a communicator for the purpose of
  * cleaning up in MPI_Finalize() */
@@ -48,6 +49,9 @@ void MPIR_MPIOInit(int * error_code) {
 
 	/* initialize ADIO */
         ADIO_Init( (int *)0, (char ***)0, error_code);
+
+        /* create mutexes */
+        MPIR_Ext_thread_mutex_create((void **) &ADIO_THREAD_MUTEX);
     }
     *error_code = MPI_SUCCESS;
 }
diff --git a/src/mpi/romio/mpi-io/open.c b/src/mpi/romio/mpi-io/open.c
index 7cebb5a..f100022 100644
--- a/src/mpi/romio/mpi-io/open.c
+++ b/src/mpi/romio/mpi-io/open.c
@@ -59,8 +59,6 @@ int MPI_File_open(MPI_Comm comm, ROMIO_CONST char *filename, int amode,
     HPMP_IO_OPEN_START(fl_xmpi, comm);
 #endif /* MPI_hpux */
 
-    ROMIO_THREAD_CS_ENTER();
-
     /* --BEGIN ERROR HANDLING-- */
     MPIO_CHECK_COMM(comm, myname, error_code);
     MPIO_CHECK_INFO_ALL(info, error_code, comm);
@@ -198,7 +196,6 @@ int MPI_File_open(MPI_Comm comm, ROMIO_CONST char *filename, int amode,
 #endif /* MPI_hpux */
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
     return error_code;
 fn_fail:
     /* --BEGIN ERROR HANDLING-- */
diff --git a/src/mpi/romio/mpi-io/prealloc.c b/src/mpi/romio/mpi-io/prealloc.c
index 1542e47..c258295 100644
--- a/src/mpi/romio/mpi-io/prealloc.c
+++ b/src/mpi/romio/mpi-io/prealloc.c
@@ -48,8 +48,6 @@ int MPI_File_preallocate(MPI_File fh, MPI_Offset size)
 		  adio_fh, MPI_DATATYPE_NULL, -1);
 #endif /* MPI_hpux */
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -99,8 +97,6 @@ int MPI_File_preallocate(MPI_File fh, MPI_Offset size)
 
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
-
     /* TODO: bcast result? */
     if (!mynod) return error_code;
     else return MPI_SUCCESS;
diff --git a/src/mpi/romio/mpi-io/read.c b/src/mpi/romio/mpi-io/read.c
index 6f12914..05ed206 100644
--- a/src/mpi/romio/mpi-io/read.c
+++ b/src/mpi/romio/mpi-io/read.c
@@ -79,8 +79,6 @@ int MPIOI_File_read(MPI_File fh,
     ADIO_Offset off, bufsize;
     void *xbuf=NULL, *e32_buf=NULL;
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -180,8 +178,6 @@ int MPIOI_File_read(MPI_File fh,
     }
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
-
     return error_code;
 }
 #endif
diff --git a/src/mpi/romio/mpi-io/read_all.c b/src/mpi/romio/mpi-io/read_all.c
index e0b605d..eed2606 100644
--- a/src/mpi/romio/mpi-io/read_all.c
+++ b/src/mpi/romio/mpi-io/read_all.c
@@ -80,8 +80,6 @@ int MPIOI_File_read_all(MPI_File fh,
     ADIO_File adio_fh;
     void *xbuf=NULL, *e32_buf=NULL;
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -135,8 +133,6 @@ int MPIOI_File_read_all(MPI_File fh,
     }
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
-
     return error_code;
 }
 #endif
diff --git a/src/mpi/romio/mpi-io/read_allb.c b/src/mpi/romio/mpi-io/read_allb.c
index 2110f71..5e2b31a 100644
--- a/src/mpi/romio/mpi-io/read_allb.c
+++ b/src/mpi/romio/mpi-io/read_allb.c
@@ -67,8 +67,6 @@ int MPIOI_File_read_all_begin(MPI_File fh,
     ADIO_File adio_fh;
     void *xbuf=NULL, *e32_buf=NULL;
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -132,8 +130,6 @@ int MPIOI_File_read_all_begin(MPI_File fh,
     }
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
-
     return error_code;
 }
 #endif
diff --git a/src/mpi/romio/mpi-io/read_alle.c b/src/mpi/romio/mpi-io/read_alle.c
index e2853c1..1754b6c 100644
--- a/src/mpi/romio/mpi-io/read_alle.c
+++ b/src/mpi/romio/mpi-io/read_alle.c
@@ -60,8 +60,6 @@ int MPIOI_File_read_all_end(MPI_File fh,
 
     MPIU_UNREFERENCED_ARG(buf);
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -83,8 +81,6 @@ int MPIOI_File_read_all_end(MPI_File fh,
     adio_fh->split_coll_count = 0;
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
-
     return error_code;
 }
 #endif
diff --git a/src/mpi/romio/mpi-io/read_ord.c b/src/mpi/romio/mpi-io/read_ord.c
index be87763..0560d89 100644
--- a/src/mpi/romio/mpi-io/read_ord.c
+++ b/src/mpi/romio/mpi-io/read_ord.c
@@ -53,8 +53,6 @@ int MPI_File_read_ordered(MPI_File fh, void *buf, int count,
     ADIO_Offset shared_fp=0;
     ADIO_File adio_fh;
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -104,8 +102,6 @@ int MPI_File_read_ordered(MPI_File fh, void *buf, int count,
     /* --END ERROR HANDLING-- */
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
-
     /* FIXME: Check for error code from ReadStridedColl? */
     return error_code;
 }
diff --git a/src/mpi/romio/mpi-io/read_ordb.c b/src/mpi/romio/mpi-io/read_ordb.c
index 5548bde..88fbc9b 100644
--- a/src/mpi/romio/mpi-io/read_ordb.c
+++ b/src/mpi/romio/mpi-io/read_ordb.c
@@ -50,8 +50,6 @@ int MPI_File_read_ordered_begin(MPI_File fh, void *buf, int count,
     static char myname[] = "MPI_FILE_READ_ORDERED_BEGIN";
     void *xbuf=NULL, *e32_buf=NULL;
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -131,7 +129,5 @@ int MPI_File_read_ordered_begin(MPI_File fh, void *buf, int count,
     }
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
-
     return error_code;
 }
diff --git a/src/mpi/romio/mpi-io/read_orde.c b/src/mpi/romio/mpi-io/read_orde.c
index 542f687..649d2e0 100644
--- a/src/mpi/romio/mpi-io/read_orde.c
+++ b/src/mpi/romio/mpi-io/read_orde.c
@@ -45,8 +45,6 @@ int MPI_File_read_ordered_end(MPI_File fh, void *buf, MPI_Status *status)
 
     MPIU_UNREFERENCED_ARG(buf);
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -69,7 +67,5 @@ int MPI_File_read_ordered_end(MPI_File fh, void *buf, MPI_Status *status)
     adio_fh->split_coll_count = 0;
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
-
     return error_code;
 }
diff --git a/src/mpi/romio/mpi-io/read_sh.c b/src/mpi/romio/mpi-io/read_sh.c
index 8ebbf87..34e76b0 100644
--- a/src/mpi/romio/mpi-io/read_sh.c
+++ b/src/mpi/romio/mpi-io/read_sh.c
@@ -52,8 +52,6 @@ int MPI_File_read_shared(MPI_File fh, void *buf, int count,
     ADIO_File adio_fh;
     void *xbuf=NULL, *e32_buf=NULL;
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -149,7 +147,5 @@ int MPI_File_read_shared(MPI_File fh, void *buf, int count,
 	ADIOI_Free(e32_buf);
     }
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
-
     return error_code;
 }
diff --git a/src/mpi/romio/mpi-io/register_datarep.c b/src/mpi/romio/mpi-io/register_datarep.c
index 3895872..53ebe3c 100644
--- a/src/mpi/romio/mpi-io/register_datarep.c
+++ b/src/mpi/romio/mpi-io/register_datarep.c
@@ -62,8 +62,6 @@ int MPI_Register_datarep(ROMIO_CONST char *datarep,
     ADIOI_Datarep *adio_datarep;
     static char myname[] = "MPI_REGISTER_DATAREP";
 
-    ROMIO_THREAD_CS_ENTER();
-
     /* --BEGIN ERROR HANDLING-- */
     /* check datarep name (use strlen instead of strnlen because
        strnlen is not portable) */
@@ -139,7 +137,5 @@ int MPI_Register_datarep(ROMIO_CONST char *datarep,
     error_code = MPI_SUCCESS;
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
-
     return error_code;
 }
diff --git a/src/mpi/romio/mpi-io/seek.c b/src/mpi/romio/mpi-io/seek.c
index c68394a..78602b1 100644
--- a/src/mpi/romio/mpi-io/seek.c
+++ b/src/mpi/romio/mpi-io/seek.c
@@ -49,8 +49,6 @@ int MPI_File_seek(MPI_File fh, MPI_Offset offset, int whence)
     HPMP_IO_START(fl_xmpi, BLKMPIFILESEEK, TRDTBLOCK, adio_fh, MPI_DATATYPE_NULL, -1);
 #endif /* MPI_hpux */
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -134,6 +132,5 @@ int MPI_File_seek(MPI_File fh, MPI_Offset offset, int whence)
     error_code = MPI_SUCCESS;
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
     return error_code;
 }
diff --git a/src/mpi/romio/mpi-io/seek_sh.c b/src/mpi/romio/mpi-io/seek_sh.c
index d3ce1ab..18396a5 100644
--- a/src/mpi/romio/mpi-io/seek_sh.c
+++ b/src/mpi/romio/mpi-io/seek_sh.c
@@ -41,8 +41,6 @@ int MPI_File_seek_shared(MPI_File fh, MPI_Offset offset, int whence)
     MPI_Offset curr_offset, eof_offset, tmp_offset;
     ADIO_File adio_fh;
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -178,7 +176,5 @@ int MPI_File_seek_shared(MPI_File fh, MPI_Offset offset, int whence)
     error_code = MPI_SUCCESS;
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
-
     return error_code;
 }
diff --git a/src/mpi/romio/mpi-io/set_atom.c b/src/mpi/romio/mpi-io/set_atom.c
index 00be9fc..7cd5c5f 100644
--- a/src/mpi/romio/mpi-io/set_atom.c
+++ b/src/mpi/romio/mpi-io/set_atom.c
@@ -41,8 +41,6 @@ int MPI_File_set_atomicity(MPI_File fh, int flag)
     ADIO_Fcntl_t *fcntl_struct;
     ADIO_File adio_fh;
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -86,6 +84,5 @@ int MPI_File_set_atomicity(MPI_File fh, int flag)
     ADIOI_Free(fcntl_struct);
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
     return error_code;
 }
diff --git a/src/mpi/romio/mpi-io/set_errh.c b/src/mpi/romio/mpi-io/set_errh.c
index 5a299f9..b9f4203 100644
--- a/src/mpi/romio/mpi-io/set_errh.c
+++ b/src/mpi/romio/mpi-io/set_errh.c
@@ -42,8 +42,6 @@ int MPI_File_set_errhandler(MPI_File mpi_fh, MPI_Errhandler errhandler)
     ADIO_File fh;
     MPIU_THREADPRIV_DECL;
 
-    ROMIO_THREAD_CS_ENTER();
-
     if (mpi_fh == MPI_FILE_NULL) {
 	ADIOI_DFLT_ERR_HANDLER = errhandler;
     }
@@ -71,6 +69,5 @@ int MPI_File_set_errhandler(MPI_File mpi_fh, MPI_Errhandler errhandler)
     }
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
     return error_code;
 }
diff --git a/src/mpi/romio/mpi-io/set_info.c b/src/mpi/romio/mpi-io/set_info.c
index 2c898fe..4eb1405 100644
--- a/src/mpi/romio/mpi-io/set_info.c
+++ b/src/mpi/romio/mpi-io/set_info.c
@@ -40,8 +40,6 @@ int MPI_File_set_info(MPI_File fh, MPI_Info info)
     static char myname[] = "MPI_FILE_SET_INFO";
     ADIO_File adio_fh;
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -58,8 +56,6 @@ fn_exit:
 	error_code = MPIO_Err_return_file(adio_fh, error_code);
     /* --END ERROR HANDLING-- */
 
-    ROMIO_THREAD_CS_EXIT();
-
     return error_code;
 fn_fail:
     goto fn_exit;
diff --git a/src/mpi/romio/mpi-io/set_size.c b/src/mpi/romio/mpi-io/set_size.c
index b658929..26a8b4d 100644
--- a/src/mpi/romio/mpi-io/set_size.c
+++ b/src/mpi/romio/mpi-io/set_size.c
@@ -48,8 +48,6 @@ int MPI_File_set_size(MPI_File fh, MPI_Offset size)
 		  MPI_DATATYPE_NULL, -1);
 #endif /* MPI_hpux */
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -99,7 +97,5 @@ int MPI_File_set_size(MPI_File fh, MPI_Offset size)
 #endif /* MPI_hpux */
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
-
     return error_code;
 }
diff --git a/src/mpi/romio/mpi-io/set_view.c b/src/mpi/romio/mpi-io/set_view.c
index 4d98fdd..e5fc2ef 100644
--- a/src/mpi/romio/mpi-io/set_view.c
+++ b/src/mpi/romio/mpi-io/set_view.c
@@ -48,8 +48,6 @@ int MPI_File_set_view(MPI_File fh, MPI_Offset disp, MPI_Datatype etype,
     ADIO_Offset shared_fp, byte_off;
     ADIO_File adio_fh;
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -193,8 +191,6 @@ int MPI_File_set_view(MPI_File fh, MPI_Offset disp, MPI_Datatype etype,
 	adio_fh->is_external32 = 1;
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
-
     return error_code;
 fn_fail:
 	/* --BEGIN ERROR HANDLING-- */
diff --git a/src/mpi/romio/mpi-io/write.c b/src/mpi/romio/mpi-io/write.c
index eb9a77f..8aa22d1 100644
--- a/src/mpi/romio/mpi-io/write.c
+++ b/src/mpi/romio/mpi-io/write.c
@@ -80,8 +80,6 @@ int MPIOI_File_write(MPI_File fh,
     void *e32buf=NULL;
     const void *xbuf=NULL;
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -179,8 +177,6 @@ int MPIOI_File_write(MPI_File fh,
 
 fn_exit:
     if (e32buf!= NULL) ADIOI_Free(e32buf);
-    ROMIO_THREAD_CS_EXIT();
-
     return error_code;
 }
 #endif
diff --git a/src/mpi/romio/mpi-io/write_all.c b/src/mpi/romio/mpi-io/write_all.c
index 6f17cc3..e48fe98 100644
--- a/src/mpi/romio/mpi-io/write_all.c
+++ b/src/mpi/romio/mpi-io/write_all.c
@@ -81,8 +81,6 @@ int MPIOI_File_write_all(MPI_File fh,
     void *e32buf=NULL;
     const void *xbuf=NULL;
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -127,8 +125,6 @@ int MPIOI_File_write_all(MPI_File fh,
 
 fn_exit:
     if (e32buf != NULL) ADIOI_Free(e32buf);
-    ROMIO_THREAD_CS_EXIT();
-
     return error_code;
 }
 #endif
diff --git a/src/mpi/romio/mpi-io/write_allb.c b/src/mpi/romio/mpi-io/write_allb.c
index e184723..40b2fe9 100644
--- a/src/mpi/romio/mpi-io/write_allb.c
+++ b/src/mpi/romio/mpi-io/write_allb.c
@@ -67,8 +67,6 @@ int MPIOI_File_write_all_begin(MPI_File fh,
     void *e32buf=NULL;
     const void *xbuf=NULL;
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -125,8 +123,6 @@ int MPIOI_File_write_all_begin(MPI_File fh,
 
 fn_exit:
     if ( e32buf != NULL) ADIOI_Free(e32buf);
-    ROMIO_THREAD_CS_EXIT();
-
     return error_code;
 }
 #endif
diff --git a/src/mpi/romio/mpi-io/write_alle.c b/src/mpi/romio/mpi-io/write_alle.c
index 6dc7f6d..5699858 100644
--- a/src/mpi/romio/mpi-io/write_alle.c
+++ b/src/mpi/romio/mpi-io/write_alle.c
@@ -59,8 +59,6 @@ int MPIOI_File_write_all_end(MPI_File fh,
 
     MPIU_UNREFERENCED_ARG(buf);
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -88,8 +86,6 @@ int MPIOI_File_write_all_end(MPI_File fh,
     error_code = MPI_SUCCESS;
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
-
     return error_code;
 }
 #endif
diff --git a/src/mpi/romio/mpi-io/write_ord.c b/src/mpi/romio/mpi-io/write_ord.c
index eb72734..17b8d21 100644
--- a/src/mpi/romio/mpi-io/write_ord.c
+++ b/src/mpi/romio/mpi-io/write_ord.c
@@ -56,8 +56,6 @@ int MPI_File_write_ordered(MPI_File fh, ROMIO_CONST void *buf, int count,
     void *e32buf=NULL;
     const void *xbuf;
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -120,7 +118,6 @@ int MPI_File_write_ordered(MPI_File fh, ROMIO_CONST void *buf, int count,
 
 fn_exit:
     if (e32buf != NULL) ADIOI_Free(e32buf);
-    ROMIO_THREAD_CS_EXIT();
 
     /* FIXME: Check for error code from WriteStridedColl? */
     return error_code;
diff --git a/src/mpi/romio/mpi-io/write_ordb.c b/src/mpi/romio/mpi-io/write_ordb.c
index 8b5a302..829f13e 100644
--- a/src/mpi/romio/mpi-io/write_ordb.c
+++ b/src/mpi/romio/mpi-io/write_ordb.c
@@ -52,8 +52,6 @@ int MPI_File_write_ordered_begin(MPI_File fh, ROMIO_CONST void *buf, int count,
     void *e32buf = NULL;
     const void *xbuf=NULL;
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -125,8 +123,6 @@ int MPI_File_write_ordered_begin(MPI_File fh, ROMIO_CONST void *buf, int count,
     /* --END ERROR HANDLING-- */
 
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
-
     /* FIXME: Check for error code from WriteStridedColl? */
     return error_code;
 }
diff --git a/src/mpi/romio/mpi-io/write_orde.c b/src/mpi/romio/mpi-io/write_orde.c
index 8cfdba2..4d294b8 100644
--- a/src/mpi/romio/mpi-io/write_orde.c
+++ b/src/mpi/romio/mpi-io/write_orde.c
@@ -45,8 +45,6 @@ int MPI_File_write_ordered_end(MPI_File fh, ROMIO_CONST void *buf, MPI_Status *s
 
     MPIU_UNREFERENCED_ARG(buf);
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -68,8 +66,6 @@ int MPI_File_write_ordered_end(MPI_File fh, ROMIO_CONST void *buf, MPI_Status *s
 #endif
     adio_fh->split_coll_count = 0;
 
-
 fn_exit:
-    ROMIO_THREAD_CS_EXIT();
     return MPI_SUCCESS;
 }
diff --git a/src/mpi/romio/mpi-io/write_sh.c b/src/mpi/romio/mpi-io/write_sh.c
index ed8e1c1..ce6444b 100644
--- a/src/mpi/romio/mpi-io/write_sh.c
+++ b/src/mpi/romio/mpi-io/write_sh.c
@@ -54,8 +54,6 @@ int MPI_File_write_shared(MPI_File fh, ROMIO_CONST void *buf, int count,
     void *e32buf = NULL;
     const void *xbuf = NULL;
 
-    ROMIO_THREAD_CS_ENTER();
-
     adio_fh = MPIO_File_resolve(fh);
 
     /* --BEGIN ERROR HANDLING-- */
@@ -144,6 +142,5 @@ int MPI_File_write_shared(MPI_File fh, ROMIO_CONST void *buf, int count,
 
 fn_exit:
     if (e32buf != NULL) ADIOI_Free(e32buf);
-    ROMIO_THREAD_CS_EXIT();
     return error_code;
 }

-----------------------------------------------------------------------

Summary of changes:
 src/glue/romio/glue_romio.c                        |   35 +++-
 src/include/glue_romio.h.in                        |    8 +-
 src/mpi/init/initthread.c                          |    2 -
 src/mpi/romio/adio/ad_gpfs/ad_gpfs_rdcoll.c        |    4 +-
 src/mpi/romio/adio/ad_gpfs/ad_gpfs_wrcoll.c        |    4 +-
 src/mpi/romio/adio/ad_gridftp/ad_gridftp_read.c    |    5 +-
 src/mpi/romio/adio/ad_gridftp/ad_gridftp_write.c   |    5 +-
 src/mpi/romio/adio/ad_lustre/ad_lustre_wrcoll.c    |    5 +-
 src/mpi/romio/adio/ad_lustre/ad_lustre_wrstr.c     |   10 +-
 src/mpi/romio/adio/ad_nfs/ad_nfs_read.c            |    8 +-
 src/mpi/romio/adio/ad_nfs/ad_nfs_write.c           |    8 +-
 src/mpi/romio/adio/ad_piofs/ad_piofs_write.c       |    8 +-
 src/mpi/romio/adio/ad_pvfs/ad_pvfs_read.c          |    8 +-
 src/mpi/romio/adio/ad_pvfs/ad_pvfs_write.c         |   16 +--
 src/mpi/romio/adio/ad_pvfs2/ad_pvfs2_io_list.c     |   10 +-
 .../adio/ad_pvfs2/ad_pvfs2_read_list_classic.c     |    8 +-
 .../adio/ad_pvfs2/ad_pvfs2_write_list_classic.c    |    8 +-
 src/mpi/romio/adio/ad_zoidfs/ad_zoidfs_read_list.c |    8 +-
 .../romio/adio/ad_zoidfs/ad_zoidfs_write_list.c    |    8 +-
 src/mpi/romio/adio/common/ad_coll_exch_new.c       |    5 +-
 src/mpi/romio/adio/common/ad_end.c                 |    5 +
 src/mpi/romio/adio/common/ad_iread_coll.c          |   10 +-
 src/mpi/romio/adio/common/ad_iwrite_coll.c         |   10 +-
 src/mpi/romio/adio/common/ad_read_coll.c           |    4 +-
 src/mpi/romio/adio/common/ad_read_str.c            |    8 +-
 src/mpi/romio/adio/common/ad_read_str_naive.c      |    8 +-
 src/mpi/romio/adio/common/ad_write_coll.c          |    4 +-
 src/mpi/romio/adio/common/ad_write_nolock.c        |    8 +-
 src/mpi/romio/adio/common/ad_write_str.c           |    8 +-
 src/mpi/romio/adio/common/ad_write_str_naive.c     |    8 +-
 src/mpi/romio/adio/common/cb_config_list.c         |    2 +
 src/mpi/romio/adio/common/flatten.c                |   16 ++
 src/mpi/romio/adio/common/onesided_aggregation.c   |    8 +-
 src/mpi/romio/adio/include/adioi.h                 |    3 +
 src/mpi/romio/mpi-io/close.c                       |    3 -
 src/mpi/romio/mpi-io/delete.c                      |    3 -
 src/mpi/romio/mpi-io/fsync.c                       |    2 -
 src/mpi/romio/mpi-io/get_errh.c                    |    3 -
 src/mpi/romio/mpi-io/get_group.c                   |    3 -
 src/mpi/romio/mpi-io/get_info.c                    |    3 -
 src/mpi/romio/mpi-io/get_view.c                    |    4 -
 src/mpi/romio/mpi-io/glue/mpich/mpio_file.c        |    2 +
 src/mpi/romio/mpi-io/ioreq_c2f.c                   |    2 -
 src/mpi/romio/mpi-io/ioreq_f2c.c                   |    3 -
 src/mpi/romio/mpi-io/iotest.c                      |    3 -
 src/mpi/romio/mpi-io/iotestall.c                   |    2 -
 src/mpi/romio/mpi-io/iotestany.c                   |    3 -
 src/mpi/romio/mpi-io/iotestsome.c                  |    4 -
 src/mpi/romio/mpi-io/iowait.c                      |    3 -
 src/mpi/romio/mpi-io/iowaitall.c                   |    4 -
 src/mpi/romio/mpi-io/iowaitany.c                   |    4 -
 src/mpi/romio/mpi-io/iowaitsome.c                  |    3 -
 src/mpi/romio/mpi-io/iread.c                       |    4 -
 src/mpi/romio/mpi-io/iread_all.c                   |    4 -
 src/mpi/romio/mpi-io/iread_sh.c                    |    3 -
 src/mpi/romio/mpi-io/iwrite.c                      |    2 -
 src/mpi/romio/mpi-io/iwrite_all.c                  |    4 -
 src/mpi/romio/mpi-io/iwrite_sh.c                   |    4 -
 src/mpi/romio/mpi-io/mpioimpl.h                    |   12 +-
 src/mpi/romio/mpi-io/mpir-mpioinit.c               |    4 +
 src/mpi/romio/mpi-io/open.c                        |    3 -
 src/mpi/romio/mpi-io/prealloc.c                    |    4 -
 src/mpi/romio/mpi-io/read.c                        |    4 -
 src/mpi/romio/mpi-io/read_all.c                    |    4 -
 src/mpi/romio/mpi-io/read_allb.c                   |    4 -
 src/mpi/romio/mpi-io/read_alle.c                   |    4 -
 src/mpi/romio/mpi-io/read_ord.c                    |    4 -
 src/mpi/romio/mpi-io/read_ordb.c                   |    4 -
 src/mpi/romio/mpi-io/read_orde.c                   |    4 -
 src/mpi/romio/mpi-io/read_sh.c                     |    4 -
 src/mpi/romio/mpi-io/register_datarep.c            |    4 -
 src/mpi/romio/mpi-io/seek.c                        |    3 -
 src/mpi/romio/mpi-io/seek_sh.c                     |    4 -
 src/mpi/romio/mpi-io/set_atom.c                    |    3 -
 src/mpi/romio/mpi-io/set_errh.c                    |    3 -
 src/mpi/romio/mpi-io/set_info.c                    |    4 -
 src/mpi/romio/mpi-io/set_size.c                    |    4 -
 src/mpi/romio/mpi-io/set_view.c                    |    4 -
 src/mpi/romio/mpi-io/write.c                       |    4 -
 src/mpi/romio/mpi-io/write_all.c                   |    4 -
 src/mpi/romio/mpi-io/write_allb.c                  |    4 -
 src/mpi/romio/mpi-io/write_alle.c                  |    4 -
 src/mpi/romio/mpi-io/write_ord.c                   |    3 -
 src/mpi/romio/mpi-io/write_ordb.c                  |    4 -
 src/mpi/romio/mpi-io/write_orde.c                  |    4 -
 src/mpi/romio/mpi-io/write_sh.c                    |    3 -
 src/util/thread/mpiu_thread.h                      |    8 -
 src/util/thread/mpiu_thread_global.h               |   36 +---
 src/util/thread/mpiu_thread_multiple.h             |  184 ++-----------------
 src/util/thread/mpiu_thread_pobj.h                 |   32 +---
 90 files changed, 153 insertions(+), 571 deletions(-)


hooks/post-receive
-- 
MPICH primary repository


More information about the commits mailing list