|
| 1 | +/* -*- C -*- |
| 2 | + * |
| 3 | + * $HEADER$ |
| 4 | + * |
| 5 | + * The most basic of MPI applications |
| 6 | + */ |
| 7 | + |
| 8 | +#include "orte_config.h" |
| 9 | + |
| 10 | +#include <stdio.h> |
| 11 | +#include "mpi.h" |
| 12 | +#include "opal/mca/pmix/pmix.h" |
| 13 | +#include "orte/runtime/runtime.h" |
| 14 | +#include "orte/util/proc_info.h" |
| 15 | +#include "orte/util/name_fns.h" |
| 16 | +#include "orte/runtime/orte_globals.h" |
| 17 | +#include "orte/mca/errmgr/errmgr.h" |
| 18 | + |
| 19 | +static volatile int active; |
| 20 | +static volatile bool wait_for_release = true; |
| 21 | +#define MEMPROBE_RELEASE 12345 |
| 22 | + |
| 23 | +static void _release_fn(int status, |
| 24 | + const opal_process_name_t *source, |
| 25 | + opal_list_t *info, opal_list_t *results, |
| 26 | + opal_pmix_notification_complete_fn_t cbfunc, |
| 27 | + void *cbdata) |
| 28 | +{ |
| 29 | + /* must let the notifier know we are done */ |
| 30 | + if (NULL != cbfunc) { |
| 31 | + cbfunc(0, NULL, NULL, NULL, cbdata); |
| 32 | + } |
| 33 | + /* flag that the debugger is complete so we can exit */ |
| 34 | + wait_for_release = false; |
| 35 | +} |
| 36 | + |
| 37 | +static void _register_fn(int status, |
| 38 | + size_t evhandler_ref, |
| 39 | + void *cbdata) |
| 40 | +{ |
| 41 | + volatile int *active = (volatile int*)cbdata; |
| 42 | + |
| 43 | + if (0 != status) { |
| 44 | + fprintf(stderr, "Client EVENT HANDLER REGISTRATION FAILED WITH STATUS %d, ref=%lu\n", |
| 45 | + status, (unsigned long)evhandler_ref); |
| 46 | + } |
| 47 | + *active = status; |
| 48 | +} |
| 49 | + |
| 50 | +int main(int argc, char* argv[]) |
| 51 | +{ |
| 52 | + int rank, size; |
| 53 | + opal_list_t *codes; |
| 54 | + opal_value_t *kv; |
| 55 | + |
| 56 | + MPI_Init(&argc, &argv); |
| 57 | + MPI_Comm_rank(MPI_COMM_WORLD, &rank); |
| 58 | + MPI_Comm_size(MPI_COMM_WORLD, &size); |
| 59 | + |
| 60 | + if (0 == rank) { |
| 61 | + fprintf(stderr, "Sampling memory usage after MPI_Init\n"); |
| 62 | + } |
| 63 | + |
| 64 | + codes = OBJ_NEW(opal_list_t); |
| 65 | + kv = OBJ_NEW(opal_value_t); |
| 66 | + kv->key = strdup("errorcode"); |
| 67 | + kv->type = OPAL_INT; |
| 68 | + kv->data.integer = MEMPROBE_RELEASE; |
| 69 | + opal_list_append(codes, &kv->super); |
| 70 | + |
| 71 | + active = -1; |
| 72 | + opal_pmix.register_evhandler(codes, NULL, _release_fn, _register_fn, (void*)&active); |
| 73 | + while (-1 == active) { |
| 74 | + usleep(10); |
| 75 | + } |
| 76 | + |
| 77 | + /* now wait for notification */ |
| 78 | + while (wait_for_release) { |
| 79 | + usleep(10); |
| 80 | + } |
| 81 | + wait_for_release = true; |
| 82 | + |
| 83 | + /* perform a barrier so some communication will occur, thus |
| 84 | + * requiring exchange of endpoint info */ |
| 85 | + MPI_Barrier(MPI_COMM_WORLD); |
| 86 | + |
| 87 | + if (0 == rank) { |
| 88 | + fprintf(stderr, "\n\nSampling memory usage after MPI_Barrier\n"); |
| 89 | + } |
| 90 | + |
| 91 | + /* wait again while memory is sampled */ |
| 92 | + while (wait_for_release) { |
| 93 | + usleep(10); |
| 94 | + } |
| 95 | + |
| 96 | + MPI_Finalize(); |
| 97 | + return 0; |
| 98 | +} |
0 commit comments