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

Service Account noreply at mpich.org
Tue Aug 11 16:37:40 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  a79f6888751553bb7804b6858ebfd8d5f0df4851 (commit)
       via  70b0e0d7ccee74aaff912c99419476bec14e2e82 (commit)
       via  688f9f9e24b042cff5de99904325a384d8e46c1d (commit)
       via  98d4b47ab463e3371c372e6621a72ca244d547bf (commit)
      from  4551de14b1d752a9c7be49df4a9e70776addd02f (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/a79f6888751553bb7804b6858ebfd8d5f0df4851

commit a79f6888751553bb7804b6858ebfd8d5f0df4851
Author: Xin Zhao <xinzhao3 at illinois.edu>
Date:   Tue Aug 11 14:14:02 2015 -0500

    Add Progress_activate/de-activate_hook routines.
    
    Here we add Progress_activate/de-activate_hook routines,
    which activate / de-activate a progress hook specified by
    corresponding id.
    
    Signed-off-by: Pavan Balaji <balaji at anl.gov>

diff --git a/src/mpid/ch3/channels/nemesis/include/mpidi_ch3_impl.h b/src/mpid/ch3/channels/nemesis/include/mpidi_ch3_impl.h
index a3b4d81..bef6b72 100644
--- a/src/mpid/ch3/channels/nemesis/include/mpidi_ch3_impl.h
+++ b/src/mpid/ch3/channels/nemesis/include/mpidi_ch3_impl.h
@@ -52,6 +52,8 @@ int MPIDI_CH3I_Progress_init(void);
 int MPIDI_CH3I_Progress_finalize(void);
 int MPIDI_CH3I_Progress_register_hook(int (*progress_fn)(int*), int *id);
 int MPIDI_CH3I_Progress_deregister_hook(int id);
+int MPIDI_CH3I_Progress_activate_hook(int id);
+int MPIDI_CH3I_Progress_deactivate_hook(int id);
 int MPIDI_CH3I_Shm_send_progress(void);
 int MPIDI_CH3I_Complete_sendq_with_error(MPIDI_VC_t * vc);
 
diff --git a/src/mpid/ch3/channels/nemesis/src/ch3_progress.c b/src/mpid/ch3/channels/nemesis/src/ch3_progress.c
index 8ece505..e65f82c 100644
--- a/src/mpid/ch3/channels/nemesis/src/ch3_progress.c
+++ b/src/mpid/ch3/channels/nemesis/src/ch3_progress.c
@@ -86,8 +86,14 @@ static qn_ent_t *qn_head = NULL;
 
 #define MAX_PROGRESS_HOOKS 16
 typedef int (*progress_func_ptr_t) (int* made_progress);
-static progress_func_ptr_t  progress_hooks[MAX_PROGRESS_HOOKS] = { NULL };
-static int total_progress_hook_cnt = 0; /* Keep track of how many progress hooks are currently registered */
+
+typedef struct progress_hook_slot {
+    progress_func_ptr_t func_ptr;
+    int active;
+} progress_hook_slot_t;
+
+static progress_hook_slot_t progress_hooks[MAX_PROGRESS_HOOKS];
+static int total_progress_hook_cnt = 0; /* Keep track of how many progress hooks are currently activated */
 
 #ifdef HAVE_SIGNAL
 static void sigusr1_handler(int sig)
@@ -301,12 +307,9 @@ int MPIDI_CH3I_Progress_register_hook(int (*progress_fn)(int*), int *id)
     MPIU_THREAD_CS_ENTER(MPIDCOMM,);
 
     for (i = 0; i < MAX_PROGRESS_HOOKS; i++) {
-        if (progress_hooks[i] == NULL) {
-            progress_hooks[i] = progress_fn;
-
-            total_progress_hook_cnt++;
-            MPIU_Assert(total_progress_hook_cnt <= MAX_PROGRESS_HOOKS);
-
+        if (progress_hooks[i].func_ptr == NULL) {
+            progress_hooks[i].func_ptr = progress_fn;
+            progress_hooks[i].active = FALSE;
             break;
         }
     }
@@ -340,16 +343,72 @@ int MPIDI_CH3I_Progress_deregister_hook(int id)
     MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CH3I_PROGRESS_DEREGISTER_HOOK);
     MPIU_THREAD_CS_ENTER(MPIDCOMM,);
 
-    MPIU_Assert(id >= 0 && id < MAX_PROGRESS_HOOKS && progress_hooks[id] != NULL);
+    MPIU_Assert(id >= 0 && id < MAX_PROGRESS_HOOKS && progress_hooks[id].func_ptr != NULL);
+
+    progress_hooks[id].func_ptr = NULL;
+    progress_hooks[id].active = FALSE;
+
+  fn_exit:
+    MPIU_THREAD_CS_EXIT(MPIDCOMM,);
+    MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3I_PROGRESS_DEREGISTER_HOOK);
+    return mpi_errno;
+
+  fn_fail:
+    goto fn_exit;
+}
+
+
+#undef FUNCNAME
+#define FUNCNAME MPIDI_CH3I_Progress_activate_hook
+#undef FCNAME
+#define FCNAME MPIU_QUOTE(FUNCNAME)
+int MPIDI_CH3I_Progress_activate_hook(int id)
+{
+    int mpi_errno = MPI_SUCCESS;
+    MPIDI_STATE_DECL(MPID_STATE_MPIDI_CH3I_PROGRESS_ACTIVATE_HOOK);
+
+    MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CH3I_PROGRESS_ACTIVATE_HOOK);
+    MPIU_THREAD_CS_ENTER(MPIDCOMM,);
+
+    MPIU_Assert(id >= 0 && id < MAX_PROGRESS_HOOKS &&
+                progress_hooks[id].active == FALSE && progress_hooks[id].func_ptr != NULL);
+    progress_hooks[id].active = TRUE;
 
-    progress_hooks[id] = NULL;
+    total_progress_hook_cnt++;
+    MPIU_Assert(total_progress_hook_cnt <= MAX_PROGRESS_HOOKS);
+
+  fn_exit:
+    MPIU_THREAD_CS_EXIT(MPIDCOMM,);
+    MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3I_PROGRESS_ACTIVATE_HOOK);
+    return mpi_errno;
+
+  fn_fail:
+    goto fn_exit;
+}
+
+
+#undef FUNCNAME
+#define FUNCNAME MPIDI_CH3I_Progress_deactivate_hook
+#undef FCNAME
+#define FCNAME MPIU_QUOTE(FUNCNAME)
+int MPIDI_CH3I_Progress_deactivate_hook(int id)
+{
+    int mpi_errno = MPI_SUCCESS;
+    MPIDI_STATE_DECL(MPID_STATE_MPIDI_CH3I_PROGRESS_DEACTIVATE_HOOK);
+
+    MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CH3I_PROGRESS_DEACTIVATE_HOOK);
+    MPIU_THREAD_CS_ENTER(MPIDCOMM,);
+
+    MPIU_Assert(id >= 0 && id < MAX_PROGRESS_HOOKS &&
+                progress_hooks[id].active == TRUE && progress_hooks[id].func_ptr != NULL);
+    progress_hooks[id].active = FALSE;
 
     total_progress_hook_cnt--;
     MPIU_Assert(total_progress_hook_cnt >= 0);
 
   fn_exit:
     MPIU_THREAD_CS_EXIT(MPIDCOMM,);
-    MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3I_PROGRESS_DEREGISTER_HOOK);
+    MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3I_PROGRESS_DEACTIVATE_HOOK);
     return mpi_errno;
 
   fn_fail:
