[mpich-commits] [mpich] MPICH primary repository branch, master, updated. v3.0.1-81-gd3e1b75

mysql vizuser noreply at mpich.org
Fri Jan 25 18:33:28 CST 2013


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  d3e1b7542d877c438054b9e40e3719bc7d3b86c5 (commit)
       via  412672dbfcfa8dc2eac1192e474d04201644d0d1 (commit)
       via  44d08f8a49fa103d2db80f84e6e3ac6f4391b5c8 (commit)
       via  e56307ab731333a06b9aa6bb7ea060142eb7efff (commit)
       via  7f528a332290e730b397932779ffe571b20c4f5c (commit)
       via  a4d103b7ece57a6aae7bac77e58927177a3b2a49 (commit)
       via  46eacfc76cde82fa9f5bf16975de58a1c9798487 (commit)
       via  2cfb60178370094f4df8ba43e535f987ff405bb3 (commit)
       via  d6b69b468128c0c356db2d31e8fd4ca0414c3ea4 (commit)
      from  6a954d01628b1443336bee7e197d91d56690d8f6 (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/d3e1b7542d877c438054b9e40e3719bc7d3b86c5

commit d3e1b7542d877c438054b9e40e3719bc7d3b86c5
Merge: 6a954d0 412672d
Author: Dave Goodell <goodell at mcs.anl.gov>
Date:   Fri Jan 25 18:20:22 2013 -0600

    Merge branch 'nemesis-mpit'
    
    Adds Ralf's changes to nemesis that add MPI_T performance variables.  I left
    his commits mostly alone and added several cleanup commits on top of them.


http://git.mpich.org/mpich.git/commitdiff/412672dbfcfa8dc2eac1192e474d04201644d0d1

commit 412672dbfcfa8dc2eac1192e474d04201644d0d1
Author: Dave Goodell <goodell at mcs.anl.gov>
Date:   Tue Jan 22 18:15:39 2013 -0600

    always define stat vars
    
    This makes the stats code more robust to persnickety compilers that
    might not appreciate references to extern variables that don't really
    exist.
    
    Reviewed-by: rgunter

diff --git a/src/mpid/ch3/channels/nemesis/src/mpid_nem_init.c b/src/mpid/ch3/channels/nemesis/src/mpid_nem_init.c
index c8cbe64..19df691 100644
--- a/src/mpid/ch3/channels/nemesis/src/mpid_nem_init.c
+++ b/src/mpid/ch3/channels/nemesis/src/mpid_nem_init.c
@@ -37,13 +37,13 @@ static int get_local_procs(MPIDI_PG_t *pg, int our_pg_rank, int *num_local_p,
 
 char *MPID_nem_asymm_base_addr = 0;
 
+/* used by mpid_nem_inline.h and mpid_nem_finalize.c */
+uint64_t *MPID_nem_fbox_fall_back_to_queue_count = NULL;
+
 #if ENABLE_NEM_STATISTICS
 /* MPIT support */
 MPIR_T_SIMPLE_HANDLE_CREATOR(fbox_count_creator, uint64_t, MPID_nem_mem_region.num_local)
 
-/* used by mpid_nem_inline.h and mpid_nem_finalize.c */
-uint64_t *MPID_nem_fbox_fall_back_to_queue_count = NULL;
-
 #undef FUNCNAME
 #define FUNCNAME MPID_nem_init_stats
 #undef FCNAME
diff --git a/src/mpid/ch3/src/ch3u_recvq.c b/src/mpid/ch3/src/ch3u_recvq.c
index 01ce6bb..01e3dcb 100644
--- a/src/mpid/ch3/src/ch3u_recvq.c
+++ b/src/mpid/ch3/src/ch3u_recvq.c
@@ -59,7 +59,9 @@ MPID_Request ** const MPID_Recvq_posted_head_ptr     = &recvq_posted_head;
 MPID_Request ** const MPID_Recvq_unexpected_head_ptr = &recvq_unexpected_head;
 #endif
 
-#if ENABLE_RECVQ_STATISTICS
+/* Always define these, since our macros will always generate references to
+ * them.  Every compiler we have tested optimizes these "if(0){...}" code paths
+ * away, even at "-O0". */
 static unsigned int posted_qlen = 0;
 static unsigned int unexpected_qlen = 0;
 static MPI_Aint posted_recvq_match_attempts = 0;
@@ -67,15 +69,6 @@ static MPI_Aint unexpected_recvq_match_attempts = 0;
 static double time_failed_matching_postedq = 0.0;
 static double time_matching_unexpectedq = 0.0;
 uint64_t MPIDI_CH3I_unexpected_recvq_buffer_size = 0;    /* used in ch3u_eager.c and ch3u_handle_recv_pkt.c */
-#else 
-extern unsigned int posted_qlen;
-extern unsigned int unexpected_qlen;
-extern MPI_Aint posted_recvq_match_attempts;
-extern MPI_Aint unexpected_recvq_match_attempts;
-extern double time_failed_matching_postedq;
-extern double time_matching_unexpectedq;
-extern uint64_t MPIDI_CH3I_unexpected_recvq_buffer_size;
-#endif  /* ENABLE_RECVQ_STATISTICS */ 
 
 
 /* If the MPIDI_Message_match structure fits into a pointer size, we

http://git.mpich.org/mpich.git/commitdiff/44d08f8a49fa103d2db80f84e6e3ac6f4391b5c8

commit 44d08f8a49fa103d2db80f84e6e3ac6f4391b5c8
Author: Dave Goodell <goodell at mcs.anl.gov>
Date:   Tue Jan 22 17:51:35 2013 -0600

    fixups for new MPI_T tests
    
    Add the copyright header, limit printing to rank 0, and print a
    "finished" message to make it clearer that the test completed and didn't
    just crash.
    
    Reviewed-by: rgunter

diff --git a/test/mpi/manual/mpi_t/nem_fbox_fallback_to_queue_count.c b/test/mpi/manual/mpi_t/nem_fbox_fallback_to_queue_count.c
index 8fea096..f045212 100644
--- a/test/mpi/manual/mpi_t/nem_fbox_fallback_to_queue_count.c
+++ b/test/mpi/manual/mpi_t/nem_fbox_fallback_to_queue_count.c
@@ -1,3 +1,16 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2013 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+/* This test checks that the nemesis code correctly exposes statistics related
+ * to "fbox" handling.  It also attempts to verify that it accurately maintains
+ * these statistics.
+ *
+ * Originally written by Ralf Gunter Correa Carvalho. */
+
 #include <mpi.h>
 #include <assert.h>
 #include <string.h>
@@ -160,12 +173,15 @@ int main(int argc, char *argv[])
     MPI_Datatype dtype;
     MPI_T_enum enumtype;
 
-    printf("MPIT pvar test: nem_fbox_fall_back_to_queue_count\n"); fflush(stdout);
-
     MPI_Init(NULL, NULL);
     MPI_Comm_size(MPI_COMM_WORLD, &size);
     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
+    if (rank == 0) {
+        printf("MPIT pvar test: nem_fbox_fall_back_to_queue_count\n");
+        fflush(stdout);
+    }
+
     /* Ensure we're using exactly two ranks. */
     assert(size == 2);
 
@@ -203,6 +219,11 @@ int main(int argc, char *argv[])
     MPI_T_pvar_handle_free(session, &fbox_handle);
     MPI_T_pvar_session_free(&session);
 
+    if (rank == 0) {
+        printf("finished\n");
+        fflush(stdout);
+    }
+
     TRY(MPI_T_finalize());
     MPI_Finalize();
 
diff --git a/test/mpi/manual/mpi_t/unexpected_recvq_buffer_size.c b/test/mpi/manual/mpi_t/unexpected_recvq_buffer_size.c
index de896cc..4753e02 100644
--- a/test/mpi/manual/mpi_t/unexpected_recvq_buffer_size.c
+++ b/test/mpi/manual/mpi_t/unexpected_recvq_buffer_size.c
@@ -1,3 +1,15 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2013 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+/* This test checks that the nemesis code correctly exposes statistics related
+ * to unexpected receive queue buffer/message sizes.
+ *
+ * Originally written by Ralf Gunter Correa Carvalho. */
+
 #include <mpi.h>
 #include <assert.h>
 #include <string.h>
@@ -91,12 +103,15 @@ int main(int argc, char *argv[])
     MPI_Datatype dtype;
     MPI_T_enum enumtype;
 
-    printf("MPIT pvar test: unexpected_recvq_buffer_size\n"); fflush(stdout);
-
     MPI_Init(NULL, NULL);
     MPI_Comm_size(MPI_COMM_WORLD, &size);
     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
+    if (rank == 0) {
+        printf("MPIT pvar test: unexpected_recvq_buffer_size\n");
+        fflush(stdout);
+    }
+
     /* Ensure we're using exactly two ranks. */
     /* Future tests (using collectives) might need this because of the MPI_Barrier */
     assert(size == 2);
@@ -131,6 +146,11 @@ int main(int argc, char *argv[])
     MPI_T_pvar_handle_free(session, &uqsize_handle);
     MPI_T_pvar_session_free(&session);
 
+    if (rank == 0) {
+        printf("finished\n");
+        fflush(stdout);
+    }
+
     TRY(MPI_T_finalize());
     MPI_Finalize();
 

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

commit e56307ab731333a06b9aa6bb7ea060142eb7efff
Author: Dave Goodell <goodell at mcs.anl.gov>
Date:   Tue Jan 22 14:34:57 2013 -0600

    move new MPI_T tests to manual/mpi_t dir
    
    Reviewed-by: rgunter

diff --git a/test/mpi/configure.ac b/test/mpi/configure.ac
index dd403ba..f0da35b 100644
--- a/test/mpi/configure.ac
+++ b/test/mpi/configure.ac
@@ -1409,6 +1409,7 @@ AC_OUTPUT(maint/testmerge \
           errors/f90/Makefile \
           manual/Makefile \
           manual/manyconnect \
+          manual/mpi_t/Makefile \
           perf/Makefile \
           testlist \
           cxx/testlist \
diff --git a/test/mpi/manual/mpi_t/Makefile.am b/test/mpi/manual/mpi_t/Makefile.am
index 3f84934..24110f8 100644
--- a/test/mpi/manual/mpi_t/Makefile.am
+++ b/test/mpi/manual/mpi_t/Makefile.am
@@ -7,5 +7,9 @@
 
 include $(top_srcdir)/Makefile.mtest
 
-noinst_PROGRAMS = mpit_test mpit_test2
+# these tests are specific to the MPICH ch3:nemesis implementation of nemesis
+nemesis_tests = nem_fbox_fallback_to_queue_count \
+                unexpected_recvq_buffer_size
 
+noinst_PROGRAMS = mpit_test mpit_test2 \
+                  $(nemesis_tests)
diff --git a/test/mpi_t/nem_fbox_fallback_to_queue_count.c b/test/mpi/manual/mpi_t/nem_fbox_fallback_to_queue_count.c
similarity index 100%
rename from test/mpi_t/nem_fbox_fallback_to_queue_count.c
rename to test/mpi/manual/mpi_t/nem_fbox_fallback_to_queue_count.c
diff --git a/test/mpi_t/unexpected_recvq_buffer_size.c b/test/mpi/manual/mpi_t/unexpected_recvq_buffer_size.c
similarity index 100%
rename from test/mpi_t/unexpected_recvq_buffer_size.c
rename to test/mpi/manual/mpi_t/unexpected_recvq_buffer_size.c

http://git.mpich.org/mpich.git/commitdiff/7f528a332290e730b397932779ffe571b20c4f5c

commit 7f528a332290e730b397932779ffe571b20c4f5c
Author: Dave Goodell <goodell at mcs.anl.gov>
Date:   Tue Jan 22 17:20:06 2013 -0600

    fixup for new pvar build system code
    
    Reviewed-by: rgunter

diff --git a/configure.ac b/configure.ac
index d97df82..f17eb74 100644
--- a/configure.ac
+++ b/configure.ac
@@ -372,15 +372,15 @@ AC_ARG_ENABLE(g,
         all      - All of the above choices
 ],,enable_g=none)
 
-AC_ARG_ENABLE(mpit_pvars,
-[--enable-mpit-pvars=list - Selectively enable MPIT performance variables.
+AC_ARG_ENABLE([mpit_pvars],
+[--enable-mpit-pvars=list - Selectively enable MPI_T performance variables.
                          list is a comma-separated list of variable names,
                          including
         none     - No performance info recorded
         recvq    - All message queue-related
         nem      - All nemesis-related
         all      - All variables above
-],,enable_mpit_pvars=none)
+],[],[enable_mpit_pvars=all])
 
 dnl We may want to force MPI_Aint to be the same size as MPI_Offset, 
 dnl particularly on 32 bit systems with large (64 bit) file systems.
@@ -401,6 +401,7 @@ AC_ARG_ENABLE(fast,
         nochkmsg - No error checking, i.e. --disable-error-checking
         notiming - No timing collection, i.e. --disable-timing.
         ndebug   - Appends -DNDEBUG to MPICHLIB_CFLAGS.
+        nompit   - Equivalent to "--disable-mpit-pvars".
         all|yes  - "defopt", "nochkmsg", "notiming" and "ndebug" are enabled
                    when --enable-fast is specified without any option.
         none     - None of above options, i.e. --disable-fast. Note that
@@ -818,6 +819,9 @@ for option in $enable_fast ; do
         ndebug)
         enable_append_ndebug=yes
         ;;
+        nompit)
+        enable_mpit_pvars=no
+        ;;
 #
 # [BRT] removed the reseting of enable_g so that --with-enable=dbg,meminit
 # can be specified with -enable-fast.  This change was largely made for the
@@ -1726,32 +1730,23 @@ PAC_COMPILER_SHLIB_FLAGS([CC],[$cc_shlib_conf])
 AC_SUBST_FILE([cc_shlib_conf])
 
 # ---------------------------------------------------------------------------
-# Support for MPIT performance variables
+# Support for MPI_T performance variables
 
 # enable-mpit-pvars
 # strip off multiple options, separated by commas
 save_IFS="$IFS"
 IFS=","
 for var in $enable_mpit_pvars ; do
-    case "$var" in 
-        nem)
-        enable_nem_pvars=yes
-	;;
-        recvq)
-        enable_recvq_pvars=yes
-	;;
-	all|yes)
-        enable_nem_pvars=yes
-        enable_recvq_pvars=yes
-	;;
-        no|none)
-	;;
-	*)
-	IFS=$save_IFS
-	AC_MSG_WARN([Unknown value $option for enable-mpit-pvars])
-	IFS=","
-	;;
-    esac
+    AS_CASE(["$var"],
+            [nem],[enable_nem_pvars=yes],
+            [recvq],[enable_recvq_pvars=yes],
+            [all|yes],
+            [enable_nem_pvars=yes
+             enable_recvq_pvars=yes],
+            [no|none],[],
+            [IFS=$save_IFS
+             AC_MSG_WARN([Unknown value ($option) for enable-mpit-pvars])
+             IFS=","])
 done
 IFS="$save_IFS"
 
