2015-01-27 11:55:24 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Mellanox Technologies, Inc.
|
|
|
|
* All rights reserved.
|
2016-10-14 01:25:16 +03:00
|
|
|
* Copyright (c) 2016 Intel, Inc. All rights reserved.
|
2015-01-27 11:55:24 +03:00
|
|
|
* $COPYRIGHT$
|
2015-06-24 06:59:57 +03:00
|
|
|
*
|
2015-01-27 11:55:24 +03:00
|
|
|
* Additional copyrights may follow
|
2015-06-24 06:59:57 +03:00
|
|
|
*
|
2015-01-27 11:55:24 +03:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* To compile test:
|
|
|
|
* mpicc -I$src_dir -I$src_dir/opal/include -I$src_dir/orte/include -I$src_dir/ompi/include -DOMPI_BUILDING=1 pmix.c -o pmix
|
|
|
|
* To run test:
|
|
|
|
* mpirun -np 2 <any mca params> ./pmix
|
|
|
|
* Test should print "Passed" in case of success and print pmix time intervals at process with rank 0.
|
|
|
|
* */
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <mpi.h>
|
2016-10-14 01:25:16 +03:00
|
|
|
#include <time.h>
|
2015-01-27 11:55:24 +03:00
|
|
|
#include <sys/time.h>
|
|
|
|
|
2016-10-14 01:25:16 +03:00
|
|
|
#include "opal/class/opal_list.h"
|
2015-01-27 11:55:24 +03:00
|
|
|
#include "opal/mca/pmix/pmix.h"
|
|
|
|
#include "ompi/proc/proc.h"
|
|
|
|
|
|
|
|
#define DO_FINALIZE(rc,flag,format,args...) \
|
|
|
|
do { \
|
|
|
|
if (flag) { \
|
|
|
|
fprintf(stderr, format, args); \
|
|
|
|
} \
|
|
|
|
MPI_Finalize(); \
|
|
|
|
return rc; \
|
|
|
|
} while(0);
|
|
|
|
|
2016-10-14 01:25:16 +03:00
|
|
|
static int my_rank;
|
|
|
|
static volatile bool waiting = true;
|
|
|
|
|
|
|
|
static double get_timestamp(void)
|
2015-01-27 11:55:24 +03:00
|
|
|
{
|
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
return ((tv.tv_sec) + (tv.tv_usec) * 1.0e-6);
|
|
|
|
}
|
|
|
|
|
2016-10-14 01:25:16 +03:00
|
|
|
static void evhandler(int status,
|
|
|
|
const opal_process_name_t *source,
|
|
|
|
opal_list_t *info, opal_list_t *results,
|
|
|
|
opal_pmix_notification_complete_fn_t cbfunc,
|
|
|
|
void *cbdata)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%d: received notification status %d\n", my_rank, status);
|
|
|
|
if (NULL != cbfunc) {
|
|
|
|
cbfunc(OPAL_ERR_HANDLERS_COMPLETE, NULL, NULL, NULL, cbdata);
|
|
|
|
}
|
|
|
|
waiting = false;
|
|
|
|
}
|
|
|
|
|
2015-01-27 11:55:24 +03:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2016-10-14 01:25:16 +03:00
|
|
|
int rc;
|
2015-01-27 11:55:24 +03:00
|
|
|
int recv_data;
|
|
|
|
size_t i, numprocs;
|
|
|
|
ompi_proc_t **procs, *thisproc;
|
2015-03-06 11:33:14 +03:00
|
|
|
double t0, t1, t2, t3, t4, t5, t6;
|
2015-01-27 11:55:24 +03:00
|
|
|
int *ptr;
|
2016-10-14 01:25:16 +03:00
|
|
|
struct timespec tp;
|
|
|
|
opal_list_t info;
|
|
|
|
opal_value_t *kv;
|
2015-01-27 11:55:24 +03:00
|
|
|
|
|
|
|
MPI_Init(&argc, &argv);
|
|
|
|
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
|
2016-10-14 01:25:16 +03:00
|
|
|
|
|
|
|
/* register an event */
|
|
|
|
OBJ_CONSTRUCT(&info, opal_list_t);
|
|
|
|
kv = OBJ_NEW(opal_value_t);
|
|
|
|
kv->key = strdup(OPAL_PMIX_EVENT_ORDER_PREPEND);
|
|
|
|
opal_list_append(&info, &kv->super);
|
|
|
|
opal_pmix.register_evhandler(NULL, &info, evhandler, NULL, NULL);
|
2015-06-24 06:59:57 +03:00
|
|
|
|
2015-01-27 11:55:24 +03:00
|
|
|
int data = my_rank;
|
|
|
|
t0 = get_timestamp();
|
2016-10-14 01:25:16 +03:00
|
|
|
OPAL_MODEX_SEND_VALUE(rc, OPAL_PMIX_GLOBAL, "MY_RANK", &data, OPAL_INT);
|
2015-01-27 11:55:24 +03:00
|
|
|
t1 = get_timestamp();
|
|
|
|
if (OPAL_SUCCESS != rc) {
|
|
|
|
DO_FINALIZE(rc, 1, "[%d] OPAL_MODEX_SEND_STRING failed.\n", my_rank);
|
|
|
|
}
|
|
|
|
t2 = get_timestamp();
|
2016-10-14 01:25:16 +03:00
|
|
|
opal_pmix.commit();
|
|
|
|
opal_pmix.fence(NULL, 1);
|
2015-01-27 11:55:24 +03:00
|
|
|
t3 = get_timestamp();
|
|
|
|
procs = ompi_proc_world ( &numprocs );
|
|
|
|
ptr = &recv_data;
|
|
|
|
t4 = get_timestamp();
|
|
|
|
for ( i = 0; i < numprocs; i++ ) {
|
|
|
|
thisproc = procs[i];
|
2016-10-14 01:25:16 +03:00
|
|
|
OPAL_MODEX_RECV_VALUE(rc, "MY_RANK", &thisproc->super.proc_name, (void**)&ptr, OPAL_INT);
|
2015-01-27 11:55:24 +03:00
|
|
|
/* check return status and received data */
|
|
|
|
if (OPAL_SUCCESS != rc || i != recv_data) {
|
|
|
|
rc = OPAL_ERROR;
|
|
|
|
DO_FINALIZE(rc, 1, "[%d] OPAL_MODEX_RECV_VALUE failed from rank %d.\n", my_rank, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
t5 = get_timestamp();
|
2015-06-24 06:59:57 +03:00
|
|
|
|
2015-01-27 11:55:24 +03:00
|
|
|
/* using fence as a barrier */
|
|
|
|
opal_pmix.fence(NULL, 0);
|
2015-03-06 11:33:14 +03:00
|
|
|
t6 = get_timestamp();
|
|
|
|
|
2015-02-02 15:15:55 +03:00
|
|
|
fprintf(stderr, "[%d] Test passed.\n", my_rank);
|
|
|
|
fprintf(stderr, "[%d] \"MODEX_SEND\" %f\n", my_rank, t1-t0);
|
|
|
|
fprintf(stderr, "[%d] \"FENCE\" %f\n", my_rank, t3-t2);
|
|
|
|
fprintf(stderr, "[%d] \"MODEX_RECV\" %f\n", my_rank, t5-t4);
|
2015-03-06 11:33:14 +03:00
|
|
|
fprintf(stderr, "[%d] \"BARRIER\" %f\n", my_rank, t6-t5);
|
|
|
|
fprintf(stderr, "[%d] \"TOTAL\" %f\n", my_rank, t6-t0);
|
2015-02-02 15:15:55 +03:00
|
|
|
|
2016-10-14 01:25:16 +03:00
|
|
|
fprintf(stderr, "[%d] Pid %d waiting for notification\n", my_rank, (int)getpid());
|
|
|
|
|
|
|
|
/* now wait for notification of someone failing */
|
|
|
|
tp.tv_sec = 0;
|
|
|
|
tp.tv_nsec = 100000;
|
|
|
|
waiting = true;
|
|
|
|
while (waiting) {
|
|
|
|
nanosleep(&tp, NULL);
|
|
|
|
}
|
|
|
|
free(procs);
|
|
|
|
|
2015-01-27 11:55:24 +03:00
|
|
|
DO_FINALIZE(0, 0, 0, 0);
|
|
|
|
}
|