@@ -542,8 +601,9 @@ int MPIDI_CH3I_Progress (MPID_Progress_state *progress_state, int is_blocking)
 
         called_progress_hook_cnt = 0;
         for (i = 0; i < MAX_PROGRESS_HOOKS; i++) {
-            if (progress_hooks[i] != NULL) {
-                mpi_errno = progress_hooks[i](&made_progress);
+            if (progress_hooks[i].active == TRUE) {
+                MPIU_Assert(progress_hooks[i].func_ptr != NULL);
+                mpi_errno = progress_hooks[i].func_ptr(&made_progress);
                 if (mpi_errno) MPIU_ERR_POP(mpi_errno);
                 if (made_progress)
                     MPIDI_CH3_Progress_signal_completion();
@@ -894,6 +954,7 @@ int MPID_nem_handle_pkt(MPIDI_VC_t *vc, char *buf, MPIDI_msg_sz_t buflen)
 #define FCNAME MPIU_QUOTE(FUNCNAME)
 int MPIDI_CH3I_Progress_init(void)
 {
+    int i;
     int mpi_errno = MPI_SUCCESS;
     MPIDI_STATE_DECL(MPID_STATE_MPIDI_CH3I_PROGRESS_INIT);
 
@@ -942,6 +1003,12 @@ int MPIDI_CH3I_Progress_init(void)
         prev_sighandler = NULL;
 #endif
 
+    /* Initialize progress hook slots */
+    for (i = 0; i < MAX_PROGRESS_HOOKS; i++) {
+        progress_hooks[i].func_ptr = NULL;
+        progress_hooks[i].active = FALSE;
+    }
+
  fn_exit:
     MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3I_PROGRESS_INIT);
     return mpi_errno;
diff --git a/src/mpid/ch3/channels/sock/include/mpidi_ch3_impl.h b/src/mpid/ch3/channels/sock/include/mpidi_ch3_impl.h
index be1783a..27f09a8 100644
--- a/src/mpid/ch3/channels/sock/include/mpidi_ch3_impl.h
+++ b/src/mpid/ch3/channels/sock/include/mpidi_ch3_impl.h
@@ -74,6 +74,8 @@ int MPIDI_CH3I_Progress_init(void);
 int MPIDI_CH3I_Progress_finalize(void);
 int MPIDI_CH3I_Progress_register_hook(int (*progress_fn)(int*), int *id);
 int MPIDI_CH3I_Progress_deregister_hook(int id);
+int MPIDI_CH3I_Progress_activate_hook(int id);
+int MPIDI_CH3I_Progress_deactivate_hook(int id);
 int MPIDI_CH3I_VC_post_connect(MPIDI_VC_t *);
 
 /* Shared memory window atomic/accumulate mutex implementation */
diff --git a/src/mpid/ch3/channels/sock/src/ch3_progress.c b/src/mpid/ch3/channels/sock/src/ch3_progress.c
index 154eb9c..77236b1 100644
--- a/src/mpid/ch3/channels/sock/src/ch3_progress.c
+++ b/src/mpid/ch3/channels/sock/src/ch3_progress.c
@@ -47,8 +47,14 @@ static int adjust_iov(MPID_IOV ** iovp, int * countp, MPIU_Size_t nb);
 
 #define MAX_PROGRESS_HOOKS 16
 typedef int (*progress_func_ptr_t) (int* made_progress);
-static progress_func_ptr_t progress_hooks[MAX_PROGRESS_HOOKS] = { NULL };
-static int total_progress_hook_cnt = 0; /* Keep track of how many progress hooks are currently registered */
+
+typedef struct progress_hook_slot {
+    progress_func_ptr_t func_ptr;
+    int active;
+} progress_hook_slot_t;
+
+static progress_hook_slot_t progress_hooks[MAX_PROGRESS_HOOKS];
+static int total_progress_hook_cnt = 0; /* Keep track of how many progress hooks are currently activated */
 
 #undef FUNCNAME
 #define FUNCNAME MPIDI_CH3i_Progress_test
@@ -94,8 +100,9 @@ static int MPIDI_CH3i_Progress_test(void)
     
     called_progress_hook_cnt = 0;
     for (i = 0; i < MAX_PROGRESS_HOOKS; i++) {
-        if (progress_hooks[i] != NULL) {
-            mpi_errno = progress_hooks[i](&made_progress);
+        if (progress_hooks[i].active == TRUE) {
+            MPIU_Assert(progress_hooks[i].func_ptr != NULL);
+            mpi_errno = progress_hooks[i].func_ptr(&made_progress);
             if (mpi_errno) MPIU_ERR_POP(mpi_errno);
 
             called_progress_hook_cnt++;
@@ -196,8 +203,9 @@ static int MPIDI_CH3i_Progress_wait(MPID_Progress_state * progress_state)
 
         called_progress_hook_cnt = 0;
         for (i = 0; i < MAX_PROGRESS_HOOKS; i++) {
-            if (progress_hooks[i] != NULL) {
-                mpi_errno = progress_hooks[i](&made_progress);
+            if (progress_hooks[i].active == TRUE) {
+                MPIU_Assert(progress_hooks[i].func_ptr != NULL);
+                mpi_errno = progress_hooks[i].func_ptr(&made_progress);
                 if (mpi_errno) MPIU_ERR_POP(mpi_errno);
                 if (made_progress) {
                     MPIDI_CH3_Progress_signal_completion();
@@ -312,6 +320,7 @@ int MPIDI_CH3_Connection_terminate(MPIDI_VC_t * vc)
 #define FCNAME MPIU_QUOTE(FUNCNAME)
 int MPIDI_CH3I_Progress_init(void)
 {
+    int i;
     int mpi_errno = MPI_SUCCESS;
     MPIDI_STATE_DECL(MPID_STATE_MPIDI_CH3I_PROGRESS_INIT);
 
@@ -346,6 +355,12 @@ int MPIDI_CH3I_Progress_init(void)
     /* Initialize the code to handle incoming packets */
     mpi_errno = MPIDI_CH3_PktHandler_Init( pktArray, MPIDI_CH3_PKT_END_CH3+1 );
     if (mpi_errno) { MPIU_ERR_POP(mpi_errno); }
+
+    /* Initialize progress hook slots */
+    for (i = 0; i < MAX_PROGRESS_HOOKS; i++) {
+        progress_hooks[i].func_ptr = NULL;
+        progress_hooks[i].active = FALSE;
+    }
     
   fn_exit:
     MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3I_PROGRESS_INIT);
@@ -977,12 +992,9 @@ int MPIDI_CH3I_Progress_register_hook(int (*progress_fn)(int*), int *id)
     MPIU_THREAD_CS_ENTER(MPIDCOMM,);
 
     for (i = 0; i < MAX_PROGRESS_HOOKS; i++) {
-        if (progress_hooks[i] == NULL) {
-            progress_hooks[i] = progress_fn;
-
-            total_progress_hook_cnt++;
-            MPIU_Assert(total_progress_hook_cnt <= MAX_PROGRESS_HOOKS);
-
+        if (progress_hooks[i].func_ptr == NULL) {
+            progress_hooks[i].func_ptr = progress_fn;
+            progress_hooks[i].active = FALSE;
             break;
         }
     }
@@ -1016,16 +1028,71 @@ int MPIDI_CH3I_Progress_deregister_hook(int id)
     MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CH3I_PROGRESS_DEREGISTER_HOOK);
     MPIU_THREAD_CS_ENTER(MPIDCOMM,);
 
-    MPIU_Assert(id >= 0 && id < MAX_PROGRESS_HOOKS && progress_hooks[id] != NULL);
+    MPIU_Assert(id >= 0 && id < MAX_PROGRESS_HOOKS && progress_hooks[id].func_ptr != NULL);
+
+    progress_hooks[id].func_ptr = NULL;
+    progress_hooks[id].active = FALSE;
+
+  fn_exit:
+    MPIU_THREAD_CS_EXIT(MPIDCOMM,);
+    MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3I_PROGRESS_DEREGISTER_HOOK);
+    return mpi_errno;
+
+  fn_fail:
+    goto fn_exit;
+}
+
+#undef FUNCNAME
+#define FUNCNAME MPIDI_CH3I_Progress_activate_hook
+#undef FCNAME
+#define FCNAME MPIU_QUOTE(FUNCNAME)
+int MPIDI_CH3I_Progress_activate_hook(int id)
+{
+    int mpi_errno = MPI_SUCCESS;
+    MPIDI_STATE_DECL(MPID_STATE_MPIDI_CH3I_PROGRESS_ACTIVATE_HOOK);
+
+    MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CH3I_PROGRESS_ACTIVATE_HOOK);
+    MPIU_THREAD_CS_ENTER(MPIDCOMM,);
+
+    MPIU_Assert(id >= 0 && id < MAX_PROGRESS_HOOKS &&
+                progress_hooks[id].active == FALSE && progress_hooks[id].func_ptr != NULL);
+    progress_hooks[id].active = TRUE;
+
+    total_progress_hook_cnt++;
+    MPIU_Assert(total_progress_hook_cnt <= MAX_PROGRESS_HOOKS);
+
+  fn_exit:
+    MPIU_THREAD_CS_EXIT(MPIDCOMM,);
+    MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3I_PROGRESS_ACTIVATE_HOOK);
+    return mpi_errno;
 
-    progress_hooks[id] = NULL;
+  fn_fail:
+    goto fn_exit;
+}
+
+
+#undef FUNCNAME
+#define FUNCNAME MPIDI_CH3I_Progress_deactivate_hook
+#undef FCNAME
+#define FCNAME MPIU_QUOTE(FUNCNAME)
+int MPIDI_CH3I_Progress_deactivate_hook(int id)
+{
+    int mpi_errno = MPI_SUCCESS;
+    MPIDI_STATE_DECL(MPID_STATE_MPIDI_CH3I_PROGRESS_DEACTIVATE_HOOK);
+
+    MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CH3I_PROGRESS_DEACTIVATE_HOOK);
+    MPIU_THREAD_CS_ENTER(MPIDCOMM,);
+
+    MPIU_Assert(id >= 0 && id < MAX_PROGRESS_HOOKS &&
+                progress_hooks[id].active == TRUE && progress_hooks[id].func_ptr != NULL);
+    progress_hooks[id].active = FALSE;
 
     total_progress_hook_cnt--;
     MPIU_Assert(total_progress_hook_cnt >= 0);
 
   fn_exit:
     MPIU_THREAD_CS_EXIT(MPIDCOMM,);
-    MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3I_PROGRESS_DEREGISTER_HOOK);
+    MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3I_PROGRESS_DEACTIVATE_HOOK);
     return mpi_errno;
 
   fn_fail:
diff --git a/src/mpid/ch3/include/mpid_rma_oplist.h b/src/mpid/ch3/include/mpid_rma_oplist.h
index 9843824..f233116 100644
--- a/src/mpid/ch3/include/mpid_rma_oplist.h
+++ b/src/mpid/ch3/include/mpid_rma_oplist.h
@@ -120,6 +120,11 @@ static inline int MPIDI_CH3I_Win_set_active(MPID_Win * win_ptr)
     if (win_ptr->active == FALSE) {
         win_ptr->active = TRUE;
 
+        if (MPIDI_RMA_Win_active_list_head == NULL) {
+            /* This is the first active window, activate RMA progress */
+            MPID_Progress_activate_hook(MPIDI_CH3I_RMA_Progress_hook_id);
+        }
+
         MPL_DL_DELETE(MPIDI_RMA_Win_inactive_list_head, win_ptr);
         MPL_DL_APPEND(MPIDI_RMA_Win_active_list_head, win_ptr);
     }
@@ -143,6 +148,11 @@ static inline int MPIDI_CH3I_Win_set_inactive(MPID_Win * win_ptr)
         win_ptr->active = FALSE;
         MPL_DL_DELETE(MPIDI_RMA_Win_active_list_head, win_ptr);
         MPL_DL_APPEND(MPIDI_RMA_Win_inactive_list_head, win_ptr);
+
+        if (MPIDI_RMA_Win_active_list_head == NULL) {
+            /* This is the last active window, de-activate RMA progress */
+            MPID_Progress_deactivate_hook(MPIDI_CH3I_RMA_Progress_hook_id);
+        }
     }
 
   fn_exit:
diff --git a/src/mpid/ch3/include/mpidimpl.h b/src/mpid/ch3/include/mpidimpl.h
index 1d238e3..fcf5f33 100644
--- a/src/mpid/ch3/include/mpidimpl.h
+++ b/src/mpid/ch3/include/mpidimpl.h
@@ -1940,8 +1940,12 @@ int MPIDI_CH3_Req_handler_rma_op_complete(MPID_Request *);
 
 int MPIDI_CH3I_Progress_register_hook(int (*progress_fn)(int*), int *id);
 int MPIDI_CH3I_Progress_deregister_hook(int id);
+int MPIDI_CH3I_Progress_activate_hook(int id);
+int MPIDI_CH3I_Progress_deactivate_hook(int id);
 
 #define MPID_Progress_register_hook(fn_, id_) MPIDI_CH3I_Progress_register_hook(fn_, id_)
 #define MPID_Progress_deregister_hook(id_) MPIDI_CH3I_Progress_deregister_hook(id_)
+#define MPID_Progress_activate_hook(id_) MPIDI_CH3I_Progress_activate_hook(id_)
+#define MPID_Progress_deactivate_hook(id_) MPIDI_CH3I_Progress_deactivate_hook(id_)
 
 #endif /* !defined(MPICH_MPIDIMPL_H_INCLUDED) */
diff --git a/src/mpid/common/hcoll/hcoll_init.c b/src/mpid/common/hcoll/hcoll_init.c
index 23f9680..5a8184c 100644
--- a/src/mpid/common/hcoll/hcoll_init.c
+++ b/src/mpid/common/hcoll/hcoll_init.c
@@ -25,6 +25,7 @@ int hcoll_destroy(void *param ATTRIBUTE((unused)))
 {
     if (1 == hcoll_initialized) {
         hcoll_finalize();
+        MPID_Progress_deactivate_hook(hcoll_progress_hook_id);
         MPID_Progress_deregister_hook(hcoll_progress_hook_id);
     }
     hcoll_initialized = 0;
@@ -87,6 +88,8 @@ int hcoll_initialize(void)
         mpi_errno = MPID_Progress_register_hook(hcoll_do_progress,
                                                 &hcoll_progress_hook_id);
         if (mpi_errno) MPIU_ERR_POP(mpi_errno);
+
+        MPID_Progress_activate_hook(hcoll_progress_hook_id);
     }
     MPIR_Add_finalize(hcoll_destroy, 0, 0);
 
diff --git a/src/mpid/common/sched/mpid_sched.c b/src/mpid/common/sched/mpid_sched.c
index 8098d37..f4865e5 100644
--- a/src/mpid/common/sched/mpid_sched.c
+++ b/src/mpid/common/sched/mpid_sched.c
@@ -415,6 +415,8 @@ int MPID_Sched_start(MPID_Sched_t *sp, MPID_Comm *comm, int tag, MPID_Request **
         mpi_errno = MPID_Progress_register_hook(MPIDU_Sched_progress,
                                                 &nbc_progress_hook_id);
         if (mpi_errno) MPIU_ERR_POP(mpi_errno);
+
+        MPID_Progress_activate_hook(nbc_progress_hook_id);
     }
     MPL_DL_APPEND(all_schedules.head, s);
 
@@ -944,8 +946,10 @@ int MPIDU_Sched_progress(int *made_progress)
     int mpi_errno;
 
     mpi_errno = MPIDU_Sched_progress_state(&all_schedules, made_progress);
-    if (!mpi_errno && all_schedules.head == NULL)
+    if (!mpi_errno && all_schedules.head == NULL) {
+        MPID_Progress_deactivate_hook(nbc_progress_hook_id);
         MPID_Progress_deregister_hook(nbc_progress_hook_id);
+    }
 
     return mpi_errno;
 }
diff --git a/src/mpid/pamid/include/mpidimpl.h b/src/mpid/pamid/include/mpidimpl.h
index 3a9e78c..3e131e4 100644
--- a/src/mpid/pamid/include/mpidimpl.h
+++ b/src/mpid/pamid/include/mpidimpl.h
@@ -187,7 +187,11 @@ MPI_Aint MPID_Aint_diff(MPI_Aint addr1, MPI_Aint addr2);
 
 int MPIDI_Progress_register_hook(int (*progress_fn)(int*), int *id);
 int MPIDI_Progress_deregister_hook(int id);
+int MPIDI_Progress_activate_hook(int id);
+int MPIDI_Progress_deactivate_hook(int id);
 
 #define MPID_Progress_register_hook(fn_, id_) MPIDI_Progress_register_hook(fn_, id_)
 #define MPID_Progress_deregister_hook(id_) MPIDI_Progress_deregister_hook(id_)
+#define MPID_Progress_activate_hook(id_) MPIDI_Progress_activate_hook(id_)
+#define MPID_Progress_deactivate_hook(id_) MPIDI_Progress_deactivate_hook(id_)
 #endif
diff --git a/src/mpid/pamid/src/mpid_progress.c b/src/mpid/pamid/src/mpid_progress.c
index f470563..72668bb 100644
--- a/src/mpid/pamid/src/mpid_progress.c
+++ b/src/mpid/pamid/src/mpid_progress.c
@@ -23,8 +23,14 @@
 
 #define MAX_PROGRESS_HOOKS 16
 typedef int (*progress_func_ptr_t) (int* made_progress);
-static progress_func_ptr_t  progress_hooks[MAX_PROGRESS_HOOKS] = { NULL };
-static int total_progress_hook_cnt = 0; /* Keep track of how many progress hooks are currently registered */
+
+typedef struct progress_hook_slot {
+    progress_func_ptr_t func_ptr;
+    int active;
+} progress_hook_slot_t;
+
+static progress_hook_slot_t progress_hooks[MAX_PROGRESS_HOOKS];
+static int total_progress_hook_cnt = 0; /* Keep track of how many progress hooks are currently activated */
 
 #undef FUNCNAME
 #define FUNCNAME MPIDI_Progress_register_hook
@@ -40,12 +46,9 @@ int MPIDI_Progress_register_hook(int (*progress_fn)(int*), int *id)
     MPIU_THREAD_CS_ENTER(ASYNC,);
 
     for (i = 0; i < MAX_PROGRESS_HOOKS; i++) {
-        if (progress_hooks[i] == NULL) {
-            progress_hooks[i] = progress_fn;
-
-            total_progress_hook_cnt++;
-            MPIU_Assert(total_progress_hook_cnt <= MAX_PROGRESS_HOOKS);
-
+        if (progress_hooks[i].func_ptr == NULL) {
+            progress_hooks[i].func_ptr = progress_fn;
+            progress_hooks[i].active = FALSE;
             break;
         }
     }
@@ -79,16 +82,71 @@ int MPIDI_Progress_deregister_hook(int id)
     MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_PROGRESS_DEREGISTER_HOOK);
     MPIU_THREAD_CS_ENTER(ASYNC,);
 
-    MPIU_Assert(id >= 0 && id < MAX_PROGRESS_HOOKS && progress_hooks[id] != NULL);
+    MPIU_Assert(id >= 0 && id < MAX_PROGRESS_HOOKS && progress_hooks[id].func_ptr != NULL);
+
+    progress_hooks[id].func_ptr = NULL;
+    progress_hooks[id].active = FALSE;
+
+  fn_exit:
+    MPIU_THREAD_CS_EXIT(ASYNC,);
+    MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_PROGRESS_DEREGISTER_HOOK);
+    return mpi_errno;
+
+  fn_fail:
+    goto fn_exit;
+}
+
+#undef FUNCNAME
+#define FUNCNAME MPIDI_CH3I_Progress_activate_hook
+#undef FCNAME
+#define FCNAME MPIU_QUOTE(FUNCNAME)
+int MPIDI_CH3I_Progress_activate_hook(int id)
+{
+    int mpi_errno = MPI_SUCCESS;
+    MPIDI_STATE_DECL(MPID_STATE_MPIDI_CH3I_PROGRESS_ACTIVATE_HOOK);
+
+    MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CH3I_PROGRESS_ACTIVATE_HOOK);
+    MPIU_THREAD_CS_ENTER(MPIDCOMM,);
+
+    MPIU_Assert(id >= 0 && id < MAX_PROGRESS_HOOKS &&
+                progress_hooks[id].active == FALSE && progress_hooks[id].func_ptr != NULL);
+    progress_hooks[id].active = TRUE;
 
