root/orte/test/mpi/mpi_spin.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. _event_fn
  2. _register_fn
  3. main

   1 /* -*- C -*-
   2  *
   3  * $HEADER$
   4  *
   5  * A program that just spins - provides mechanism for testing user-driven
   6  * abnormal program termination
   7  */
   8 
   9 #include <stdio.h>
  10 #include "mpi.h"
  11 
  12 #include "opal/dss/dss.h"
  13 #include "opal/mca/pmix/pmix.h"
  14 #include "opal/util/output.h"
  15 #include "orte/util/name_fns.h"
  16 #include "orte/constants.h"
  17 
  18 static volatile bool register_active = false;
  19 
  20 static void _event_fn(int status,
  21                       const opal_process_name_t *source,
  22                       opal_list_t *info, opal_list_t *results,
  23                       opal_pmix_notification_complete_fn_t cbfunc,
  24                       void *cbdata)
  25 {
  26     opal_value_t *kv;
  27     orte_process_name_t proc;
  28 
  29     /* the name of the terminating proc should be on the info list */
  30     proc.jobid = ORTE_JOBID_INVALID;
  31     proc.vpid = ORTE_VPID_INVALID;
  32     OPAL_LIST_FOREACH(kv, info, opal_value_t) {
  33         if (0 == strcmp(kv->key, OPAL_PMIX_EVENT_AFFECTED_PROC)) {
  34             proc.jobid = kv->data.name.jobid;
  35             proc.vpid = kv->data.name.vpid;
  36             break;
  37         }
  38     }
  39 
  40     opal_output(0, "NOTIFIED OF TERMINATION OF PROC %s",
  41                 ORTE_NAME_PRINT(&proc));
  42 
  43     /* must let the notifier know we are done */
  44     if (NULL != cbfunc) {
  45         cbfunc(ORTE_SUCCESS, NULL, NULL, NULL, cbdata);
  46     }
  47 }
  48 
  49 static void _register_fn(int status,
  50                          size_t evhandler_ref,
  51                          void *cbdata)
  52 {
  53     opal_list_t *codes = (opal_list_t*)cbdata;
  54 
  55     OPAL_LIST_RELEASE(codes);
  56     register_active = false;
  57 }
  58 
  59 
  60 int main(int argc, char* argv[])
  61 {
  62 
  63     int i;
  64     double pi;
  65     opal_list_t *codes;
  66     opal_value_t *kv;
  67 
  68     MPI_Init(&argc, &argv);
  69 
  70     /* register an event handler for the OPAL_ERR_PROC_ABORTED event */
  71     codes = OBJ_NEW(opal_list_t);
  72     kv = OBJ_NEW(opal_value_t);
  73     kv->key = strdup("errorcode");
  74     kv->type = OPAL_INT;
  75     kv->data.integer = OPAL_ERR_PROC_ABORTED;
  76     opal_list_append(codes, &kv->super);
  77 
  78     register_active = true;
  79     opal_pmix.register_evhandler(codes, NULL, _event_fn, _register_fn, codes);
  80 
  81     i = 0;
  82     while (1) {
  83         i++;
  84         pi = i / 3.14159256;
  85         if (i > 100) i = 0;
  86     }
  87 
  88     MPI_Finalize();
  89 
  90     return 0;
  91 }

/* [<][>][^][v][top][bottom][index][help] */