@@ -1761,7 +1756,7 @@ else
     status_nem_pvars=0
 fi
 AC_DEFINE_UNQUOTED(ENABLE_NEM_STATISTICS,$status_nem_pvars,
-          [Define to 1 to enable nemesis-related MPIT performance variables])
+          [Define to 1 to enable nemesis-related MPI_T performance variables])
 
 if test -n "$enable_recvq_pvars" ; then
     status_recvq_pvars=1
@@ -1769,7 +1764,7 @@ else
     status_recvq_pvars=0
 fi
 AC_DEFINE_UNQUOTED(ENABLE_RECVQ_STATISTICS,$status_recvq_pvars,
-          [Define to 1 to enable message receive queue-related MPIT performance variables])
+          [Define to 1 to enable message receive queue-related MPI_T performance variables])
 
 # ---------------------------------------------------------------------------
 # Support for the language bindings: Fortran 77, Fortran 90, and C++

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

commit a4d103b7ece57a6aae7bac77e58927177a3b2a49
Author: Ralf Gunter <ralfgunter at gmail.com>
Date:   Fri Dec 7 09:31:58 2012 -0600

    Add configure args to selectively enable MPIT pvars.
    
    Users can now pass --enable-mpit-pvars to configure to statically
    enable/disable MPIT performance variables so as to limit performance
    impacts only to those variables they need.
    
    Current valid arguments are as follows:
        none     - No performance info recorded
        recvq    - All message queue-related variables
        nem      - All nemesis-related variables
        all      - All variables above
    
    A macro framework is added to facilitate the addition of new variables
    (see MPIR_T_GATE on mpid_common_statistics.h).
    
    Also add a check to the MPIT nemesis test to ensure that the variables
    being tested have been registered with the runtime.

diff --git a/configure.ac b/configure.ac
index a183a57..d97df82 100644
--- a/configure.ac
+++ b/configure.ac
@@ -372,6 +372,16 @@ AC_ARG_ENABLE(g,
         all      - All of the above choices
 ],,enable_g=none)
 
+AC_ARG_ENABLE(mpit_pvars,
+[--enable-mpit-pvars=list - Selectively enable MPIT performance variables.
+                         list is a comma-separated list of variable names,
+                         including
+        none     - No performance info recorded
+        recvq    - All message queue-related
+        nem      - All nemesis-related
+        all      - All variables above
+],,enable_mpit_pvars=none)
+
 dnl We may want to force MPI_Aint to be the same size as MPI_Offset, 
 dnl particularly on 32 bit systems with large (64 bit) file systems.
 AC_ARG_WITH(aint-size,
@@ -1716,6 +1726,52 @@ PAC_COMPILER_SHLIB_FLAGS([CC],[$cc_shlib_conf])
 AC_SUBST_FILE([cc_shlib_conf])
 
 # ---------------------------------------------------------------------------
+# Support for MPIT performance variables
+
+# enable-mpit-pvars
+# strip off multiple options, separated by commas
+save_IFS="$IFS"
+IFS=","
+for var in $enable_mpit_pvars ; do
+    case "$var" in 
+        nem)
+        enable_nem_pvars=yes
+	;;
+        recvq)
+        enable_recvq_pvars=yes
+	;;
+	all|yes)
+        enable_nem_pvars=yes
+        enable_recvq_pvars=yes
+	;;
+        no|none)
+	;;
+	*)
+	IFS=$save_IFS
+	AC_MSG_WARN([Unknown value $option for enable-mpit-pvars])
+	IFS=","
+	;;
+    esac
+done
+IFS="$save_IFS"
+
+if test -n "$enable_nem_pvars" ; then
+    status_nem_pvars=1
+else
+    status_nem_pvars=0
+fi
+AC_DEFINE_UNQUOTED(ENABLE_NEM_STATISTICS,$status_nem_pvars,
+          [Define to 1 to enable nemesis-related MPIT performance variables])
+
+if test -n "$enable_recvq_pvars" ; then
+    status_recvq_pvars=1
+else
+    status_recvq_pvars=0
+fi
+AC_DEFINE_UNQUOTED(ENABLE_RECVQ_STATISTICS,$status_recvq_pvars,
+          [Define to 1 to enable message receive queue-related MPIT performance variables])
+
+# ---------------------------------------------------------------------------
 # Support for the language bindings: Fortran 77, Fortran 90, and C++
 #
 # First, we handle the case of no explicit enable/disable option.  In that
diff --git a/src/mpid/ch3/channels/nemesis/include/mpid_nem_inline.h b/src/mpid/ch3/channels/nemesis/include/mpid_nem_inline.h
index e2bff14..6d215a1 100644
--- a/src/mpid/ch3/channels/nemesis/include/mpid_nem_inline.h
+++ b/src/mpid/ch3/channels/nemesis/include/mpid_nem_inline.h
@@ -83,7 +83,7 @@ MPID_nem_mpich_send_header (void* buf, int size, MPIDI_VC_t *vc, int *again)
         goto return_success;
     }
  usequeue_l:
-    MPIR_T_INC(MPID_nem_fbox_fall_back_to_queue_count[MPID_nem_mem_region.local_ranks[vc->lpid]]);
+    MPIR_T_INC(NEM_STATISTICS, MPID_nem_fbox_fall_back_to_queue_count[MPID_nem_mem_region.local_ranks[vc->lpid]]);
 
 #endif /*USE_FASTBOX */
 
@@ -315,7 +315,7 @@ MPID_nem_mpich_sendv_header (MPID_IOV **iov, int *n_iov, MPIDI_VC_t *vc, int *ag
         goto return_success;
     }
  usequeue_l:
-    MPIR_T_INC(MPID_nem_fbox_fall_back_to_queue_count[MPID_nem_mem_region.local_ranks[vc->lpid]]);
+    MPIR_T_INC(NEM_STATISTICS, MPID_nem_fbox_fall_back_to_queue_count[MPID_nem_mem_region.local_ranks[vc->lpid]]);
 
 #endif /*USE_FASTBOX */
 	
@@ -469,7 +469,7 @@ MPID_nem_mpich_send_seg_header (MPID_Segment *segment, MPIDI_msg_sz_t *segment_f
 	}
     }
  usequeue_l:
-    MPIR_T_INC(MPID_nem_fbox_fall_back_to_queue_count[MPID_nem_mem_region.local_ranks[vc->lpid]]);
+    MPIR_T_INC(NEM_STATISTICS, MPID_nem_fbox_fall_back_to_queue_count[MPID_nem_mem_region.local_ranks[vc->lpid]]);
 
 #endif /*USE_FASTBOX */
 	
diff --git a/src/mpid/ch3/channels/nemesis/include/mpidi_nem_statistics.h b/src/mpid/ch3/channels/nemesis/include/mpidi_nem_statistics.h
index 0e942f6..bdf6a0a 100644
--- a/src/mpid/ch3/channels/nemesis/include/mpidi_nem_statistics.h
+++ b/src/mpid/ch3/channels/nemesis/include/mpidi_nem_statistics.h
@@ -7,12 +7,9 @@
 #ifndef _MPIDI_NEM_STATISTICS_H_
 #define _MPIDI_NEM_STATISTICS_H_
 
-#define ENABLE_STATISTICS 1
 #include "mpidi_common_statistics.h"
 
-#define ENABLE_NEM_STATISTICS 1
-
-/* from mpid_nem_init.c */
+/* Do not protect by enable macro - see mpidi_common_statistics.h */
 extern uint64_t *MPID_nem_fbox_fall_back_to_queue_count;
 
 #endif  /* _MPIDI_NEM_STATISTICS_H_ */
diff --git a/src/mpid/ch3/channels/nemesis/src/mpid_nem_init.c b/src/mpid/ch3/channels/nemesis/src/mpid_nem_init.c
index 7bf7952..c8cbe64 100644
--- a/src/mpid/ch3/channels/nemesis/src/mpid_nem_init.c
+++ b/src/mpid/ch3/channels/nemesis/src/mpid_nem_init.c
@@ -37,6 +37,7 @@ static int get_local_procs(MPIDI_PG_t *pg, int our_pg_rank, int *num_local_p,
 
 char *MPID_nem_asymm_base_addr = 0;
 
+#if ENABLE_NEM_STATISTICS
 /* MPIT support */
 MPIR_T_SIMPLE_HANDLE_CREATOR(fbox_count_creator, uint64_t, MPID_nem_mem_region.num_local)
 
@@ -75,6 +76,7 @@ static int MPID_nem_init_stats(int n_local_ranks)
 fn_fail:
     return mpi_errno;
 }
+#endif  /* ENABLE_NEM_STATISTICS */
 
 #undef FUNCNAME
 #define FUNCNAME MPID_nem_init
diff --git a/src/mpid/ch3/include/mpidi_common_statistics.h b/src/mpid/ch3/include/mpidi_common_statistics.h
index d4c1d2e..d430bca 100644
--- a/src/mpid/ch3/include/mpidi_common_statistics.h
+++ b/src/mpid/ch3/include/mpidi_common_statistics.h
@@ -7,16 +7,34 @@
 #ifndef _MPIDI_COMMON_STATISTICS_H_
 #define _MPIDI_COMMON_STATISTICS_H_
 
-#if ENABLE_STATISTICS
+/* Statically decides whether or not to perform 'action'.
+ *
+ * This has the unfortunate side-effect that the compiler will complain about
+ * undeclared variables in the 'action' parameter.
+ * Thankfully, since by linking time they will be long gone (due to the compiler
+ * optimizing away the whole macro), a simple 'extern' declaration suffices.
+ * This is why some statistics headers declare their variables as extern
+ * outside of the macro scope.
+ */
+#define MPIR_T_GATE(PVAR_CLASS, action) \
+    do {                                \
+        if (ENABLE_##PVAR_CLASS) {      \
+            action;                     \
+        }                               \
+    } while(0)
+
 
 /* TODO add some code here and probably elsewhere to make these show up in the
  * MPI_T_pvar_ interface */
+#define MPIR_T_INC_impl(x) (++(x))
+#define MPIR_T_DEC_impl(x) (--(x))
 
-#define MPIR_T_INC(x) (++(x))
-#define MPIR_T_DEC(x) (--(x))
+#define MPIR_T_INC(PVAR_CLASS, x) MPIR_T_GATE(PVAR_CLASS, MPIR_T_INC_impl(x))
+#define MPIR_T_DEC(PVAR_CLASS, x) MPIR_T_GATE(PVAR_CLASS, MPIR_T_DEC_impl(x))
 
-#define MPIR_T_START_TIMER(start) MPID_Wtime(&start)
-#define MPIR_T_END_TIMER(start, mpit_variable)          \
+
+#define MPIR_T_START_TIMER_impl(start) MPID_Wtime(&start)
+#define MPIR_T_END_TIMER_impl(start, mpit_variable)     \
     do {                                                \
         MPID_Time_t end;                                \
         double temp_delta = 0.0;                        \
@@ -25,21 +43,16 @@
         (mpit_variable) += temp_delta;                  \
     } while(0)
 
-#define MPIR_T_SUBTRACT(x, y) ((x) -= (y))
-#define MPIR_T_ADD(x, y)      ((x) += (y))
-
-#else
+#define MPIR_T_START_TIMER(PVAR_CLASS, start) MPIR_T_GATE(PVAR_CLASS, MPIR_T_START_TIMER_impl(start))
+#define MPIR_T_END_TIMER(PVAR_CLASS, start, pvar) MPIR_T_GATE(PVAR_CLASS, MPIR_T_END_TIMER_impl(start, pvar))
 
-#define MPIR_T_INC(x)
-#define MPIR_T_DEC(x)
 