-    progress_hooks[id] = NULL;
+    total_progress_hook_cnt++;
+    MPIU_Assert(total_progress_hook_cnt <= MAX_PROGRESS_HOOKS);
+
+  fn_exit:
+    MPIU_THREAD_CS_EXIT(MPIDCOMM,);
+    MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3I_PROGRESS_ACTIVATE_HOOK);
+    return mpi_errno;
+
+  fn_fail:
+    goto fn_exit;
+}
+
+
+#undef FUNCNAME
+#define FUNCNAME MPIDI_CH3I_Progress_deactivate_hook
+#undef FCNAME
+#define FCNAME MPIU_QUOTE(FUNCNAME)
+int MPIDI_CH3I_Progress_deactivate_hook(int id)
+{
+    int mpi_errno = MPI_SUCCESS;
+    MPIDI_STATE_DECL(MPID_STATE_MPIDI_CH3I_PROGRESS_DEACTIVATE_HOOK);
+
+    MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CH3I_PROGRESS_DEACTIVATE_HOOK);
+    MPIU_THREAD_CS_ENTER(MPIDCOMM,);
+
+    MPIU_Assert(id >= 0 && id < MAX_PROGRESS_HOOKS &&
+                progress_hooks[id].active == TRUE && progress_hooks[id].func_ptr != NULL);
+    progress_hooks[id].active = FALSE;
 
     total_progress_hook_cnt--;
     MPIU_Assert(total_progress_hook_cnt >= 0);
 
   fn_exit:
