This source file includes following definitions.
- get_timestamp
- evhandler
- main
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 
  14 
  15 
  16 
  17 
  18 #include <stdio.h>
  19 #include <unistd.h>
  20 #include <mpi.h>
  21 #include <time.h>
  22 #include <sys/time.h>
  23 
  24 #include "opal/class/opal_list.h"
  25 #include "opal/mca/pmix/pmix.h"
  26 #include "ompi/proc/proc.h"
  27 
  28 #define DO_FINALIZE(rc,flag,format,args...) \
  29     do {                                    \
  30         if (flag) {                         \
  31             fprintf(stderr, format, args);  \
  32         }                                   \
  33         MPI_Finalize();                     \
  34         return rc;                          \
  35     } while(0);
  36 
  37 static int my_rank;
  38 static volatile bool waiting = true;
  39 
  40 static double get_timestamp(void)
  41 {
  42     struct timeval tv;
  43     gettimeofday(&tv, NULL);
  44     return ((tv.tv_sec) + (tv.tv_usec) * 1.0e-6);
  45 }
  46 
  47 static void evhandler(int status,
  48                       const opal_process_name_t *source,
  49                       opal_list_t *info, opal_list_t *results,
  50                       opal_pmix_notification_complete_fn_t cbfunc,
  51                       void *cbdata)
  52 {
  53     fprintf(stderr, "%d: received notification status %d\n", my_rank, status);
  54     if (NULL != cbfunc) {
  55         cbfunc(OPAL_ERR_HANDLERS_COMPLETE, NULL, NULL, NULL, cbdata);
  56     }
  57     waiting = false;
  58 }
  59 
  60 int main(int argc, char* argv[])
  61 {
  62     int rc;
  63     int recv_data;
  64     size_t i, numprocs;
  65     ompi_proc_t **procs, *thisproc;
  66     double t0, t1, t2, t3, t4, t5, t6;
  67     int *ptr;
  68     struct timespec tp;
  69     opal_list_t info;
  70     opal_value_t *kv;
  71 
  72     MPI_Init(&argc, &argv);
  73     MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
  74 
  75     
  76     OBJ_CONSTRUCT(&info, opal_list_t);
  77     kv = OBJ_NEW(opal_value_t);
  78     kv->key = strdup(OPAL_PMIX_EVENT_ORDER_PREPEND);
  79     opal_list_append(&info, &kv->super);
  80     opal_pmix.register_evhandler(NULL, &info, evhandler, NULL, NULL);
  81 
  82     int data = my_rank;
  83     t0 = get_timestamp();
  84     OPAL_MODEX_SEND_VALUE(rc, OPAL_PMIX_GLOBAL, "MY_RANK", &data, OPAL_INT);
  85     t1 = get_timestamp();
  86     if (OPAL_SUCCESS != rc) {
  87         DO_FINALIZE(rc, 1, "[%d] OPAL_MODEX_SEND_STRING failed.\n", my_rank);
  88     }
  89     t2 = get_timestamp();
  90     opal_pmix.commit();
  91     opal_pmix.fence(NULL, 1);
  92     t3 = get_timestamp();
  93     procs = ompi_proc_world ( &numprocs );
  94     ptr = &recv_data;
  95     t4 = get_timestamp();
  96     for ( i = 0; i < numprocs; i++ ) {
  97         thisproc = procs[i];
  98         OPAL_MODEX_RECV_VALUE(rc, "MY_RANK", &thisproc->super.proc_name, (void**)&ptr, OPAL_INT);
  99         
 100         if (OPAL_SUCCESS != rc || i != recv_data) {
 101             rc = OPAL_ERROR;
 102             DO_FINALIZE(rc, 1, "[%d] OPAL_MODEX_RECV_VALUE failed from rank %d.\n", my_rank, i);
 103         }
 104     }
 105     t5 = get_timestamp();
 106 
 107     
 108     opal_pmix.fence(NULL, 0);
 109     t6 = get_timestamp();
 110 
 111     fprintf(stderr, "[%d] Test passed.\n", my_rank);
 112     fprintf(stderr, "[%d] \"MODEX_SEND\" %f\n", my_rank, t1-t0);
 113     fprintf(stderr, "[%d] \"FENCE\" %f\n", my_rank, t3-t2);
 114     fprintf(stderr, "[%d] \"MODEX_RECV\" %f\n", my_rank, t5-t4);
 115     fprintf(stderr, "[%d] \"BARRIER\" %f\n", my_rank, t6-t5);
 116     fprintf(stderr, "[%d] \"TOTAL\" %f\n", my_rank, t6-t0);
 117 
 118     fprintf(stderr, "[%d] Pid %d waiting for notification\n", my_rank, (int)getpid());
 119 
 120     
 121     tp.tv_sec = 0;
 122     tp.tv_nsec = 100000;
 123     waiting = true;
 124     while (waiting) {
 125         nanosleep(&tp, NULL);
 126     }
 127     free(procs);
 128 
 129     DO_FINALIZE(0, 0, 0, 0);
 130 }