-#define MPIR_T_START_TIMER(start)
-#define MPIR_T_END_TIMER(start, mpit_variable)
+#define MPIR_T_SUBTRACT_impl(x, y) ((x) -= (y))
+#define MPIR_T_ADD_impl(x, y)      ((x) += (y))
 
-#define MPIR_T_SUBTRACT(x, y)
-#define MPIR_T_ADD(x, y)
+#define MPIR_T_SUBTRACT(PVAR_CLASS, x, y) MPIR_T_GATE(PVAR_CLASS, MPIR_T_SUBTRACT_impl(x, y))
+#define MPIR_T_ADD(PVAR_CLASS, x, y) MPIR_T_GATE(PVAR_CLASS, MPIR_T_ADD_impl(x, y))
 
-#endif /* ENABLE_STATISTICS */
 
 #define MPIR_T_SIMPLE_HANDLE_CREATOR(TAG, TYPE, COUNT)                          \
 static int TAG(void *obj_handle,                                                \
@@ -51,7 +64,7 @@ static int TAG(void *obj_handle,
     handle->handle_state = handle->info->var_state;                             \
     handle->bytes = sizeof(TYPE);                                               \
                                                                                 \
-    *countp       = (COUNT);                                                    \
+    *countp = (COUNT);                                                          \
     return MPI_SUCCESS;                                                         \
 }
 
diff --git a/src/mpid/ch3/include/mpidi_recvq_statistics.h b/src/mpid/ch3/include/mpidi_recvq_statistics.h
index 53a8da3..d0109a2 100644
--- a/src/mpid/ch3/include/mpidi_recvq_statistics.h
+++ b/src/mpid/ch3/include/mpidi_recvq_statistics.h
@@ -7,11 +7,10 @@
 #ifndef _MPIDI_RECVQ_STATISTICS_H_
 #define _MPIDI_RECVQ_STATISTICS_H_
 
-#define ENABLE_STATISTICS 1
 #include "mpidi_common_statistics.h"
 
-#define ENABLE_RECVQ_STATISTICS 1
-
-extern uint64_t MPIDI_CH3I_unexpected_recvq_buffer_size;   /* from ch3u_recvq.c */
+/* Do not protect by enable macro - see mpidi_common_statistics.h */
+/* from ch3u_recvq.c */
+extern uint64_t MPIDI_CH3I_unexpected_recvq_buffer_size;
 
 #endif  /* _MPIDI_RECVQ_STATISTICS_H_ */
diff --git a/src/mpid/ch3/src/ch3u_eager.c b/src/mpid/ch3/src/ch3u_eager.c
index 64310c2..2ca4e78 100644
--- a/src/mpid/ch3/src/ch3u_eager.c
+++ b/src/mpid/ch3/src/ch3u_eager.c
@@ -436,7 +436,7 @@ int MPIDI_CH3_PktHandler_EagerShortSend( MPIDI_VC_t *vc, MPIDI_CH3_Pkt_t *pkt,
                a buffer that we've allocated). */
 	    /* printf( "Allocating into tmp\n" ); fflush(stdout); */
 	    recv_data_sz = rreq->dev.recv_data_sz;
-            MPIR_T_ADD(MPIDI_CH3I_unexpected_recvq_buffer_size, recv_data_sz);
+            MPIR_T_ADD(RECVQ_STATISTICS, MPIDI_CH3I_unexpected_recvq_buffer_size, recv_data_sz);
 	    rreq->dev.tmpbuf = MPIU_Malloc(recv_data_sz);
 	    if (!rreq->dev.tmpbuf) {
 		MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER,"**nomem");
diff --git a/src/mpid/ch3/src/ch3u_handle_recv_pkt.c b/src/mpid/ch3/src/ch3u_handle_recv_pkt.c
index 7f3f020..8ea67a8 100644
--- a/src/mpid/ch3/src/ch3u_handle_recv_pkt.c
+++ b/src/mpid/ch3/src/ch3u_handle_recv_pkt.c
@@ -274,7 +274,7 @@ int MPIDI_CH3U_Receive_data_unexpected(MPID_Request * rreq, char *buf, MPIDI_msg
     }
 
     if (MPIDI_Request_get_msg_type(rreq) == MPIDI_REQUEST_EAGER_MSG)
-        MPIR_T_ADD(MPIDI_CH3I_unexpected_recvq_buffer_size, rreq->dev.tmpbuf_sz);
+        MPIR_T_ADD(RECVQ_STATISTICS, MPIDI_CH3I_unexpected_recvq_buffer_size, rreq->dev.tmpbuf_sz);
 
     rreq->dev.OnDataAvail = MPIDI_CH3_ReqHandler_UnpackUEBufComplete;
 
diff --git a/src/mpid/ch3/src/ch3u_recvq.c b/src/mpid/ch3/src/ch3u_recvq.c
index 6b3b823..01ce6bb 100644
--- a/src/mpid/ch3/src/ch3u_recvq.c
+++ b/src/mpid/ch3/src/ch3u_recvq.c
@@ -67,7 +67,16 @@ static MPI_Aint unexpected_recvq_match_attempts = 0;
 static double time_failed_matching_postedq = 0.0;
 static double time_matching_unexpectedq = 0.0;
 uint64_t MPIDI_CH3I_unexpected_recvq_buffer_size = 0;    /* used in ch3u_eager.c and ch3u_handle_recv_pkt.c */
-#endif /* defined(ENABLE_RECVQ_STATISTICS) */
+#else 
+extern unsigned int posted_qlen;
+extern unsigned int unexpected_qlen;
+extern MPI_Aint posted_recvq_match_attempts;
+extern MPI_Aint unexpected_recvq_match_attempts;
+extern double time_failed_matching_postedq;
+extern double time_matching_unexpectedq;
+extern uint64_t MPIDI_CH3I_unexpected_recvq_buffer_size;
+#endif  /* ENABLE_RECVQ_STATISTICS */ 
+
 
 /* If the MPIDI_Message_match structure fits into a pointer size, we
  * can directly work on it */
@@ -114,7 +123,7 @@ MPIR_T_SIMPLE_HANDLE_CREATOR(simple_double_creator, double, 1)
 int MPIDI_CH3U_Recvq_init(void)
 {
     int mpi_errno = MPI_SUCCESS;
-#ifdef ENABLE_RECVQ_STATISTICS
+#if ENABLE_RECVQ_STATISTICS
     int idx = -1;
     mpi_errno = MPIR_T_pvar_add("posted_recvq_length",
                                 MPI_T_VERBOSITY_USER_DETAIL,
@@ -282,14 +291,14 @@ int MPIDI_CH3U_Recvq_FU(int source, int tag, int context_id, MPI_Status *s)
     match.parts.rank = source;
 
     if (tag != MPI_ANY_TAG && source != MPI_ANY_SOURCE) {
-        MPIR_T_START_TIMER(timer_start);
+        MPIR_T_START_TIMER(RECVQ_STATISTICS, timer_start);
 	while (rreq != NULL) {
-            MPIR_T_INC(unexpected_recvq_match_attempts);
+            MPIR_T_INC(RECVQ_STATISTICS, unexpected_recvq_match_attempts);
 	    if (MATCH_WITH_NO_MASK(rreq->dev.match, match))
 		break;
 	    rreq = rreq->dev.next;
 	}
-        MPIR_T_END_TIMER(timer_start, time_matching_unexpectedq);
+        MPIR_T_END_TIMER(RECVQ_STATISTICS, timer_start, time_matching_unexpectedq);
     }
     else {
 	mask.parts.context_id = mask.parts.rank = mask.parts.tag = ~0;
@@ -298,14 +307,14 @@ int MPIDI_CH3U_Recvq_FU(int source, int tag, int context_id, MPI_Status *s)
 	if (source == MPI_ANY_SOURCE)
 	    match.parts.rank = mask.parts.rank = 0;
 
-        MPIR_T_START_TIMER(timer_start);
+        MPIR_T_START_TIMER(RECVQ_STATISTICS, timer_start);
 	while (rreq != NULL) {
-            MPIR_T_INC(unexpected_recvq_match_attempts);
+            MPIR_T_INC(RECVQ_STATISTICS, unexpected_recvq_match_attempts);
 	    if (MATCH_WITH_LEFT_MASK(rreq->dev.match, match, mask))
 		break;
 	    rreq = rreq->dev.next;
 	}
-        MPIR_T_END_TIMER(timer_start, time_matching_unexpectedq);
+        MPIR_T_END_TIMER(RECVQ_STATISTICS, timer_start, time_matching_unexpectedq);
     }
 
     /* Save the information about the request before releasing the 
@@ -365,14 +374,17 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU(MPI_Request sreq_id,
     /* FIXME: Why doesn't this exit after it finds the first match? */
     cur_rreq = recvq_unexpected_head;
     while (cur_rreq != NULL) {
-        MPIR_T_START_TIMER(timer_start);
-	if (cur_rreq->dev.sender_req_id == sreq_id &&
-            MPIR_T_INC(unexpected_recvq_match_attempts) &&
-	    (MATCH_WITH_NO_MASK(cur_rreq->dev.match, *match))) {
-	    matching_prev_rreq = prev_rreq;
-	    matching_cur_rreq = cur_rreq;
+        MPIR_T_START_TIMER(RECVQ_STATISTICS, timer_start);
+
+        if (cur_rreq->dev.sender_req_id == sreq_id) {
+            MPIR_T_INC(RECVQ_STATISTICS, unexpected_recvq_match_attempts);
+
+            if (MATCH_WITH_NO_MASK(cur_rreq->dev.match, *match)) {
+                matching_prev_rreq = prev_rreq;
+                matching_cur_rreq = cur_rreq;
+            }
 	}
-        MPIR_T_END_TIMER(timer_start, time_matching_unexpectedq);
+        MPIR_T_END_TIMER(RECVQ_STATISTICS, timer_start, time_matching_unexpectedq);
 
 	prev_rreq = cur_rreq;
 	cur_rreq = cur_rreq->dev.next;
@@ -390,10 +402,10 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU(MPI_Request sreq_id,
 	    recvq_unexpected_tail = matching_prev_rreq;
 	}
 
-        MPIR_T_DEC(unexpected_qlen);
+        MPIR_T_DEC(RECVQ_STATISTICS, unexpected_qlen);
 	rreq = matching_cur_rreq;
 
-        MPIR_T_SUBTRACT(MPIDI_CH3I_unexpected_recvq_buffer_size, rreq->dev.tmpbuf_sz);
+        MPIR_T_SUBTRACT(RECVQ_STATISTICS, MPIDI_CH3I_unexpected_recvq_buffer_size, rreq->dev.tmpbuf_sz);
     }
     else {
 	rreq = NULL;
@@ -425,7 +437,7 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU_matchonly(int source, int tag, int context_i
     MPIU_THREAD_CS_ASSERT_HELD(MSGQUEUE);
 
     /* Store how much time is spent traversing the queue */
-    MPIR_T_START_TIMER(timer_start);
+    MPIR_T_START_TIMER(RECVQ_STATISTICS, timer_start);
 
     /* Optimize this loop for an empty unexpected receive queue */
     rreq = recvq_unexpected_head;
@@ -438,7 +450,7 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU_matchonly(int source, int tag, int context_i
 
         if (tag != MPI_ANY_TAG && source != MPI_ANY_SOURCE) {
             do {
-                MPIR_T_INC(unexpected_recvq_match_attempts);
+                MPIR_T_INC(RECVQ_STATISTICS, unexpected_recvq_match_attempts);
                 if (MATCH_WITH_NO_MASK(rreq->dev.match, match)) {
                     if (prev_rreq != NULL) {
                         prev_rreq->dev.next = rreq->dev.next;
@@ -450,8 +462,8 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU_matchonly(int source, int tag, int context_i
                     if (rreq->dev.next == NULL) {
                         recvq_unexpected_tail = prev_rreq;
                     }
-                    MPIR_T_DEC(unexpected_qlen);
-                    MPIR_T_SUBTRACT(MPIDI_CH3I_unexpected_recvq_buffer_size, rreq->dev.tmpbuf_sz);
+                    MPIR_T_DEC(RECVQ_STATISTICS, unexpected_qlen);
+                    MPIR_T_SUBTRACT(RECVQ_STATISTICS, MPIDI_CH3I_unexpected_recvq_buffer_size, rreq->dev.tmpbuf_sz);
 
                     rreq->comm = comm;
                     MPIR_Comm_add_ref(comm);
@@ -472,7 +484,7 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU_matchonly(int source, int tag, int context_i
                 match.parts.rank = mask.parts.rank = 0;
 
             do {
-                MPIR_T_INC(unexpected_recvq_match_attempts);
+                MPIR_T_INC(RECVQ_STATISTICS, unexpected_recvq_match_attempts);
                 if (MATCH_WITH_LEFT_MASK(rreq->dev.match, match, mask)) {
                     if (prev_rreq != NULL) {
                         prev_rreq->dev.next = rreq->dev.next;
@@ -483,8 +495,8 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU_matchonly(int source, int tag, int context_i
                     if (rreq->dev.next == NULL) {
                         recvq_unexpected_tail = prev_rreq;
                     }
-                    MPIR_T_DEC(unexpected_qlen);
-                    MPIR_T_SUBTRACT(MPIDI_CH3I_unexpected_recvq_buffer_size, rreq->dev.tmpbuf_sz);
+                    MPIR_T_DEC(RECVQ_STATISTICS, unexpected_qlen);
+                    MPIR_T_SUBTRACT(RECVQ_STATISTICS, MPIDI_CH3I_unexpected_recvq_buffer_size, rreq->dev.tmpbuf_sz);
 
                     rreq->comm                 = comm;
                     MPIR_Comm_add_ref(comm);
@@ -500,7 +512,7 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU_matchonly(int source, int tag, int context_i
     }
 
 lock_exit:
-    MPIR_T_END_TIMER(timer_start, time_matching_unexpectedq);
+    MPIR_T_END_TIMER(RECVQ_STATISTICS, timer_start, time_matching_unexpectedq);
 
     *foundp = found;
 
@@ -542,7 +554,7 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU_or_AEP(int source, int tag,
     MPIU_THREAD_CS_ASSERT_HELD(MSGQUEUE);
 
     /* Store how much time is spent traversing the queue */
-    MPIR_T_START_TIMER(timer_start);
+    MPIR_T_START_TIMER(RECVQ_STATISTICS, timer_start);
 
     /* Optimize this loop for an empty unexpected receive queue */
     rreq = recvq_unexpected_head;
@@ -555,7 +567,7 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU_or_AEP(int source, int tag,
 
 	if (tag != MPI_ANY_TAG && source != MPI_ANY_SOURCE) {
 	    do {
-                MPIR_T_INC(unexpected_recvq_match_attempts);
+                MPIR_T_INC(RECVQ_STATISTICS, unexpected_recvq_match_attempts);
 		if (MATCH_WITH_NO_MASK(rreq->dev.match, match)) {
 		    if (prev_rreq != NULL) {
 			prev_rreq->dev.next = rreq->dev.next;
@@ -567,10 +579,10 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU_or_AEP(int source, int tag,
 		    if (rreq->dev.next == NULL) {
 			recvq_unexpected_tail = prev_rreq;
 		    }
-                    MPIR_T_DEC(unexpected_qlen);
+                    MPIR_T_DEC(RECVQ_STATISTICS, unexpected_qlen);
 
                     if (MPIDI_Request_get_msg_type(rreq) == MPIDI_REQUEST_EAGER_MSG)
-                        MPIR_T_SUBTRACT(MPIDI_CH3I_unexpected_recvq_buffer_size, rreq->dev.tmpbuf_sz);
+                        MPIR_T_SUBTRACT(RECVQ_STATISTICS, MPIDI_CH3I_unexpected_recvq_buffer_size, rreq->dev.tmpbuf_sz);
 
 		    rreq->comm = comm;
 		    MPIR_Comm_add_ref(comm);
@@ -592,7 +604,7 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU_or_AEP(int source, int tag,
 		match.parts.rank = mask.parts.rank = 0;
 
 	    do {
-                MPIR_T_INC(unexpected_recvq_match_attempts);
+                MPIR_T_INC(RECVQ_STATISTICS, unexpected_recvq_match_attempts);
 		if (MATCH_WITH_LEFT_MASK(rreq->dev.match, match, mask)) {
 		    if (prev_rreq != NULL) {
 			prev_rreq->dev.next = rreq->dev.next;
@@ -603,10 +615,10 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU_or_AEP(int source, int tag,
 		    if (rreq->dev.next == NULL) {
 			recvq_unexpected_tail = prev_rreq;
 		    }
-                    MPIR_T_DEC(unexpected_qlen);
+                    MPIR_T_DEC(RECVQ_STATISTICS, unexpected_qlen);
 
                     if (MPIDI_Request_get_msg_type(rreq) == MPIDI_REQUEST_EAGER_MSG)
-                        MPIR_T_SUBTRACT(MPIDI_CH3I_unexpected_recvq_buffer_size, rreq->dev.tmpbuf_sz);
+                        MPIR_T_SUBTRACT(RECVQ_STATISTICS, MPIDI_CH3I_unexpected_recvq_buffer_size, rreq->dev.tmpbuf_sz);
 
 		    rreq->comm                 = comm;
 		    MPIR_Comm_add_ref(comm);
@@ -621,7 +633,7 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU_or_AEP(int source, int tag,
 	    } while (rreq);
 	}
     }
-    MPIR_T_END_TIMER(timer_start, time_matching_unexpectedq);
+    MPIR_T_END_TIMER(RECVQ_STATISTICS, timer_start, time_matching_unexpectedq);
 
     /* A matching request was not found in the unexpected queue, so we 
        need to allocate a new request and add it to the posted queue */
@@ -679,7 +691,7 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU_or_AEP(int source, int tag,
 	    recvq_posted_head = rreq;
 	}
 	recvq_posted_tail = rreq;
-        MPIR_T_INC(posted_qlen);
+        MPIR_T_INC(RECVQ_STATISTICS, posted_qlen);
 	MPIDI_POSTED_RECV_ENQUEUE_HOOK(rreq);
     }
     
@@ -688,7 +700,7 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU_or_AEP(int source, int tag,
 
     /* If a match was not found, the timer was stopped after the traversal */
     if (found)
-        MPIR_T_END_TIMER(timer_start, time_matching_unexpectedq);
+        MPIR_T_END_TIMER(RECVQ_STATISTICS, timer_start, time_matching_unexpectedq);
     
     MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3U_RECVQ_FDU_OR_AEP);
     return rreq;
@@ -723,7 +735,7 @@ int MPIDI_CH3U_Recvq_DP(MPID_Request * rreq)
 
     /* MT FIXME is this right? or should the caller do this? */
     MPIU_THREAD_CS_ENTER(MSGQUEUE,);
-    MPIR_T_START_TIMER(timer_start);
+    MPIR_T_START_TIMER(RECVQ_STATISTICS, timer_start);
     cur_rreq = recvq_posted_head;
     while (cur_rreq != NULL) {
 	if (cur_rreq == rreq) {
@@ -736,7 +748,7 @@ int MPIDI_CH3U_Recvq_DP(MPID_Request * rreq)
 	    if (cur_rreq->dev.next == NULL) {
 		recvq_posted_tail = prev_rreq;
 	    }
-            MPIR_T_DEC(posted_qlen);
+            MPIR_T_DEC(RECVQ_STATISTICS, posted_qlen);
             /* Notify channel that rreq has been dequeued and check if
                it has already matched rreq, fail if so */
 	    dequeue_failed = MPIDI_POSTED_RECV_DEQUEUE_HOOK(rreq);
@@ -749,7 +761,7 @@ int MPIDI_CH3U_Recvq_DP(MPID_Request * rreq)
 	cur_rreq = cur_rreq->dev.next;
     }
     if (!found)
-        MPIR_T_END_TIMER(timer_start, time_failed_matching_postedq);
+        MPIR_T_END_TIMER(RECVQ_STATISTICS, timer_start, time_failed_matching_postedq);
 
     MPIU_THREAD_CS_EXIT(MSGQUEUE,);
 
@@ -799,9 +811,9 @@ MPID_Request * MPIDI_CH3U_Recvq_FDP_or_AEU(MPIDI_Message_match * match,
 
     rreq = recvq_posted_head;
 
-    MPIR_T_START_TIMER(timer_start);
+    MPIR_T_START_TIMER(RECVQ_STATISTICS, timer_start);
     while (rreq != NULL) {
-        MPIR_T_INC(posted_recvq_match_attempts);
+        MPIR_T_INC(RECVQ_STATISTICS, posted_recvq_match_attempts);
 	if (MATCH_WITH_LEFT_RIGHT_MASK(rreq->dev.match, *match, rreq->dev.mask)) {
 	    if (prev_rreq != NULL) {
 		prev_rreq->dev.next = rreq->dev.next;
@@ -812,7 +824,7 @@ MPID_Request * MPIDI_CH3U_Recvq_FDP_or_AEU(MPIDI_Message_match * match,
 	    if (rreq->dev.next == NULL) {
 		recvq_posted_tail = prev_rreq;
 	    }
-            MPIR_T_DEC(posted_qlen);
+            MPIR_T_DEC(RECVQ_STATISTICS, posted_qlen);
 
             /* give channel a chance to match the request, try again if so */
 	    channel_matched = MPIDI_POSTED_RECV_DEQUEUE_HOOK(rreq);
@@ -825,7 +837,7 @@ MPID_Request * MPIDI_CH3U_Recvq_FDP_or_AEU(MPIDI_Message_match * match,
 	prev_rreq = rreq;
 	rreq = rreq->dev.next;
     }
-    MPIR_T_END_TIMER(timer_start, time_failed_matching_postedq);
+    MPIR_T_END_TIMER(RECVQ_STATISTICS, timer_start, time_failed_matching_postedq);
 
     /* A matching request was not found in the posted queue, so we 
        need to allocate a new request and add it to the unexpected queue */
@@ -844,7 +856,7 @@ MPID_Request * MPIDI_CH3U_Recvq_FDP_or_AEU(MPIDI_Message_match * match,
 	    recvq_unexpected_head = rreq;
 	}
 	recvq_unexpected_tail = rreq;
-        MPIR_T_INC(unexpected_qlen);
+        MPIR_T_INC(RECVQ_STATISTICS, unexpected_qlen);
     }
     
     found = FALSE;
@@ -891,7 +903,7 @@ static inline void dequeue_and_set_error(MPID_Request **req,  MPID_Request *prev
     if (recvq_posted_tail == *req)
         recvq_posted_tail = prev_req;
 
-    MPIR_T_DEC(posted_qlen);
+    MPIR_T_DEC(RECVQ_STATISTICS, posted_qlen);
 
     /* set error and complete */
     (*req)->status.MPI_ERROR = *error;
diff --git a/test/mpi_t/nem_fbox_fallback_to_queue_count.c b/test/mpi_t/nem_fbox_fallback_to_queue_count.c
index e4a0530..8fea096 100644
--- a/test/mpi_t/nem_fbox_fallback_to_queue_count.c
+++ b/test/mpi_t/nem_fbox_fallback_to_queue_count.c
@@ -154,7 +154,8 @@ void recv_first_test()
 int main(int argc, char *argv[])
 {
     int i, size, num, name_len, desc_len, count, verb, thread_support;
-    int varclass, bind, readonly, continuous, atomic, fbox_idx;
+    int varclass, bind, readonly, continuous, atomic;
+    int fbox_idx = -1;
     char name[STR_LEN], desc[STR_LEN];
     MPI_Datatype dtype;
     MPI_T_enum enumtype;
@@ -183,6 +184,9 @@ int main(int argc, char *argv[])
             fbox_idx = i;
     }
 
+    /* Ensure variable was registered by the runtime */
+    assert(fbox_idx != -1);
+
     /* Initialize MPIT session & variable handle. */
     MPI_T_pvar_session_create(&session);
     MPI_T_pvar_handle_alloc(session, fbox_idx, NULL, &fbox_handle, &count);

http://git.mpich.org/mpich.git/commitdiff/46eacfc76cde82fa9f5bf16975de58a1c9798487

commit 46eacfc76cde82fa9f5bf16975de58a1c9798487
Author: Ralf Gunter <ralfgunter at gmail.com>
Date:   Thu Nov 29 16:31:48 2012 -0600

    Add MPIT variables and corresponding tests.
    
    The following MPIT performance variables are added:
    
     - nem_fbox_fall_back_to_queue_count;
     - time_failed_matching_postedq;
     - time_matching_unexpectedq;
     - unexpected_recvq_buffer_size.
    
    Some common MPIT-related routines, handle creation functions and
    enable/disable switches are gathered in a common file.
    
    Two test cases are furnished, but not yet integrated with 'make check'.

diff --git a/src/mpid/ch3/channels/nemesis/include/mpid_nem_inline.h b/src/mpid/ch3/channels/nemesis/include/mpid_nem_inline.h
index ee71cc6..e2bff14 100644
--- a/src/mpid/ch3/channels/nemesis/include/mpid_nem_inline.h
+++ b/src/mpid/ch3/channels/nemesis/include/mpid_nem_inline.h
@@ -11,6 +11,7 @@
 
 #include "my_papi_defs.h"
 #include "mpiiov.h"
+#include "mpidi_nem_statistics.h"
 
 extern int MPID_nem_lmt_shm_pending;
 extern MPID_nem_cell_ptr_t MPID_nem_prefetched_cell;
@@ -82,6 +83,8 @@ MPID_nem_mpich_send_header (void* buf, int size, MPIDI_VC_t *vc, int *again)
         goto return_success;
     }
  usequeue_l:
+    MPIR_T_INC(MPID_nem_fbox_fall_back_to_queue_count[MPID_nem_mem_region.local_ranks[vc->lpid]]);
+
 #endif /*USE_FASTBOX */
 
 #ifdef PREFETCH_CELL
@@ -312,6 +315,7 @@ MPID_nem_mpich_sendv_header (MPID_IOV **iov, int *n_iov, MPIDI_VC_t *vc, int *ag
         goto return_success;
     }
  usequeue_l:
+    MPIR_T_INC(MPID_nem_fbox_fall_back_to_queue_count[MPID_nem_mem_region.local_ranks[vc->lpid]]);
 
 #endif /*USE_FASTBOX */
 	
@@ -465,6 +469,7 @@ MPID_nem_mpich_send_seg_header (MPID_Segment *segment, MPIDI_msg_sz_t *segment_f
 	}
     }
  usequeue_l:
+    MPIR_T_INC(MPID_nem_fbox_fall_back_to_queue_count[MPID_nem_mem_region.local_ranks[vc->lpid]]);
 
 #endif /*USE_FASTBOX */
 	
diff --git a/src/mpid/ch3/channels/nemesis/include/mpidi_nem_statistics.h b/src/mpid/ch3/channels/nemesis/include/mpidi_nem_statistics.h
new file mode 100644
index 0000000..0e942f6
--- /dev/null
+++ b/src/mpid/ch3/channels/nemesis/include/mpidi_nem_statistics.h
@@ -0,0 +1,18 @@
+/* -*- Mode: c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *  (C) 2013 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+#ifndef _MPIDI_NEM_STATISTICS_H_
+#define _MPIDI_NEM_STATISTICS_H_
+
+#define ENABLE_STATISTICS 1
+#include "mpidi_common_statistics.h"
+
+#define ENABLE_NEM_STATISTICS 1
+
+/* from mpid_nem_init.c */
+extern uint64_t *MPID_nem_fbox_fall_back_to_queue_count;
+
+#endif  /* _MPIDI_NEM_STATISTICS_H_ */
diff --git a/src/mpid/ch3/channels/nemesis/src/mpid_nem_finalize.c b/src/mpid/ch3/channels/nemesis/src/mpid_nem_finalize.c
index baed188..f5cc1a5 100644
--- a/src/mpid/ch3/channels/nemesis/src/mpid_nem_finalize.c
+++ b/src/mpid/ch3/channels/nemesis/src/mpid_nem_finalize.c
@@ -10,6 +10,8 @@
 #include "pmi.h"
 #endif
 
+#include "mpidi_nem_statistics.h"
+
 #undef FUNCNAME
 #define FUNCNAME MPID_nem_finalize
 #undef FCNAME
@@ -54,6 +56,10 @@ int MPID_nem_finalize(void)
     my_papi_close();
 #endif /*PAPI_MONITOR */
     
+#if ENABLE_NEM_STATISTICS
+    MPIU_Free(MPID_nem_fbox_fall_back_to_queue_count);
+#endif
+
  fn_exit:
     MPIDI_FUNC_EXIT(MPID_STATE_MPID_NEM_FINALIZE);
     return mpi_errno;
diff --git a/src/mpid/ch3/channels/nemesis/src/mpid_nem_init.c b/src/mpid/ch3/channels/nemesis/src/mpid_nem_init.c
index 947da3b..7bf7952 100644
--- a/src/mpid/ch3/channels/nemesis/src/mpid_nem_init.c
+++ b/src/mpid/ch3/channels/nemesis/src/mpid_nem_init.c
@@ -8,6 +8,7 @@
 #include "mpid_nem_impl.h"
 #include "mpid_nem_nets.h"
 #include <errno.h>
+#include "mpidi_nem_statistics.h"
 
 /* constants for configure time selection of local LMT implementations */
 #define MPID_NEM_LOCAL_LMT_NONE 0
@@ -36,6 +37,45 @@ static int get_local_procs(MPIDI_PG_t *pg, int our_pg_rank, int *num_local_p,
 
 char *MPID_nem_asymm_base_addr = 0;
 
+/* MPIT support */
+MPIR_T_SIMPLE_HANDLE_CREATOR(fbox_count_creator, uint64_t, MPID_nem_mem_region.num_local)
+
+/* used by mpid_nem_inline.h and mpid_nem_finalize.c */
+uint64_t *MPID_nem_fbox_fall_back_to_queue_count = NULL;
+
+#undef FUNCNAME
+#define FUNCNAME MPID_nem_init_stats
+#undef FCNAME
+#define FCNAME MPIDI_QUOTE(FUNCNAME)
+static int MPID_nem_init_stats(int n_local_ranks)
+{
+    int mpi_errno = MPI_SUCCESS;
+    int idx = -1;
+
+    MPID_nem_fbox_fall_back_to_queue_count = MPIU_Calloc(n_local_ranks, sizeof(uint64_t));
+
+    mpi_errno = MPIR_T_pvar_add("nem_fbox_fall_back_to_queue_count",
+                                MPI_T_VERBOSITY_USER_DETAIL,
+                                MPI_T_PVAR_CLASS_COUNTER,
+                                MPI_AINT,
+                                MPI_T_ENUM_NULL,
+                                "array counting how many times nemesis had to fall back to "
+                                "the regular queue when sending messages between pairs of "
+                                "local processes",
+                                MPI_T_BIND_NO_OBJECT,
+                                /*readonly=*/ FALSE,
+                                /*continuous=*/ TRUE,
+                                /*atomic=*/ FALSE,
+                                MPIR_T_PVAR_IMPL_SIMPLE,
+                                /*var_state=*/ MPID_nem_fbox_fall_back_to_queue_count,
+                                &fbox_count_creator,
+                                &idx);
+    if (mpi_errno) MPIU_ERR_POP(mpi_errno);
+
+fn_fail:
+    return mpi_errno;
+}
+
 #undef FUNCNAME
 #define FUNCNAME MPID_nem_init
 #undef FCNAME
@@ -341,6 +381,10 @@ MPID_nem_init(int pg_rank, MPIDI_PG_t *pg_p, int has_parent ATTRIBUTE((unused)))
     my_papi_start( pg_rank );
 #endif /*PAPI_MONITOR   */
 
+#if ENABLE_NEM_STATISTICS
+    MPID_nem_init_stats(num_local);
+#endif
+
     MPIU_CHKPMEM_COMMIT();
  fn_exit:
     return mpi_errno;
@@ -349,6 +393,7 @@ MPID_nem_init(int pg_rank, MPIDI_PG_t *pg_p, int has_parent ATTRIBUTE((unused)))
     MPIU_CHKPMEM_REAP();
     goto fn_exit;
     /* --END ERROR HANDLING-- */
+
 }
 
 /* MPID_nem_vc_init initialize nemesis' part of the vc */
diff --git a/src/mpid/ch3/include/mpidi_common_statistics.h b/src/mpid/ch3/include/mpidi_common_statistics.h
new file mode 100644
index 0000000..d4c1d2e
--- /dev/null
+++ b/src/mpid/ch3/include/mpidi_common_statistics.h
@@ -0,0 +1,58 @@
+/* -*- Mode: c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *  (C) 2013 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+#ifndef _MPIDI_COMMON_STATISTICS_H_
+#define _MPIDI_COMMON_STATISTICS_H_
+
+#if ENABLE_STATISTICS
+
+/* TODO add some code here and probably elsewhere to make these show up in the
+ * MPI_T_pvar_ interface */
+
+#define MPIR_T_INC(x) (++(x))
+#define MPIR_T_DEC(x) (--(x))
+
+#define MPIR_T_START_TIMER(start) MPID_Wtime(&start)
+#define MPIR_T_END_TIMER(start, mpit_variable)          \
+    do {                                                \
+        MPID_Time_t end;                                \
+        double temp_delta = 0.0;                        \
+        MPID_Wtime(&(end));                             \
+        MPID_Wtime_diff(&(start), &end, &temp_delta);   \
+        (mpit_variable) += temp_delta;                  \
+    } while(0)
+
+#define MPIR_T_SUBTRACT(x, y) ((x) -= (y))
+#define MPIR_T_ADD(x, y)      ((x) += (y))
+
+#else
+
+#define MPIR_T_INC(x)
+#define MPIR_T_DEC(x)
+
+#define MPIR_T_START_TIMER(start)
+#define MPIR_T_END_TIMER(start, mpit_variable)
+
+#define MPIR_T_SUBTRACT(x, y)
+#define MPIR_T_ADD(x, y)
+
+#endif /* ENABLE_STATISTICS */
+
+#define MPIR_T_SIMPLE_HANDLE_CREATOR(TAG, TYPE, COUNT)                          \
+static int TAG(void *obj_handle,                                                \
+               struct MPIR_T_pvar_handle *handle,                               \
+               int *countp)                                                     \
+{                                                                               \
+    /* the IMPL_SIMPLE code reads/writes "bytes" bytes from the location given  \
+     * by the "handle_state" pointer */                                         \
+    handle->handle_state = handle->info->var_state;                             \
+    handle->bytes = sizeof(TYPE);                                               \
+                                                                                \
+    *countp       = (COUNT);                                                    \
+    return MPI_SUCCESS;                                                         \
+}
+
+#endif  /* _MPIDI_COMMON_STATISTICS_H_ */
diff --git a/src/mpid/ch3/include/mpidi_recvq_statistics.h b/src/mpid/ch3/include/mpidi_recvq_statistics.h
new file mode 100644
index 0000000..53a8da3
--- /dev/null
+++ b/src/mpid/ch3/include/mpidi_recvq_statistics.h
@@ -0,0 +1,17 @@
+/* -*- Mode: c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *  (C) 2013 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+#ifndef _MPIDI_RECVQ_STATISTICS_H_
+#define _MPIDI_RECVQ_STATISTICS_H_
+
+#define ENABLE_STATISTICS 1
+#include "mpidi_common_statistics.h"
+
+#define ENABLE_RECVQ_STATISTICS 1
+
+extern uint64_t MPIDI_CH3I_unexpected_recvq_buffer_size;   /* from ch3u_recvq.c */
+
+#endif  /* _MPIDI_RECVQ_STATISTICS_H_ */
diff --git a/src/mpid/ch3/src/ch3u_eager.c b/src/mpid/ch3/src/ch3u_eager.c
index 4800e23..64310c2 100644
--- a/src/mpid/ch3/src/ch3u_eager.c
+++ b/src/mpid/ch3/src/ch3u_eager.c
@@ -5,6 +5,7 @@
  */
 
 #include "mpidimpl.h"
+#include "mpidi_recvq_statistics.h"
 
 /*
  * Send an eager message.  To optimize for the important, short contiguous
@@ -435,6 +436,7 @@ int MPIDI_CH3_PktHandler_EagerShortSend( MPIDI_VC_t *vc, MPIDI_CH3_Pkt_t *pkt,
                a buffer that we've allocated). */
 	    /* printf( "Allocating into tmp\n" ); fflush(stdout); */
 	    recv_data_sz = rreq->dev.recv_data_sz;
+            MPIR_T_ADD(MPIDI_CH3I_unexpected_recvq_buffer_size, recv_data_sz);
 	    rreq->dev.tmpbuf = MPIU_Malloc(recv_data_sz);
 	    if (!rreq->dev.tmpbuf) {
 		MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER,"**nomem");
diff --git a/src/mpid/ch3/src/ch3u_handle_recv_pkt.c b/src/mpid/ch3/src/ch3u_handle_recv_pkt.c
index 7828606..7f3f020 100644
--- a/src/mpid/ch3/src/ch3u_handle_recv_pkt.c
+++ b/src/mpid/ch3/src/ch3u_handle_recv_pkt.c
@@ -6,6 +6,7 @@
 
 #include "mpidimpl.h"
 #include "mpidrma.h"
+#include "mpidi_recvq_statistics.h"
 
 /*
  * This file contains the dispatch routine called by the ch3 progress 
@@ -272,6 +273,9 @@ int MPIDI_CH3U_Receive_data_unexpected(MPID_Request * rreq, char *buf, MPIDI_msg
         *complete = FALSE;
     }
 
+    if (MPIDI_Request_get_msg_type(rreq) == MPIDI_REQUEST_EAGER_MSG)
+        MPIR_T_ADD(MPIDI_CH3I_unexpected_recvq_buffer_size, rreq->dev.tmpbuf_sz);
+
     rreq->dev.OnDataAvail = MPIDI_CH3_ReqHandler_UnpackUEBufComplete;
 
  fn_fail:
diff --git a/src/mpid/ch3/src/ch3u_recvq.c b/src/mpid/ch3/src/ch3u_recvq.c
index de99de1..6b3b823 100644
--- a/src/mpid/ch3/src/ch3u_recvq.c
+++ b/src/mpid/ch3/src/ch3u_recvq.c
@@ -5,6 +5,7 @@
  */
 
 #include "mpidimpl.h"
+#include "mpidi_recvq_statistics.h"
 
 /* MPIDI_POSTED_RECV_ENQUEUE_HOOK(req): Notifies channel that req has
    been enqueued on the posted recv queue.  Returns void. */
@@ -58,24 +59,14 @@ MPID_Request ** const MPID_Recvq_posted_head_ptr     = &recvq_posted_head;
 MPID_Request ** const MPID_Recvq_unexpected_head_ptr = &recvq_unexpected_head;
 #endif
 
-/* TODO decide control this independently via configure or with the existing
- * --enable-timing option (#ifdef COLLECT_STATS) */
-#define ENABLE_RECVQ_STATISTICS 1
-#ifdef ENABLE_RECVQ_STATISTICS
+#if ENABLE_RECVQ_STATISTICS
 static unsigned int posted_qlen = 0;
 static unsigned int unexpected_qlen = 0;
 static MPI_Aint posted_recvq_match_attempts = 0;
 static MPI_Aint unexpected_recvq_match_attempts = 0;
-/* TODO add some code here and probably elsewhere to make these show up in the
- * MPI_T_pvar_ interface */
-#define MPIR_T_INC(x) (++(x))
-#define MPIR_T_DEC(x) (--(x))
-
-#else
-
-#define MPIR_T_INC(x)
-#define MPIR_T_DEC(x)
-
+static double time_failed_matching_postedq = 0.0;
+static double time_matching_unexpectedq = 0.0;
+uint64_t MPIDI_CH3I_unexpected_recvq_buffer_size = 0;    /* used in ch3u_eager.c and ch3u_handle_recv_pkt.c */
 #endif /* defined(ENABLE_RECVQ_STATISTICS) */
 
 /* If the MPIDI_Message_match structure fits into a pointer size, we
@@ -110,34 +101,11 @@ static MPI_Aint unexpected_recvq_match_attempts = 0;
       (((match1).parts.tag & (mask).parts.tag) == ((match2).parts.tag & (mask).parts.tag)) && \
       ((match1).parts.context_id == (match2).parts.context_id)))
 
-/* will be invoked to populate the custom parts of pvar_handle objects */
-static int simple_uint_creator(void *obj_handle,
-                               struct MPIR_T_pvar_handle *handle,
-                               int *countp)
-{
-    /* the IMPL_SIMPLE code reads/writes "bytes" bytes from the location given
-     * by the "handle_state" pointer */
-    handle->handle_state = handle->info->var_state;
-    handle->bytes = sizeof(unsigned int);
-
-    /* a single unsigned int should be read/written */
-    *countp = 1;
-    return MPI_SUCCESS;
-}
 
-static int simple_aint_creator(void *obj_handle,
-                               struct MPIR_T_pvar_handle *handle,
-                               int *countp)
-{
-    /* the IMPL_SIMPLE code reads/writes "bytes" bytes from the location given
-     * by the "handle_state" pointer */
-    handle->handle_state = handle->info->var_state;
-    handle->bytes = sizeof(MPI_Aint);
-
-    /* a single Aint should be read/written */
-    *countp = 1;
-    return MPI_SUCCESS;
-}
+/* will be invoked to populate the custom parts of pvar_handle objects */
+MPIR_T_SIMPLE_HANDLE_CREATOR(simple_aint_creator, MPI_Aint, 1)
+MPIR_T_SIMPLE_HANDLE_CREATOR(simple_uint_creator, unsigned int, 1)
+MPIR_T_SIMPLE_HANDLE_CREATOR(simple_double_creator, double, 1)
 
 #undef FUNCNAME
 #define FUNCNAME MPIDI_CH3U_Recvq_init
@@ -213,6 +181,58 @@ int MPIDI_CH3U_Recvq_init(void)
                                 &simple_aint_creator,
                                 &idx);
     if (mpi_errno) MPIU_ERR_POP(mpi_errno);
+
+    /* time spent unsuccessfully trying to match incoming message with posted receives */
+    mpi_errno = MPIR_T_pvar_add("time_failed_matching_postedq",
+                                MPI_T_VERBOSITY_USER_DETAIL,
+                                MPI_T_PVAR_CLASS_TIMER,
+                                MPI_DOUBLE,
+                                MPI_T_ENUM_NULL,
+                                "total time spent on unsuccessful search passes on the posted receives queue",
+                                MPI_T_BIND_NO_OBJECT,
+                                /*readonly=*/FALSE,
+                                /*continuous=*/TRUE,
+                                /*atomic=*/FALSE,
+                                MPIR_T_PVAR_IMPL_SIMPLE,
+                                /*var_state=*/&time_failed_matching_postedq,
+                                &simple_double_creator,
+                                &idx);
+    if (mpi_errno) MPIU_ERR_POP(mpi_errno);
+
+    /* time spent trying to match a posted receive with messages in the unexpected queue */
+    mpi_errno = MPIR_T_pvar_add("time_matching_unexpectedq",
+                                MPI_T_VERBOSITY_USER_DETAIL,
+                                MPI_T_PVAR_CLASS_TIMER,
+                                MPI_DOUBLE,
+                                MPI_T_ENUM_NULL,
+                                "total time spent on search passes on the unexpected receive queue",
+                                MPI_T_BIND_NO_OBJECT,
+                                /*readonly=*/FALSE,
+                                /*continuous=*/TRUE,
+                                /*atomic=*/FALSE,
+                                MPIR_T_PVAR_IMPL_SIMPLE,
+                                /*var_state=*/&time_matching_unexpectedq,
+                                &simple_double_creator,
+                                &idx);
+    if (mpi_errno) MPIU_ERR_POP(mpi_errno);
+
+    /* allocated buffer size in the unexpected receive queue */
+    mpi_errno = MPIR_T_pvar_add("unexpected_recvq_buffer_size",
+                                MPI_T_VERBOSITY_USER_DETAIL,
+                                MPI_T_PVAR_CLASS_LEVEL,
+                                MPI_AINT,
+                                MPI_T_ENUM_NULL,
+                                "total buffer size allocated in the unexpected receive queue",
+                                MPI_T_BIND_NO_OBJECT,
+                                /*readonly=*/TRUE,
+                                /*continuous=*/TRUE,
+                                /*atomic=*/FALSE,
+                                MPIR_T_PVAR_IMPL_SIMPLE,
+                                /*var_state=*/&MPIDI_CH3I_unexpected_recvq_buffer_size,
+                                &simple_aint_creator,
+                                &idx);
+    if (mpi_errno) MPIU_ERR_POP(mpi_errno);
+
 #endif
 fn_fail:
     return mpi_errno;
@@ -246,6 +266,7 @@ fn_fail:
 int MPIDI_CH3U_Recvq_FU(int source, int tag, int context_id, MPI_Status *s)
 {
     MPID_Request * rreq;
+    MPID_Time_t timer_start;
     int found = 0;
     MPIDI_Message_match match, mask;
     MPIDI_STATE_DECL(MPID_STATE_MPIDI_CH3U_RECVQ_FU);
@@ -261,12 +282,14 @@ int MPIDI_CH3U_Recvq_FU(int source, int tag, int context_id, MPI_Status *s)
     match.parts.rank = source;
 
     if (tag != MPI_ANY_TAG && source != MPI_ANY_SOURCE) {
+        MPIR_T_START_TIMER(timer_start);
 	while (rreq != NULL) {
             MPIR_T_INC(unexpected_recvq_match_attempts);
 	    if (MATCH_WITH_NO_MASK(rreq->dev.match, match))
 		break;
 	    rreq = rreq->dev.next;
 	}
+        MPIR_T_END_TIMER(timer_start, time_matching_unexpectedq);
     }
     else {
 	mask.parts.context_id = mask.parts.rank = mask.parts.tag = ~0;
@@ -275,12 +298,14 @@ int MPIDI_CH3U_Recvq_FU(int source, int tag, int context_id, MPI_Status *s)
 	if (source == MPI_ANY_SOURCE)
 	    match.parts.rank = mask.parts.rank = 0;
 
+        MPIR_T_START_TIMER(timer_start);
 	while (rreq != NULL) {
             MPIR_T_INC(unexpected_recvq_match_attempts);
 	    if (MATCH_WITH_LEFT_MASK(rreq->dev.match, match, mask))
 		break;
 	    rreq = rreq->dev.next;
 	}
+        MPIR_T_END_TIMER(timer_start, time_matching_unexpectedq);
     }
 
     /* Save the information about the request before releasing the 
@@ -319,6 +344,7 @@ int MPIDI_CH3U_Recvq_FU(int source, int tag, int context_id, MPI_Status *s)
 MPID_Request * MPIDI_CH3U_Recvq_FDU(MPI_Request sreq_id, 
 				    MPIDI_Message_match * match)
 {
+    MPID_Time_t timer_start;
     MPID_Request * rreq;
     MPID_Request * prev_rreq;
     MPID_Request * cur_rreq;
@@ -339,12 +365,15 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU(MPI_Request sreq_id,
     /* FIXME: Why doesn't this exit after it finds the first match? */
     cur_rreq = recvq_unexpected_head;
     while (cur_rreq != NULL) {
+        MPIR_T_START_TIMER(timer_start);
 	if (cur_rreq->dev.sender_req_id == sreq_id &&
             MPIR_T_INC(unexpected_recvq_match_attempts) &&
 	    (MATCH_WITH_NO_MASK(cur_rreq->dev.match, *match))) {
 	    matching_prev_rreq = prev_rreq;
 	    matching_cur_rreq = cur_rreq;
 	}
+        MPIR_T_END_TIMER(timer_start, time_matching_unexpectedq);
+
 	prev_rreq = cur_rreq;
 	cur_rreq = cur_rreq->dev.next;
     }
@@ -363,6 +392,8 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU(MPI_Request sreq_id,
 
         MPIR_T_DEC(unexpected_qlen);
 	rreq = matching_cur_rreq;
+
+        MPIR_T_SUBTRACT(MPIDI_CH3I_unexpected_recvq_buffer_size, rreq->dev.tmpbuf_sz);
     }
     else {
 	rreq = NULL;
@@ -382,6 +413,7 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU(MPI_Request sreq_id,
 #define FCNAME MPIDI_QUOTE(FUNCNAME)
 MPID_Request * MPIDI_CH3U_Recvq_FDU_matchonly(int source, int tag, int context_id, MPID_Comm *comm, int *foundp)
 {
+    MPID_Time_t timer_start;
     int found = FALSE;
     MPID_Request *rreq, *prev_rreq;
     MPIDI_Message_match match;
@@ -392,6 +424,9 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU_matchonly(int source, int tag, int context_i
 
     MPIU_THREAD_CS_ASSERT_HELD(MSGQUEUE);
 
+    /* Store how much time is spent traversing the queue */
+    MPIR_T_START_TIMER(timer_start);
+
     /* Optimize this loop for an empty unexpected receive queue */
     rreq = recvq_unexpected_head;
     if (rreq) {
@@ -416,6 +451,7 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU_matchonly(int source, int tag, int context_i
                         recvq_unexpected_tail = prev_rreq;
                     }
                     MPIR_T_DEC(unexpected_qlen);
+                    MPIR_T_SUBTRACT(MPIDI_CH3I_unexpected_recvq_buffer_size, rreq->dev.tmpbuf_sz);
 
                     rreq->comm = comm;
                     MPIR_Comm_add_ref(comm);
@@ -448,6 +484,7 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU_matchonly(int source, int tag, int context_i
                         recvq_unexpected_tail = prev_rreq;
                     }
                     MPIR_T_DEC(unexpected_qlen);
+                    MPIR_T_SUBTRACT(MPIDI_CH3I_unexpected_recvq_buffer_size, rreq->dev.tmpbuf_sz);
 
                     rreq->comm                 = comm;
                     MPIR_Comm_add_ref(comm);
@@ -463,6 +500,8 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU_matchonly(int source, int tag, int context_i
     }
 
 lock_exit:
+    MPIR_T_END_TIMER(timer_start, time_matching_unexpectedq);
+
     *foundp = found;
 
     MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3U_RECVQ_FDU_MATCHONLY);
@@ -491,6 +530,7 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU_or_AEP(int source, int tag,
                                            int context_id, MPID_Comm *comm, void *user_buf,
                                            int user_count, MPI_Datatype datatype, int * foundp)
 {
+    MPID_Time_t timer_start;
     int found;
     MPID_Request *rreq, *prev_rreq;
     MPIDI_Message_match match;
@@ -501,6 +541,9 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU_or_AEP(int source, int tag,
 
     MPIU_THREAD_CS_ASSERT_HELD(MSGQUEUE);
 
+    /* Store how much time is spent traversing the queue */
+    MPIR_T_START_TIMER(timer_start);
+
     /* Optimize this loop for an empty unexpected receive queue */
     rreq = recvq_unexpected_head;
     if (rreq) {
@@ -526,6 +569,9 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU_or_AEP(int source, int tag,
 		    }
                     MPIR_T_DEC(unexpected_qlen);
 
+                    if (MPIDI_Request_get_msg_type(rreq) == MPIDI_REQUEST_EAGER_MSG)
+                        MPIR_T_SUBTRACT(MPIDI_CH3I_unexpected_recvq_buffer_size, rreq->dev.tmpbuf_sz);
+
 		    rreq->comm = comm;
 		    MPIR_Comm_add_ref(comm);
 		    rreq->dev.user_buf = user_buf;
@@ -559,6 +605,9 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU_or_AEP(int source, int tag,
 		    }
                     MPIR_T_DEC(unexpected_qlen);
 
+                    if (MPIDI_Request_get_msg_type(rreq) == MPIDI_REQUEST_EAGER_MSG)
+                        MPIR_T_SUBTRACT(MPIDI_CH3I_unexpected_recvq_buffer_size, rreq->dev.tmpbuf_sz);
+
 		    rreq->comm                 = comm;
 		    MPIR_Comm_add_ref(comm);
 		    rreq->dev.user_buf         = user_buf;
@@ -572,7 +621,8 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU_or_AEP(int source, int tag,
 	    } while (rreq);
 	}
     }
-    
+    MPIR_T_END_TIMER(timer_start, time_matching_unexpectedq);
+
     /* A matching request was not found in the unexpected queue, so we 
        need to allocate a new request and add it to the posted queue */
     {
@@ -634,8 +684,11 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU_or_AEP(int source, int tag,
     }
     
   lock_exit:
-
     *foundp = found;
+
+    /* If a match was not found, the timer was stopped after the traversal */
+    if (found)
+        MPIR_T_END_TIMER(timer_start, time_matching_unexpectedq);
     
     MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3U_RECVQ_FDU_OR_AEP);
     return rreq;
@@ -657,6 +710,7 @@ MPID_Request * MPIDI_CH3U_Recvq_FDU_or_AEP(int source, int tag,
 int MPIDI_CH3U_Recvq_DP(MPID_Request * rreq)
 {
     int found;
+    MPID_Time_t timer_start;
     MPID_Request * cur_rreq;
     MPID_Request * prev_rreq;
     int dequeue_failed;
@@ -669,6 +723,7 @@ int MPIDI_CH3U_Recvq_DP(MPID_Request * rreq)
 
     /* MT FIXME is this right? or should the caller do this? */
     MPIU_THREAD_CS_ENTER(MSGQUEUE,);
+    MPIR_T_START_TIMER(timer_start);
     cur_rreq = recvq_posted_head;
     while (cur_rreq != NULL) {
 	if (cur_rreq == rreq) {
@@ -693,6 +748,8 @@ int MPIDI_CH3U_Recvq_DP(MPID_Request * rreq)
 	prev_rreq = cur_rreq;
 	cur_rreq = cur_rreq->dev.next;
     }
+    if (!found)
+        MPIR_T_END_TIMER(timer_start, time_failed_matching_postedq);
 
     MPIU_THREAD_CS_EXIT(MSGQUEUE,);
 
@@ -726,6 +783,7 @@ int MPIDI_CH3U_Recvq_DP(MPID_Request * rreq)
 MPID_Request * MPIDI_CH3U_Recvq_FDP_or_AEU(MPIDI_Message_match * match, 
 					   int * foundp)
 {
+    MPID_Time_t timer_start;
     int found;
     MPID_Request * rreq;
     MPID_Request * prev_rreq;
@@ -741,6 +799,7 @@ MPID_Request * MPIDI_CH3U_Recvq_FDP_or_AEU(MPIDI_Message_match * match,
 
     rreq = recvq_posted_head;
 
+    MPIR_T_START_TIMER(timer_start);
     while (rreq != NULL) {
         MPIR_T_INC(posted_recvq_match_attempts);
 	if (MATCH_WITH_LEFT_RIGHT_MASK(rreq->dev.match, *match, rreq->dev.mask)) {
@@ -766,6 +825,7 @@ MPID_Request * MPIDI_CH3U_Recvq_FDP_or_AEU(MPIDI_Message_match * match,
 	prev_rreq = rreq;
 	rreq = rreq->dev.next;
     }
+    MPIR_T_END_TIMER(timer_start, time_failed_matching_postedq);
 
     /* A matching request was not found in the posted queue, so we 
        need to allocate a new request and add it to the unexpected queue */
diff --git a/test/mpi_t/nem_fbox_fallback_to_queue_count.c b/test/mpi_t/nem_fbox_fallback_to_queue_count.c
new file mode 100644
index 0000000..e4a0530
--- /dev/null
+++ b/test/mpi_t/nem_fbox_fallback_to_queue_count.c
@@ -0,0 +1,206 @@
+#include <mpi.h>
+#include <assert.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdio.h>
+
+#define TRY(func)                           \
+    do {                                    \
+        err = (func);                       \
+        if (err != MPI_SUCCESS)             \
+            MPI_Abort(MPI_COMM_WORLD, err); \
+    } while(0)
+
+#define STR_LEN   100
+#define BUF_COUNT 10
+
+uint64_t null_fbox[2] = { 0 };
+int err, rank;
+MPI_T_pvar_session session;
+MPI_T_pvar_handle fbox_handle;
+
+/* Check that we can successfuly write to the variable. */
+void blank_test()
+{
+    int i;
+    uint64_t temp[2] = { -1 };
+
+    temp[0] = 0x1234; temp[1] = 0xABCD;
+    TRY(MPI_T_pvar_write(session, fbox_handle, temp));
+
+    temp[0] = 0xCD34; temp[1] = 0x12AB;
+    TRY(MPI_T_pvar_read(session, fbox_handle, temp));
+    assert(temp[0] == 0x1234); assert(temp[1] == 0xABCD);
+}
+
+/* Nemesis' fastbox falls back to regular queues when more than one message
+ * is yet to be delivered.
+ * Here, the sender posts all sends before the receiver has a chance to
+ * acknowledge any of them; this should force the sender to fall_back to the
+ * queue every time. */
+void send_first_test()
+{
+    uint64_t nem_fbox_fall_back_to_queue_count[2] = {-1};
+
+    /* Reset the fbox variable. */
+    MPI_T_pvar_write(session, fbox_handle, null_fbox);
+
+    if (rank == 0) {
+        char send_buf[BUF_COUNT] = { 0x12 };
+
+        /* Check that the variable has been correctly initialized. */
+        TRY(MPI_T_pvar_read(session, fbox_handle, nem_fbox_fall_back_to_queue_count));
+        assert(nem_fbox_fall_back_to_queue_count[1] == 0);
+
+        MPI_Send(send_buf, BUF_COUNT, MPI_CHAR, 1, 0, MPI_COMM_WORLD);
+        TRY(MPI_T_pvar_read(session, fbox_handle, nem_fbox_fall_back_to_queue_count));
+        assert(nem_fbox_fall_back_to_queue_count[1] == 0);
+
+        MPI_Send(send_buf, BUF_COUNT, MPI_CHAR, 1, 0, MPI_COMM_WORLD);
+        TRY(MPI_T_pvar_read(session, fbox_handle, nem_fbox_fall_back_to_queue_count));
+        assert(nem_fbox_fall_back_to_queue_count[1] == 1);
+
+        MPI_Send(send_buf, BUF_COUNT, MPI_CHAR, 1, 0, MPI_COMM_WORLD);
+        TRY(MPI_T_pvar_read(session, fbox_handle, nem_fbox_fall_back_to_queue_count));
+        assert(nem_fbox_fall_back_to_queue_count[1] == 2);
+
+        MPI_Send(send_buf, BUF_COUNT, MPI_CHAR, 1, 0, MPI_COMM_WORLD);
+        TRY(MPI_T_pvar_read(session, fbox_handle, nem_fbox_fall_back_to_queue_count));
+        assert(nem_fbox_fall_back_to_queue_count[1] == 3);
+
+        /* Make sure we've posted the sends before the receiver gets a chance
+         * to receive them.
+         * FIXME: Ideally this should use a barrier, but that uses messages
+         *        internally and hence will sometimes screw up the asserts above.
+         */
+        sleep(1);   
+
+    } else if (rank == 1) {
+        char recv_buf[BUF_COUNT];
+        MPI_Status status;
+
+        sleep(1);   /* see above */
+
+        MPI_Recv(recv_buf, BUF_COUNT, MPI_CHAR, 0, 0, MPI_COMM_WORLD, &status);
+        MPI_Recv(recv_buf, BUF_COUNT, MPI_CHAR, 0, 0, MPI_COMM_WORLD, &status);
+        MPI_Recv(recv_buf, BUF_COUNT, MPI_CHAR, 0, 0, MPI_COMM_WORLD, &status);
+        MPI_Recv(recv_buf, BUF_COUNT, MPI_CHAR, 0, 0, MPI_COMM_WORLD, &status);
+    }
+
+    MPI_Barrier(MPI_COMM_WORLD);    /* ensure we've finished this test before
+                                     * moving on to the next */
+}
+
+/* By posting receives ahead of time, messages should be taken out of the
+ * fastbox as soon as they are delivered.  Hence, the counter should remain 0
+ * throughout.
+ * FIXME: This doesn't quite work yet, in part because of the barrier (which
+ *        also uses messages).  May want to 'sleep' between sends as a
+ *        workaround.
+ */
+void recv_first_test()
+{
+    uint64_t nem_fbox_fall_back_to_queue_count[2] = {-1};
+
+    /* Reset the fbox variable. */
+    MPI_T_pvar_write(session, fbox_handle, null_fbox);
+
+    if (rank == 0) {
+        char send_buf[BUF_COUNT] = { 0x12 };
+
+        MPI_Barrier(MPI_COMM_WORLD);    /* see below */
+
+        /* Check that the variable has been correctly initialized. */
+        TRY(MPI_T_pvar_read(session, fbox_handle, nem_fbox_fall_back_to_queue_count));
+        assert(nem_fbox_fall_back_to_queue_count[1] == 0);
+
+        MPI_Send(send_buf, BUF_COUNT, MPI_CHAR, 1, 0, MPI_COMM_WORLD);
+        TRY(MPI_T_pvar_read(session, fbox_handle, nem_fbox_fall_back_to_queue_count));
+        assert(nem_fbox_fall_back_to_queue_count[1] == 0);
+
+        MPI_Send(send_buf, BUF_COUNT, MPI_CHAR, 1, 0, MPI_COMM_WORLD);
+        TRY(MPI_T_pvar_read(session, fbox_handle, nem_fbox_fall_back_to_queue_count));
+        assert(nem_fbox_fall_back_to_queue_count[1] == 0);
+
+        MPI_Send(send_buf, BUF_COUNT, MPI_CHAR, 1, 0, MPI_COMM_WORLD);
+        TRY(MPI_T_pvar_read(session, fbox_handle, nem_fbox_fall_back_to_queue_count));
+        assert(nem_fbox_fall_back_to_queue_count[1] == 0);
+
+        MPI_Send(send_buf, BUF_COUNT, MPI_CHAR, 1, 0, MPI_COMM_WORLD);
+        TRY(MPI_T_pvar_read(session, fbox_handle, nem_fbox_fall_back_to_queue_count));
+        assert(nem_fbox_fall_back_to_queue_count[1] == 0);
+    } else if (rank == 1) {
+        char recv_buf[BUF_COUNT];
+        MPI_Request reqs[4];
+
+        MPI_Irecv(recv_buf, BUF_COUNT, MPI_CHAR, 0, 0, MPI_COMM_WORLD, &reqs[0]);
+        MPI_Irecv(recv_buf, BUF_COUNT, MPI_CHAR, 0, 0, MPI_COMM_WORLD, &reqs[1]);
+        MPI_Irecv(recv_buf, BUF_COUNT, MPI_CHAR, 0, 0, MPI_COMM_WORLD, &reqs[2]);
+        MPI_Irecv(recv_buf, BUF_COUNT, MPI_CHAR, 0, 0, MPI_COMM_WORLD, &reqs[3]);
+
+        MPI_Barrier(MPI_COMM_WORLD);    /* make sure we've posted the receives
+                                         * before the sender gets a chance
+                                         * to send them */
+
+        MPI_Status status[4];
+        MPI_Waitall(4, reqs, status);
+    }
+
+    MPI_Barrier(MPI_COMM_WORLD);    /* ensure we've finished this test before
+                                     * moving on to the next */
+}
+
+int main(int argc, char *argv[])
+{
+    int i, size, num, name_len, desc_len, count, verb, thread_support;
+    int varclass, bind, readonly, continuous, atomic, fbox_idx;
+    char name[STR_LEN], desc[STR_LEN];
+    MPI_Datatype dtype;
+    MPI_T_enum enumtype;
+
+    printf("MPIT pvar test: nem_fbox_fall_back_to_queue_count\n"); fflush(stdout);
+
+    MPI_Init(NULL, NULL);
+    MPI_Comm_size(MPI_COMM_WORLD, &size);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+
+    /* Ensure we're using exactly two ranks. */
+    assert(size == 2);
+
+    /* Standard MPIT initialization. */
+    TRY(MPI_T_init_thread(MPI_THREAD_SINGLE, &thread_support));
+    TRY(MPI_T_pvar_get_num(&num));
+
+    /* Locate desired MPIT variable. */
+    for (i = 0; i < num; i++) {
+        name_len = desc_len = STR_LEN;
+        TRY(MPI_T_pvar_get_info(i, name, &name_len, &verb, &varclass, &dtype,
+                                &enumtype, desc, &desc_len, &bind, &readonly,
+                                &continuous, &atomic));
+
+        if (strcmp(name, "nem_fbox_fall_back_to_queue_count") == 0)
+            fbox_idx = i;
+    }
+
+    /* Initialize MPIT session & variable handle. */
+    MPI_T_pvar_session_create(&session);
+    MPI_T_pvar_handle_alloc(session, fbox_idx, NULL, &fbox_handle, &count);
+
+    /* Ensure the variable is of the correct size. */
+    assert(count == 2);
+
+    /* Run a batch of tests. */
+    blank_test();
+    send_first_test();
+    /* recv_first_test(); */
+
+    /* Cleanup. */
+    MPI_T_pvar_handle_free(session, &fbox_handle);
+    MPI_T_pvar_session_free(&session);
+
+    TRY(MPI_T_finalize());
+    MPI_Finalize();
+
+    return 0;
+}
diff --git a/test/mpi_t/unexpected_recvq_buffer_size.c b/test/mpi_t/unexpected_recvq_buffer_size.c
new file mode 100644
index 0000000..de896cc
--- /dev/null
+++ b/test/mpi_t/unexpected_recvq_buffer_size.c
@@ -0,0 +1,138 @@
+#include <mpi.h>
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+
+#define TRY(func)                           \
+    do {                                    \
+        err = (func);                       \
+        if (err != MPI_SUCCESS)             \
+            MPI_Abort(MPI_COMM_WORLD, err); \
+    } while(0)
+
+#define EAGER_SIZE 10
+#define RNDV_SIZE  100000
+#define STR_LEN    100
+
+int err, rank;
+MPI_T_pvar_session session;
+MPI_T_pvar_handle uqsize_handle;
+
+/* The first receive will block waiting for the last send, since messages from
+ * a given rank are received in order. */
+void reversed_tags_test()
+{
+    size_t unexpected_recvq_buffer_size;
+
+    if (rank == 0) {
+        int send_buf[EAGER_SIZE] = { 0x1234 };
+
+        MPI_Send(send_buf, EAGER_SIZE, MPI_INT, 1, 0xA, MPI_COMM_WORLD);
+        MPI_Send(send_buf, EAGER_SIZE, MPI_INT, 1, 0xB, MPI_COMM_WORLD);
+        MPI_Send(send_buf, EAGER_SIZE, MPI_INT, 1, 0xC, MPI_COMM_WORLD);
+        MPI_Send(send_buf, EAGER_SIZE, MPI_INT, 1, 0xD, MPI_COMM_WORLD);
+    } else if (rank == 1) {
+        int recv_buf[EAGER_SIZE];
+        MPI_Status status;
+
+        MPI_Recv(recv_buf, EAGER_SIZE, MPI_INT, 0, 0xD, MPI_COMM_WORLD, &status);
+        TRY(MPI_T_pvar_read(session, uqsize_handle, &unexpected_recvq_buffer_size));
+        assert(unexpected_recvq_buffer_size == 3*EAGER_SIZE*sizeof(int));
+
+        MPI_Recv(recv_buf, EAGER_SIZE, MPI_INT, 0, 0xC, MPI_COMM_WORLD, &status);
+        TRY(MPI_T_pvar_read(session, uqsize_handle, &unexpected_recvq_buffer_size));
+        assert(unexpected_recvq_buffer_size == 2*EAGER_SIZE*sizeof(int));
+
+        MPI_Recv(recv_buf, EAGER_SIZE, MPI_INT, 0, 0xB, MPI_COMM_WORLD, &status);
+        TRY(MPI_T_pvar_read(session, uqsize_handle, &unexpected_recvq_buffer_size));
+        assert(unexpected_recvq_buffer_size == 1*EAGER_SIZE*sizeof(int));
+
+        MPI_Recv(recv_buf, EAGER_SIZE, MPI_INT, 0, 0xA, MPI_COMM_WORLD, &status);
+        TRY(MPI_T_pvar_read(session, uqsize_handle, &unexpected_recvq_buffer_size));
+        assert(unexpected_recvq_buffer_size == 0*EAGER_SIZE*sizeof(int));
+    }
+
+    MPI_Barrier(MPI_COMM_WORLD);  /* make sure this test is over before going to the next one */
+}
+
+/* Rendezvous-based messages will never be unexpected (except for the initial RTS,
+ * which has an empty buffer anyhow).
+ */
+void rndv_test()
+{
+    size_t unexpected_recvq_buffer_size;
+
+    if (rank == 0) {
+        int send_buf[RNDV_SIZE] = { 0x5678 };
+
+        MPI_Send(send_buf, RNDV_SIZE, MPI_INT, 1, 0, MPI_COMM_WORLD);
+        MPI_Send(send_buf, RNDV_SIZE, MPI_INT, 1, 0, MPI_COMM_WORLD);
+    } else if (rank == 1) {
+        int recv_buf[RNDV_SIZE];
+        MPI_Status status;
+
+        MPI_Recv(recv_buf, RNDV_SIZE, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
+        TRY(MPI_T_pvar_read(session, uqsize_handle, &unexpected_recvq_buffer_size));
+        assert(unexpected_recvq_buffer_size == 0);
+
+        MPI_Recv(recv_buf, RNDV_SIZE, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
+        TRY(MPI_T_pvar_read(session, uqsize_handle, &unexpected_recvq_buffer_size));
+        assert(unexpected_recvq_buffer_size == 0);
+    }
+
+    MPI_Barrier(MPI_COMM_WORLD);  /* make sure this test is over before going to the next one */
+}
+
+int main(int argc, char *argv[])
+{
+    int i, size, num, name_len, desc_len, verb, thread_support;
+    int varclass, bind, readonly, continuous, atomic, uqsize_idx, count;
+    char name[STR_LEN], desc[STR_LEN];
+    MPI_Datatype dtype;
+    MPI_T_enum enumtype;
+
+    printf("MPIT pvar test: unexpected_recvq_buffer_size\n"); fflush(stdout);
+
+    MPI_Init(NULL, NULL);
+    MPI_Comm_size(MPI_COMM_WORLD, &size);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+
+    /* Ensure we're using exactly two ranks. */
+    /* Future tests (using collectives) might need this because of the MPI_Barrier */
+    assert(size == 2);
+
+    /* Standard MPIT initialization. */
+    TRY(MPI_T_init_thread(MPI_THREAD_SINGLE, &thread_support));
+    TRY(MPI_T_pvar_get_num(&num));
+
+    /* Locate desired MPIT variable. */
+    for (i = 0; i < num; i++) {
+        name_len = desc_len = STR_LEN;
+        TRY(MPI_T_pvar_get_info(i, name, &name_len, &verb, &varclass, &dtype,
+                                &enumtype, desc, &desc_len, &bind, &readonly,
+                                &continuous, &atomic));
+
+        if (strcmp(name, "unexpected_recvq_buffer_size") == 0)
+            uqsize_idx = i;
+    }
+
+    /* Initialize MPIT session & variable handle. */
+    MPI_T_pvar_session_create(&session);
+    MPI_T_pvar_handle_alloc(session, uqsize_idx, NULL, &uqsize_handle, &count);
+
+    /* Ensure the variable is of the correct size. */
+    assert(count == 1);
+
+    /* Run a batch of tests. */
+    reversed_tags_test();
+    rndv_test();
+
+    /* Cleanup. */
+    MPI_T_pvar_handle_free(session, &uqsize_handle);
+    MPI_T_pvar_session_free(&session);
+
+    TRY(MPI_T_finalize());
+    MPI_Finalize();
+
+    return 0;
+}

http://git.mpich.org/mpich.git/commitdiff/2cfb60178370094f4df8ba43e535f987ff405bb3

commit 2cfb60178370094f4df8ba43e535f987ff405bb3
Author: Ralf Gunter <ralfgunter at gmail.com>
Date:   Thu Nov 29 14:25:05 2012 -0600

    MPI_T_pvar_read/write now respect the handle creator's count variable

diff --git a/src/mpi_t/pvar_handle_alloc.c b/src/mpi_t/pvar_handle_alloc.c
index e26316f..e61ce49 100644
--- a/src/mpi_t/pvar_handle_alloc.c
+++ b/src/mpi_t/pvar_handle_alloc.c
@@ -61,6 +61,9 @@ int MPIR_T_pvar_handle_alloc_impl(MPI_T_pvar_session session, int pvar_index, vo
     mpi_errno = info->create_fn(obj_handle, (*handle), count);
     if (mpi_errno) MPIU_ERR_POP(mpi_errno);
 
+    /* some creator functions may not assign this */
+    (*handle)->count = *count;
+
     MPL_DL_APPEND(session->hlist, *handle);
 
     MPIU_CHKPMEM_COMMIT();
diff --git a/src/mpi_t/pvar_read.c b/src/mpi_t/pvar_read.c
index aaf9e8a..34d7041 100644
--- a/src/mpi_t/pvar_read.c
+++ b/src/mpi_t/pvar_read.c
@@ -35,7 +35,7 @@ int MPIR_T_pvar_read_impl(MPI_T_pvar_session session, MPI_T_pvar_handle handle,
     /* the extra indirection through "info" might be too costly for some tools,
      * consider moving this value to or caching it in the handle itself */
     if (likely(handle->info->impl_kind == MPIR_T_PVAR_IMPL_SIMPLE)) {
-        MPIU_Memcpy(buf, handle->handle_state, handle->bytes);
+        MPIU_Memcpy(buf, handle->handle_state, handle->count * handle->bytes);
     }
     else {
         MPIU_Assertp(FALSE); /* _IMPL_CB not yet implemented */
diff --git a/src/mpi_t/pvar_write.c b/src/mpi_t/pvar_write.c
index 2c7781c..26f4ecb 100644
--- a/src/mpi_t/pvar_write.c
+++ b/src/mpi_t/pvar_write.c
@@ -37,7 +37,7 @@ int MPIR_T_pvar_write_impl(MPI_T_pvar_session session, MPI_T_pvar_handle handle,
     /* the extra indirection through "info" might be too costly for some tools,
      * consider moving this value to or caching it in the handle itself */
     if (likely(handle->info->impl_kind == MPIR_T_PVAR_IMPL_SIMPLE)) {
-        MPIU_Memcpy(handle->handle_state, buf, handle->bytes);
+        MPIU_Memcpy(handle->handle_state, buf, handle->count * handle->bytes);
     }
     else {
         MPIU_Assertp(FALSE); /* _IMPL_CB not yet implemented */

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

commit d6b69b468128c0c356db2d31e8fd4ca0414c3ea4
Author: Dave Goodell <goodell at mcs.anl.gov>
Date:   Tue Jan 22 14:38:31 2013 -0600

    move MPI_T tests to their own subdir in "manual"
    
    Reviewed-by: rgunter

diff --git a/test/mpi/manual/Makefile.am b/test/mpi/manual/Makefile.am
index d466feb..4ba8d9e 100644
--- a/test/mpi/manual/Makefile.am
+++ b/test/mpi/manual/Makefile.am
@@ -7,9 +7,10 @@
 
 include $(top_srcdir)/Makefile.mtest
 
+SUBDIRS = mpi_t
+
 noinst_PROGRAMS = singjoin testconnect testconnectserial dimsbalanced \
-                  spawntest_master spawntest_child segfault \
-                  mpit_test mpit_test2
+                  spawntest_master spawntest_child segfault
 
 # testconnectserial would like MPICHLIBSTR to be defined as the installation
 # directory of the MPI library.  This definition is not required.
diff --git a/test/mpi/manual/mpi_t/Makefile.am b/test/mpi/manual/mpi_t/Makefile.am
new file mode 100644
index 0000000..3f84934
--- /dev/null
+++ b/test/mpi/manual/mpi_t/Makefile.am
@@ -0,0 +1,11 @@
+## -*- Mode: Makefile; -*-
+## vim: set ft=automake :
+##
+## (C) 2013 by Argonne National Laboratory.
+##     See COPYRIGHT in top-level directory.
+##
+
+include $(top_srcdir)/Makefile.mtest
+
+noinst_PROGRAMS = mpit_test mpit_test2
+
diff --git a/test/mpi/manual/mpit_test.c b/test/mpi/manual/mpi_t/mpit_test.c
similarity index 100%
rename from test/mpi/manual/mpit_test.c
rename to test/mpi/manual/mpi_t/mpit_test.c
diff --git a/test/mpi/manual/mpit_test2.c b/test/mpi/manual/mpi_t/mpit_test2.c
similarity index 100%
rename from test/mpi/manual/mpit_test2.c
rename to test/mpi/manual/mpi_t/mpit_test2.c

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

Summary of changes:
 configure.ac                                       |   51 +++++
 src/mpi_t/pvar_handle_alloc.c                      |    3 +
 src/mpi_t/pvar_read.c                              |    2 +-
 src/mpi_t/pvar_write.c                             |    2 +-
 .../ch3/channels/nemesis/include/mpid_nem_inline.h |    5 +
 .../nemesis/include/mpidi_nem_statistics.h         |   15 ++
 .../ch3/channels/nemesis/src/mpid_nem_finalize.c   |    6 +
 src/mpid/ch3/channels/nemesis/src/mpid_nem_init.c  |   47 ++++
 src/mpid/ch3/include/mpidi_common_statistics.h     |   71 ++++++
 src/mpid/ch3/include/mpidi_recvq_statistics.h      |   16 ++
 src/mpid/ch3/src/ch3u_eager.c                      |    2 +
 src/mpid/ch3/src/ch3u_handle_recv_pkt.c            |    4 +
 src/mpid/ch3/src/ch3u_recvq.c                      |  197 +++++++++++------
 test/mpi/configure.ac                              |    1 +
 test/mpi/manual/Makefile.am                        |    5 +-
 test/mpi/manual/mpi_t/Makefile.am                  |   15 ++
 test/mpi/manual/{ => mpi_t}/mpit_test.c            |    0
 test/mpi/manual/{ => mpi_t}/mpit_test2.c           |    0
 .../mpi_t/nem_fbox_fallback_to_queue_count.c       |  231 ++++++++++++++++++++
 .../manual/mpi_t/unexpected_recvq_buffer_size.c    |  158 +++++++++++++
 20 files changed, 761 insertions(+), 70 deletions(-)
 create mode 100644 src/mpid/ch3/channels/nemesis/include/mpidi_nem_statistics.h
 create mode 100644 src/mpid/ch3/include/mpidi_common_statistics.h
 create mode 100644 src/mpid/ch3/include/mpidi_recvq_statistics.h
 create mode 100644 test/mpi/manual/mpi_t/Makefile.am
 rename test/mpi/manual/{ => mpi_t}/mpit_test.c (100%)
 rename test/mpi/manual/{ => mpi_t}/mpit_test2.c (100%)
 create mode 100644 test/mpi/manual/mpi_t/nem_fbox_fallback_to_queue_count.c
 create mode 100644 test/mpi/manual/mpi_t/unexpected_recvq_buffer_size.c


hooks/post-receive
-- 
MPICH primary repository


More information about the commits mailing list