-    MPIU_THREAD_CS_EXIT(ASYNC,);
-    MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_PROGRESS_DEREGISTER_HOOK);
+    MPIU_THREAD_CS_EXIT(MPIDCOMM,);
+    MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3I_PROGRESS_DEACTIVATE_HOOK);
     return mpi_errno;
 
   fn_fail:
@@ -106,6 +164,7 @@ MPIDI_Progress_init()
    * function is ignored if async progress is disabled.
    */
   pamix_progress_function progress_fn = MPIDI_Progress_async_poll;
+  uintptr_t i;
 
 #if (MPIU_THREAD_GRANULARITY == MPIU_THREAD_GRANULARITY_PER_OBJECT)
   /* In the "per object" mpich lock mode the only possible progress functions
@@ -145,7 +204,6 @@ MPIDI_Progress_init()
       TRACE_ERR("Async advance beginning...\n");
 
       /* Enable async progress on all contexts.*/
-      uintptr_t i;
       for (i=0; i<MPIDI_Process.avail_contexts; ++i)
         {
           PAMIX_Progress_register(MPIDI_Context[i],
@@ -157,6 +215,13 @@ MPIDI_Progress_init()
         }
       TRACE_ERR("Async advance enabled\n");
     }
+
+  /* Initialize progress hook slots */
+  for (i = 0; i < MAX_PROGRESS_HOOKS; i++)
+    {
+      progress_hooks[i].func_ptr = NULL;
+      progress_hooks[i].active = FALSE;
+    }
 }
 
 void
@@ -241,8 +306,9 @@ MPIDI_Progress_async_poll (pami_context_t context, void *cookie)
     {
       called_progress_hook_cnt = 0;
       for (i = 0; i < MAX_PROGRESS_HOOKS; i++) {
-        if (progress_hooks[i] != NULL) {
-          progress_hooks[i](&made_progress);
+        if (progress_hooks[i].active == TRUE) {
+          MPIU_Assert(progress_hooks[i].func_ptr != NULL);
+          progress_hooks[i].func_ptr(&made_progress);
 
           called_progress_hook_cnt++;
           if (called_progress_hook_cnt == total_progress_hook_cnt)
@@ -277,8 +343,9 @@ MPIDI_Progress_async_poll_perobj (pami_context_t context, void *cookie)
   int called_progress_hook_cnt = 0;
 
   for (i = 0; i < MAX_PROGRESS_HOOKS; i++) {
-    if (progress_hooks[i] != NULL) {
-      progress_hooks[i](&made_progress);
+    if (progress_hooks[i].active == TRUE) {
+      MPIU_Assert(progress_hooks[i].func_ptr != NULL);
+      progress_hooks[i].func_ptr(&made_progress);
 
       called_progress_hook_cnt++;
       if (called_progress_hook_cnt == total_progress_hook_cnt)

http://git.mpich.org/mpich.git/commitdiff/70b0e0d7ccee74aaff912c99419476bec14e2e82

commit 70b0e0d7ccee74aaff912c99419476bec14e2e82
Author: Xin Zhao <xinzhao3 at illinois.edu>
Date:   Tue Aug 11 14:11:13 2015 -0500

    Move RMA progress_register/de-register_hook to Win_init/free.
    
    Signed-off-by: Pavan Balaji <balaji at anl.gov>

diff --git a/src/mpid/ch3/include/mpid_rma_oplist.h b/src/mpid/ch3/include/mpid_rma_oplist.h
index 6e32af3..9843824 100644
--- a/src/mpid/ch3/include/mpid_rma_oplist.h
+++ b/src/mpid/ch3/include/mpid_rma_oplist.h
@@ -109,8 +109,6 @@ MPIR_T_PVAR_DOUBLE_TIMER_DECL_EXTERN(RMA, rma_rmaqueue_alloc);
      &(win_ptr_)->slots[(rank_) % (win_ptr_)->num_slots] :              \
      &(win_ptr_)->slots[(rank_)])
 
-static int rma_progress_hook_id = 0;
-
 #undef FUNCNAME
 #define FUNCNAME MPIDI_CH3I_Win_set_active
 #undef FCNAME
@@ -122,15 +120,6 @@ static inline int MPIDI_CH3I_Win_set_active(MPID_Win * win_ptr)
     if (win_ptr->active == FALSE) {
         win_ptr->active = TRUE;
 
-        /* If this is the first active window, register RMA progress */
-        if (MPIDI_RMA_Win_active_list_head == NULL) {
-            mpi_errno = MPID_Progress_register_hook(MPIDI_CH3I_RMA_Make_progress_global,
-                                                    &rma_progress_hook_id);
-            if (mpi_errno) {
-                MPIU_ERR_POP(mpi_errno);
-            }
-        }
-
         MPL_DL_DELETE(MPIDI_RMA_Win_inactive_list_head, win_ptr);
         MPL_DL_APPEND(MPIDI_RMA_Win_active_list_head, win_ptr);
     }
@@ -154,14 +143,6 @@ static inline int MPIDI_CH3I_Win_set_inactive(MPID_Win * win_ptr)
         win_ptr->active = FALSE;
         MPL_DL_DELETE(MPIDI_RMA_Win_active_list_head, win_ptr);
         MPL_DL_APPEND(MPIDI_RMA_Win_inactive_list_head, win_ptr);
-
-        /* This is the last active window, de-register RMA progress */
-        if (MPIDI_RMA_Win_active_list_head == NULL) {
-            mpi_errno = MPID_Progress_deregister_hook(rma_progress_hook_id);
-            if (mpi_errno != MPI_SUCCESS) {
-                MPIU_ERR_POP(mpi_errno);
-            }
-        }
     }
 
   fn_exit:
diff --git a/src/mpid/ch3/include/mpidpre.h b/src/mpid/ch3/include/mpidpre.h
index 81ca4b4..19df355 100644
--- a/src/mpid/ch3/include/mpidpre.h
+++ b/src/mpid/ch3/include/mpidpre.h
@@ -352,6 +352,7 @@ typedef struct MPIDI_Win_basic_info {
 extern struct MPID_Win *MPIDI_RMA_Win_active_list_head, *MPIDI_RMA_Win_inactive_list_head;
 
 extern int MPIDI_CH3I_RMA_Active_req_cnt;
+extern int MPIDI_CH3I_RMA_Progress_hook_id;
 
 #ifdef MPIDI_CH3_WIN_DECL
 #define MPID_DEV_WIN_DECL \
diff --git a/src/mpid/ch3/src/mpid_rma.c b/src/mpid/ch3/src/mpid_rma.c
index e3c0e54..e12b81f 100644
--- a/src/mpid/ch3/src/mpid_rma.c
+++ b/src/mpid/ch3/src/mpid_rma.c
@@ -48,6 +48,9 @@ MPID_Win *MPIDI_RMA_Win_active_list_head = NULL, *MPIDI_RMA_Win_inactive_list_he
  * internal requests in RMA infrastructure. */
 int MPIDI_CH3I_RMA_Active_req_cnt = 0;
 
+/* This variable stores the index of RMA progress hook in progress hook array */
+int MPIDI_CH3I_RMA_Progress_hook_id = 0;
+
 static int win_init(MPI_Aint size, int disp_unit, int create_flavor, int model, MPID_Info * info,
                     MPID_Comm * comm_ptr, MPID_Win ** win_ptr);
 
@@ -357,6 +360,15 @@ static int win_init(MPI_Aint size, int disp_unit, int create_flavor, int model,
                       &((*win_ptr)->target_lock_entry_pool_start[i]));
     }
 
+    if (MPIDI_RMA_Win_inactive_list_head == NULL && MPIDI_RMA_Win_active_list_head == NULL) {
+        /* this is the first window, register RMA progress hook */
+        mpi_errno = MPID_Progress_register_hook(MPIDI_CH3I_RMA_Make_progress_global,
+                                                &MPIDI_CH3I_RMA_Progress_hook_id);
+        if (mpi_errno) {
+            MPIU_ERR_POP(mpi_errno);
+        }
+    }
+
     MPL_DL_APPEND(MPIDI_RMA_Win_inactive_list_head, (*win_ptr));
 
     if (MPIDI_CH3U_Win_hooks.win_init != NULL) {
diff --git a/src/mpid/ch3/src/mpidi_rma.c b/src/mpid/ch3/src/mpidi_rma.c
index 495d5b3..a114c3c 100644
--- a/src/mpid/ch3/src/mpidi_rma.c
+++ b/src/mpid/ch3/src/mpidi_rma.c
@@ -193,6 +193,14 @@ int MPID_Win_free(MPID_Win ** win_ptr)
     MPIU_Assert((*win_ptr)->active == FALSE);
     MPL_DL_DELETE(MPIDI_RMA_Win_inactive_list_head, (*win_ptr));
 
+    if (MPIDI_RMA_Win_inactive_list_head == NULL && MPIDI_RMA_Win_inactive_list_head == NULL) {
+        /* this is the last window, de-register RMA progress hook */
+        mpi_errno = MPID_Progress_deregister_hook(MPIDI_CH3I_RMA_Progress_hook_id);
+        if (mpi_errno != MPI_SUCCESS) {
+            MPIU_ERR_POP(mpi_errno);
+        }
+    }
+
     comm_ptr = (*win_ptr)->comm_ptr;
     mpi_errno = MPIR_Comm_free_impl(comm_ptr);
     if (mpi_errno)

http://git.mpich.org/mpich.git/commitdiff/688f9f9e24b042cff5de99904325a384d8e46c1d

commit 688f9f9e24b042cff5de99904325a384d8e46c1d
Author: Xin Zhao <xinzhao3 at illinois.edu>
Date:   Tue Aug 11 12:45:09 2015 -0500

    Modify Proress_register/deregister_hook to return/pass id argument.
    
    By doing this, we can use the id to activate/de-activate each
    progress hook by O(1) operation, avoid going over the entire
    progress hook slots everytime.
    
    Signed-off-by: Pavan Balaji <balaji at anl.gov>

diff --git a/src/mpid/ch3/channels/nemesis/include/mpidi_ch3_impl.h b/src/mpid/ch3/channels/nemesis/include/mpidi_ch3_impl.h
index c00133e..a3b4d81 100644
--- a/src/mpid/ch3/channels/nemesis/include/mpidi_ch3_impl.h
+++ b/src/mpid/ch3/channels/nemesis/include/mpidi_ch3_impl.h
@@ -50,8 +50,8 @@ extern struct MPID_Request *MPIDI_CH3I_shm_active_send;
 int MPIDI_CH3I_Shm_supported(void);
 int MPIDI_CH3I_Progress_init(void);
 int MPIDI_CH3I_Progress_finalize(void);
-int MPIDI_CH3I_Progress_register_hook(int (*progress_fn)(int*));
-int MPIDI_CH3I_Progress_deregister_hook(int (*progress_fn)(int*));
+int MPIDI_CH3I_Progress_register_hook(int (*progress_fn)(int*), int *id);
+int MPIDI_CH3I_Progress_deregister_hook(int id);
 int MPIDI_CH3I_Shm_send_progress(void);
 int MPIDI_CH3I_Complete_sendq_with_error(MPIDI_VC_t * vc);
 
diff --git a/src/mpid/ch3/channels/nemesis/src/ch3_progress.c b/src/mpid/ch3/channels/nemesis/src/ch3_progress.c
index 380fd45..8ece505 100644
--- a/src/mpid/ch3/channels/nemesis/src/ch3_progress.c
+++ b/src/mpid/ch3/channels/nemesis/src/ch3_progress.c
@@ -291,7 +291,7 @@ int MPIDI_CH3I_Shm_send_progress(void)
 #define FUNCNAME MPIDI_CH3I_Progress_register_hook
 #undef FCNAME
 #define FCNAME MPIU_QUOTE(FUNCNAME)
-int MPIDI_CH3I_Progress_register_hook(int (*progress_fn)(int*))
+int MPIDI_CH3I_Progress_register_hook(int (*progress_fn)(int*), int *id)
 {
     int mpi_errno = MPI_SUCCESS;
     int i;
@@ -317,6 +317,8 @@ int MPIDI_CH3I_Progress_register_hook(int (*progress_fn)(int*))
 				     MPI_ERR_INTERN, "**progresshookstoomany", 0 );
     }
 
+    (*id) = i;
+
   fn_exit:
     MPIU_THREAD_CS_EXIT(MPIDCOMM,);
     MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3I_PROGRESS_REGISTER_HOOK);
@@ -330,25 +332,20 @@ int MPIDI_CH3I_Progress_register_hook(int (*progress_fn)(int*))
 #define FUNCNAME MPIDI_CH3I_Progress_deregister_hook
 #undef FCNAME
 #define FCNAME MPIU_QUOTE(FUNCNAME)
-int MPIDI_CH3I_Progress_deregister_hook(int (*progress_fn)(int*))
+int MPIDI_CH3I_Progress_deregister_hook(int id)
 {
     int mpi_errno = MPI_SUCCESS;
-    int i;
     MPIDI_STATE_DECL(MPID_STATE_MPIDI_CH3I_PROGRESS_DEREGISTER_HOOK);
 
     MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CH3I_PROGRESS_DEREGISTER_HOOK);
     MPIU_THREAD_CS_ENTER(MPIDCOMM,);
 
-    for (i = 0; i < MAX_PROGRESS_HOOKS; i++) {
-        if (progress_hooks[i] == progress_fn) {
-            progress_hooks[i] = NULL;
+    MPIU_Assert(id >= 0 && id < MAX_PROGRESS_HOOKS && progress_hooks[id] != NULL);
 
-            total_progress_hook_cnt--;
-            MPIU_Assert(total_progress_hook_cnt >= 0);
+    progress_hooks[id] = NULL;
 
-            break;
-        }
-    }
+    total_progress_hook_cnt--;
+    MPIU_Assert(total_progress_hook_cnt >= 0);
 
   fn_exit:
     MPIU_THREAD_CS_EXIT(MPIDCOMM,);
diff --git a/src/mpid/ch3/channels/sock/include/mpidi_ch3_impl.h b/src/mpid/ch3/channels/sock/include/mpidi_ch3_impl.h
index f1bc05d..be1783a 100644
--- a/src/mpid/ch3/channels/sock/include/mpidi_ch3_impl.h
+++ b/src/mpid/ch3/channels/sock/include/mpidi_ch3_impl.h
@@ -72,8 +72,8 @@
    channel interface */
 int MPIDI_CH3I_Progress_init(void);
 int MPIDI_CH3I_Progress_finalize(void);
-int MPIDI_CH3I_Progress_register_hook(int (*progress_fn)(int*));
-int MPIDI_CH3I_Progress_deregister_hook(int (*progress_fn)(int*));
+int MPIDI_CH3I_Progress_register_hook(int (*progress_fn)(int*), int *id);
+int MPIDI_CH3I_Progress_deregister_hook(int id);
 int MPIDI_CH3I_VC_post_connect(MPIDI_VC_t *);
 
 /* Shared memory window atomic/accumulate mutex implementation */
diff --git a/src/mpid/ch3/channels/sock/src/ch3_progress.c b/src/mpid/ch3/channels/sock/src/ch3_progress.c
index 230620a..154eb9c 100644
--- a/src/mpid/ch3/channels/sock/src/ch3_progress.c
+++ b/src/mpid/ch3/channels/sock/src/ch3_progress.c
@@ -967,7 +967,7 @@ int MPIDI_CH3I_Progress( int blocking, MPID_Progress_state *state )
 #define FUNCNAME MPIDI_CH3I_Progress_register_hook
 #undef FCNAME
 #define FCNAME MPIU_QUOTE(FUNCNAME)
-int MPIDI_CH3I_Progress_register_hook(int (*progress_fn)(int*))
+int MPIDI_CH3I_Progress_register_hook(int (*progress_fn)(int*), int *id)
 {
     int mpi_errno = MPI_SUCCESS;
     int i;
@@ -993,6 +993,8 @@ int MPIDI_CH3I_Progress_register_hook(int (*progress_fn)(int*))
 				     MPI_ERR_INTERN, "**progresshookstoomany", 0 );
     }
 
+    (*id) = i;
+
   fn_exit:
     MPIU_THREAD_CS_EXIT(MPIDCOMM,);
     MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3I_PROGRESS_REGISTER_HOOK);
@@ -1006,25 +1008,20 @@ int MPIDI_CH3I_Progress_register_hook(int (*progress_fn)(int*))
 #define FUNCNAME MPIDI_CH3I_Progress_deregister_hook
 #undef FCNAME
 #define FCNAME MPIU_QUOTE(FUNCNAME)
-int MPIDI_CH3I_Progress_deregister_hook(int (*progress_fn)(int*))
+int MPIDI_CH3I_Progress_deregister_hook(int id)
 {
     int mpi_errno = MPI_SUCCESS;
-    int i;
     MPIDI_STATE_DECL(MPID_STATE_MPIDI_CH3I_PROGRESS_DEREGISTER_HOOK);
 
     MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CH3I_PROGRESS_DEREGISTER_HOOK);
     MPIU_THREAD_CS_ENTER(MPIDCOMM,);
 
-    for (i = 0; i < MAX_PROGRESS_HOOKS; i++) {
-        if (progress_hooks[i] == progress_fn) {
-            progress_hooks[i] = NULL;
+    MPIU_Assert(id >= 0 && id < MAX_PROGRESS_HOOKS && progress_hooks[id] != NULL);
 
-            total_progress_hook_cnt--;
-            MPIU_Assert(total_progress_hook_cnt >= 0);
+    progress_hooks[id] = NULL;
 
-            break;
-        }
-    }
+    total_progress_hook_cnt--;
+    MPIU_Assert(total_progress_hook_cnt >= 0);
 
   fn_exit:
     MPIU_THREAD_CS_EXIT(MPIDCOMM,);
diff --git a/src/mpid/ch3/include/mpid_rma_oplist.h b/src/mpid/ch3/include/mpid_rma_oplist.h
index bc598ea..6e32af3 100644
--- a/src/mpid/ch3/include/mpid_rma_oplist.h
+++ b/src/mpid/ch3/include/mpid_rma_oplist.h
@@ -109,6 +109,7 @@ MPIR_T_PVAR_DOUBLE_TIMER_DECL_EXTERN(RMA, rma_rmaqueue_alloc);
      &(win_ptr_)->slots[(rank_) % (win_ptr_)->num_slots] :              \
      &(win_ptr_)->slots[(rank_)])
 
+static int rma_progress_hook_id = 0;
 
 #undef FUNCNAME
 #define FUNCNAME MPIDI_CH3I_Win_set_active
@@ -123,7 +124,8 @@ static inline int MPIDI_CH3I_Win_set_active(MPID_Win * win_ptr)
 
         /* If this is the first active window, register RMA progress */
         if (MPIDI_RMA_Win_active_list_head == NULL) {
-            mpi_errno = MPID_Progress_register_hook(MPIDI_CH3I_RMA_Make_progress_global);
+            mpi_errno = MPID_Progress_register_hook(MPIDI_CH3I_RMA_Make_progress_global,
+                                                    &rma_progress_hook_id);
             if (mpi_errno) {
                 MPIU_ERR_POP(mpi_errno);
             }
@@ -155,7 +157,7 @@ static inline int MPIDI_CH3I_Win_set_inactive(MPID_Win * win_ptr)
 
         /* This is the last active window, de-register RMA progress */
         if (MPIDI_RMA_Win_active_list_head == NULL) {
-            mpi_errno = MPID_Progress_deregister_hook(MPIDI_CH3I_RMA_Make_progress_global);
+            mpi_errno = MPID_Progress_deregister_hook(rma_progress_hook_id);
             if (mpi_errno != MPI_SUCCESS) {
                 MPIU_ERR_POP(mpi_errno);
             }
diff --git a/src/mpid/ch3/include/mpidimpl.h b/src/mpid/ch3/include/mpidimpl.h
index 06cb0e4..1d238e3 100644
--- a/src/mpid/ch3/include/mpidimpl.h
+++ b/src/mpid/ch3/include/mpidimpl.h
@@ -1938,10 +1938,10 @@ int MPIDI_CH3_Req_handler_rma_op_complete(MPID_Request *);
     } while (0)
 
 
-int MPIDI_CH3I_Progress_register_hook(int (*progress_fn)(int*));
-int MPIDI_CH3I_Progress_deregister_hook(int (*progress_fn)(int*));
+int MPIDI_CH3I_Progress_register_hook(int (*progress_fn)(int*), int *id);
+int MPIDI_CH3I_Progress_deregister_hook(int id);
 
-#define MPID_Progress_register_hook(fn_) MPIDI_CH3I_Progress_register_hook(fn_)
-#define MPID_Progress_deregister_hook(fn_) MPIDI_CH3I_Progress_deregister_hook(fn_)
+#define MPID_Progress_register_hook(fn_, id_) MPIDI_CH3I_Progress_register_hook(fn_, id_)
+#define MPID_Progress_deregister_hook(id_) MPIDI_CH3I_Progress_deregister_hook(id_)
 
 #endif /* !defined(MPICH_MPIDIMPL_H_INCLUDED) */
diff --git a/src/mpid/common/hcoll/hcoll_init.c b/src/mpid/common/hcoll/hcoll_init.c
index ee1a364..23f9680 100644
--- a/src/mpid/common/hcoll/hcoll_init.c
+++ b/src/mpid/common/hcoll/hcoll_init.c
@@ -2,6 +2,8 @@
 
 static int hcoll_initialized = 0;
 static int hcoll_comm_world_initialized = 0;
+static int hcoll_progress_hook_id = 0;
+
 int hcoll_enable = 1;
 int hcoll_enable_barrier = 1;
 int hcoll_enable_bcast = 1;
@@ -23,7 +25,7 @@ int hcoll_destroy(void *param ATTRIBUTE((unused)))
 {
     if (1 == hcoll_initialized) {
         hcoll_finalize();
-        MPID_Progress_deregister_hook(hcoll_do_progress);
+        MPID_Progress_deregister_hook(hcoll_progress_hook_id);
     }
     hcoll_initialized = 0;
     return 0;
@@ -82,7 +84,8 @@ int hcoll_initialize(void)
 
     if (!hcoll_initialized) {
         hcoll_initialized = 1;
-        mpi_errno = MPID_Progress_register_hook(hcoll_do_progress);
+        mpi_errno = MPID_Progress_register_hook(hcoll_do_progress,
+                                                &hcoll_progress_hook_id);
         if (mpi_errno) MPIU_ERR_POP(mpi_errno);
     }
     MPIR_Add_finalize(hcoll_destroy, 0, 0);
diff --git a/src/mpid/common/sched/mpid_sched.c b/src/mpid/common/sched/mpid_sched.c
index a6e7037..8098d37 100644
--- a/src/mpid/common/sched/mpid_sched.c
+++ b/src/mpid/common/sched/mpid_sched.c
@@ -54,6 +54,8 @@ struct MPIDU_Sched_state {
 /* holds on to all incomplete schedules on which progress should be made */
 struct MPIDU_Sched_state all_schedules = {NULL};
 
+static int nbc_progress_hook_id = 0;
+
 /* returns TRUE if any schedules are currently pending completion by the
  * progress engine, FALSE otherwise */
 #undef FUNCNAME
@@ -410,7 +412,8 @@ int MPID_Sched_start(MPID_Sched_t *sp, MPID_Comm *comm, int tag, MPID_Request **
     /* finally, enqueue in the list of all pending schedules so that the
      * progress engine can make progress on it */
     if (all_schedules.head == NULL) {
-        mpi_errno = MPID_Progress_register_hook(MPIDU_Sched_progress);
+        mpi_errno = MPID_Progress_register_hook(MPIDU_Sched_progress,
+                                                &nbc_progress_hook_id);
         if (mpi_errno) MPIU_ERR_POP(mpi_errno);
     }
     MPL_DL_APPEND(all_schedules.head, s);
@@ -942,7 +945,7 @@ int MPIDU_Sched_progress(int *made_progress)
 
     mpi_errno = MPIDU_Sched_progress_state(&all_schedules, made_progress);
     if (!mpi_errno && all_schedules.head == NULL)
-        MPID_Progress_deregister_hook(MPIDU_Sched_progress);
+        MPID_Progress_deregister_hook(nbc_progress_hook_id);
 
     return mpi_errno;
 }
diff --git a/src/mpid/pamid/include/mpidimpl.h b/src/mpid/pamid/include/mpidimpl.h
index fabc9d4..3a9e78c 100644
--- a/src/mpid/pamid/include/mpidimpl.h
+++ b/src/mpid/pamid/include/mpidimpl.h
@@ -185,9 +185,9 @@ MPIDI_Win_set_info(MPID_Win *win,
 MPI_Aint MPID_Aint_add(MPI_Aint base, MPI_Aint disp);
 MPI_Aint MPID_Aint_diff(MPI_Aint addr1, MPI_Aint addr2);
 
-int MPIDI_Progress_register_hook(int (*progress_fn)(int*));
-int MPIDI_Progress_deregister_hook(int (*progress_fn)(int*));
+int MPIDI_Progress_register_hook(int (*progress_fn)(int*), int *id);
+int MPIDI_Progress_deregister_hook(int id);
 
-#define MPID_Progress_register_hook(fn_) MPIDI_Progress_register_hook(fn_)
-#define MPID_Progress_deregister_hook(fn_) MPIDI_Progress_deregister_hook(fn_)
+#define MPID_Progress_register_hook(fn_, id_) MPIDI_Progress_register_hook(fn_, id_)
+#define MPID_Progress_deregister_hook(id_) MPIDI_Progress_deregister_hook(id_)
 #endif
diff --git a/src/mpid/pamid/src/mpid_progress.c b/src/mpid/pamid/src/mpid_progress.c
index 07111a3..f470563 100644
--- a/src/mpid/pamid/src/mpid_progress.c
+++ b/src/mpid/pamid/src/mpid_progress.c
@@ -30,7 +30,7 @@ static int total_progress_hook_cnt = 0; /* Keep track of how many progress hooks
 #define FUNCNAME MPIDI_Progress_register_hook
 #undef FCNAME
 #define FCNAME MPIU_QUOTE(FUNCNAME)
-int MPIDI_Progress_register_hook(int (*progress_fn)(int*))
+int MPIDI_Progress_register_hook(int (*progress_fn)(int*), int *id)
 {
     int mpi_errno = MPI_SUCCESS;
     int i;
@@ -56,6 +56,8 @@ int MPIDI_Progress_register_hook(int (*progress_fn)(int*))
             MPI_ERR_INTERN, "**progresshookstoomany", 0 );
     }
 
+    (*id) = i;
+
   fn_exit:
     MPIU_THREAD_CS_EXIT(ASYNC,);
     MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_PROGRESS_REGISTER_HOOK);
@@ -69,25 +71,20 @@ int MPIDI_Progress_register_hook(int (*progress_fn)(int*))
 #define FUNCNAME MPIDI_Progress_deregister_hook
 #undef FCNAME
 #define FCNAME MPIU_QUOTE(FUNCNAME)
-int MPIDI_Progress_deregister_hook(int (*progress_fn)(int*))
+int MPIDI_Progress_deregister_hook(int id)
 {
     int mpi_errno = MPI_SUCCESS;
-    int i;
     MPIDI_STATE_DECL(MPID_STATE_MPIDI_PROGRESS_DEREGISTER_HOOK);
 
     MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_PROGRESS_DEREGISTER_HOOK);
     MPIU_THREAD_CS_ENTER(ASYNC,);
 
-    for (i = 0; i < MAX_PROGRESS_HOOKS; i++) {
-        if (progress_hooks[i] == progress_fn) {
-            progress_hooks[i] = NULL;
+    MPIU_Assert(id >= 0 && id < MAX_PROGRESS_HOOKS && progress_hooks[id] != NULL);
 
-            total_progress_hook_cnt--;
-            MPIU_Assert(total_progress_hook_cnt >= 0);
+    progress_hooks[id] = NULL;
 
-            break;
-        }
-    }
+    total_progress_hook_cnt--;
+    MPIU_Assert(total_progress_hook_cnt >= 0);
 
   fn_exit:
     MPIU_THREAD_CS_EXIT(ASYNC,);

http://git.mpich.org/mpich.git/commitdiff/98d4b47ab463e3371c372e6621a72ca244d547bf

commit 98d4b47ab463e3371c372e6621a72ca244d547bf
Author: Xin Zhao <xinzhao3 at illinois.edu>
Date:   Tue Aug 11 10:41:02 2015 -0500

    Add missed optimization for sock and pamid.
    
    In 4551de14b1d752a9c7be49df4a9e70776addd02f, we added a counter
    in nemesis to keep track of how many progress hooks are currently
    registered. Here we do the same optimizaton for sock and pamid.
    
    Signed-off-by: Pavan Balaji <balaji at anl.gov>

diff --git a/src/mpid/ch3/channels/sock/src/ch3_progress.c b/src/mpid/ch3/channels/sock/src/ch3_progress.c
index ded4e10..230620a 100644
--- a/src/mpid/ch3/channels/sock/src/ch3_progress.c
+++ b/src/mpid/ch3/channels/sock/src/ch3_progress.c
@@ -48,6 +48,7 @@ static int adjust_iov(MPID_IOV ** iovp, int * countp, MPIU_Size_t nb);
 #define MAX_PROGRESS_HOOKS 16
 typedef int (*progress_func_ptr_t) (int* made_progress);
 static progress_func_ptr_t progress_hooks[MAX_PROGRESS_HOOKS] = { NULL };
+static int total_progress_hook_cnt = 0; /* Keep track of how many progress hooks are currently registered */
 
 #undef FUNCNAME
 #define FUNCNAME MPIDI_CH3i_Progress_test
@@ -59,6 +60,7 @@ static int MPIDI_CH3i_Progress_test(void)
     int mpi_errno = MPI_SUCCESS;
     int made_progress;
     int i;
+    int called_progress_hook_cnt;
     MPIDI_STATE_DECL(MPID_STATE_MPIDI_CH3I_PROGRESS_TEST);
 
     MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CH3I_PROGRESS_TEST);
@@ -90,10 +92,15 @@ static int MPIDI_CH3i_Progress_test(void)
     }
 #   endif
     
+    called_progress_hook_cnt = 0;
     for (i = 0; i < MAX_PROGRESS_HOOKS; i++) {
         if (progress_hooks[i] != NULL) {
             mpi_errno = progress_hooks[i](&made_progress);
             if (mpi_errno) MPIU_ERR_POP(mpi_errno);
+
+            called_progress_hook_cnt++;
+            if (called_progress_hook_cnt == total_progress_hook_cnt)
+                break;
         }
     }
 
@@ -185,7 +192,9 @@ static int MPIDI_CH3i_Progress_wait(MPID_Progress_state * progress_state)
     {
         int made_progress = FALSE;
         int i;
+        int called_progress_hook_cnt;
 
+        called_progress_hook_cnt = 0;
         for (i = 0; i < MAX_PROGRESS_HOOKS; i++) {
             if (progress_hooks[i] != NULL) {
                 mpi_errno = progress_hooks[i](&made_progress);
@@ -194,6 +203,10 @@ static int MPIDI_CH3i_Progress_wait(MPID_Progress_state * progress_state)
                     MPIDI_CH3_Progress_signal_completion();
                     break; /* break the for loop */
                 }
+
+                called_progress_hook_cnt++;
+                if (called_progress_hook_cnt == total_progress_hook_cnt)
+                    break;
             }
         }
         if (made_progress) break; /* break the do loop */
@@ -966,6 +979,10 @@ int MPIDI_CH3I_Progress_register_hook(int (*progress_fn)(int*))
     for (i = 0; i < MAX_PROGRESS_HOOKS; i++) {
         if (progress_hooks[i] == NULL) {
             progress_hooks[i] = progress_fn;
+
+            total_progress_hook_cnt++;
+            MPIU_Assert(total_progress_hook_cnt <= MAX_PROGRESS_HOOKS);
+
             break;
         }
     }
@@ -1001,6 +1018,10 @@ int MPIDI_CH3I_Progress_deregister_hook(int (*progress_fn)(int*))
     for (i = 0; i < MAX_PROGRESS_HOOKS; i++) {
         if (progress_hooks[i] == progress_fn) {
             progress_hooks[i] = NULL;
+
+            total_progress_hook_cnt--;
+            MPIU_Assert(total_progress_hook_cnt >= 0);
+
             break;
         }
     }
diff --git a/src/mpid/pamid/src/mpid_progress.c b/src/mpid/pamid/src/mpid_progress.c
index f4294f7..07111a3 100644
--- a/src/mpid/pamid/src/mpid_progress.c
+++ b/src/mpid/pamid/src/mpid_progress.c
@@ -24,6 +24,7 @@
 #define MAX_PROGRESS_HOOKS 16
 typedef int (*progress_func_ptr_t) (int* made_progress);
 static progress_func_ptr_t  progress_hooks[MAX_PROGRESS_HOOKS] = { NULL };
+static int total_progress_hook_cnt = 0; /* Keep track of how many progress hooks are currently registered */
 
 #undef FUNCNAME
 #define FUNCNAME MPIDI_Progress_register_hook
@@ -41,6 +42,10 @@ int MPIDI_Progress_register_hook(int (*progress_fn)(int*))
     for (i = 0; i < MAX_PROGRESS_HOOKS; i++) {
         if (progress_hooks[i] == NULL) {
             progress_hooks[i] = progress_fn;
+
+            total_progress_hook_cnt++;
+            MPIU_Assert(total_progress_hook_cnt <= MAX_PROGRESS_HOOKS);
+
             break;
         }
     }
@@ -76,6 +81,10 @@ int MPIDI_Progress_deregister_hook(int (*progress_fn)(int*))
     for (i = 0; i < MAX_PROGRESS_HOOKS; i++) {
         if (progress_hooks[i] == progress_fn) {
             progress_hooks[i] = NULL;
+
+            total_progress_hook_cnt--;
+            MPIU_Assert(total_progress_hook_cnt >= 0);
+
             break;
         }
     }
@@ -223,6 +232,7 @@ MPIDI_Progress_async_poll (pami_context_t context, void *cookie)
   pami_result_t rc;
   int loop_count=100;
   int i, made_progress;
+  int called_progress_hook_cnt;
 
   /* In the "global" mpich lock mode all application threads must acquire the
    * ALLFUNC global lock upon entry to the API. The async progress thread
@@ -232,9 +242,14 @@ MPIDI_Progress_async_poll (pami_context_t context, void *cookie)
    */
   if (MPIU_THREAD_CS_TRY(ALLFUNC,))           /* (0==try_acquire(0)) */
     {
+      called_progress_hook_cnt = 0;
       for (i = 0; i < MAX_PROGRESS_HOOKS; i++) {
         if (progress_hooks[i] != NULL) {
           progress_hooks[i](&made_progress);
+
+          called_progress_hook_cnt++;
+          if (called_progress_hook_cnt == total_progress_hook_cnt)
+            break;
         }
       }
 
@@ -262,10 +277,15 @@ MPIDI_Progress_async_poll_perobj (pami_context_t context, void *cookie)
   pami_result_t rc;
   int loop_count=100;
   int i, made_progress;
+  int called_progress_hook_cnt = 0;
 
   for (i = 0; i < MAX_PROGRESS_HOOKS; i++) {
     if (progress_hooks[i] != NULL) {
       progress_hooks[i](&made_progress);
+
+      called_progress_hook_cnt++;
+      if (called_progress_hook_cnt == total_progress_hook_cnt)
+        break;
     }
   }
 

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

Summary of changes:
 .../ch3/channels/nemesis/include/mpidi_ch3_impl.h  |    6 +-
 src/mpid/ch3/channels/nemesis/src/ch3_progress.c   |  108 ++++++++++++++----
 .../ch3/channels/sock/include/mpidi_ch3_impl.h     |    6 +-
 src/mpid/ch3/channels/sock/src/ch3_progress.c      |  117 +++++++++++++++++---
 src/mpid/ch3/include/mpid_rma_oplist.h             |   15 +--
 src/mpid/ch3/include/mpidimpl.h                    |   14 ++-
 src/mpid/ch3/include/mpidpre.h                     |    1 +
 src/mpid/ch3/src/mpid_rma.c                        |   12 ++
 src/mpid/ch3/src/mpidi_rma.c                       |    8 ++
 src/mpid/common/hcoll/hcoll_init.c                 |   10 ++-
 src/mpid/common/sched/mpid_sched.c                 |   13 ++-
 src/mpid/pamid/include/mpidimpl.h                  |   14 ++-
 src/mpid/pamid/src/mpid_progress.c                 |  118 +++++++++++++++++---
 13 files changed, 357 insertions(+), 85 deletions(-)


hooks/post-receive
-- 
MPICH primary repository


More information about the commits mailing list