root/opal/mca/pmix/pmix4x/pmix/test/simple/simpdyn.c

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

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /*
   2  * Copyright (c) 2004-2010 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2011 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2006-2013 Los Alamos National Security, LLC.
  13  *                         All rights reserved.
  14  * Copyright (c) 2009-2012 Cisco Systems, Inc.  All rights reserved.
  15  * Copyright (c) 2011      Oak Ridge National Labs.  All rights reserved.
  16  * Copyright (c) 2013-2018 Intel, Inc. All rights reserved.
  17  * Copyright (c) 2015      Mellanox Technologies, Inc.  All rights reserved.
  18  * $COPYRIGHT$
  19  *
  20  * Additional copyrights may follow
  21  *
  22  * $HEADER$
  23  *
  24  */
  25 
  26 #include <src/include/pmix_config.h>
  27 #include <pmix.h>
  28 
  29 #include <stdio.h>
  30 #include <stdlib.h>
  31 #include <unistd.h>
  32 #include <time.h>
  33 
  34 #include "src/class/pmix_object.h"
  35 #include "src/util/argv.h"
  36 #include "src/util/output.h"
  37 #include "src/util/pmix_environ.h"
  38 #include "src/util/printf.h"
  39 
  40 static pmix_proc_t myproc;
  41 
  42 int main(int argc, char **argv)
  43 {
  44     int rc;
  45     pmix_value_t value;
  46     pmix_value_t *val = &value;
  47     pmix_proc_t proc;
  48     uint32_t nprocs;
  49     char nsp2[PMIX_MAX_NSLEN+1];
  50     pmix_app_t *app;
  51     char hostname[PMIX_MAXHOSTNAMELEN];
  52     pmix_proc_t *peers;
  53     size_t npeers, ntmp=0;
  54     char *nodelist;
  55 
  56     gethostname(hostname, sizeof(hostname));
  57 
  58     /* init us */
  59     if (PMIX_SUCCESS != (rc = PMIx_Init(&myproc, NULL, 0))) {
  60         pmix_output(0, "Client ns %s rank %d: PMIx_Init failed: %d", myproc.nspace, myproc.rank, rc);
  61         exit(0);
  62     }
  63     pmix_output(0, "Client ns %s rank %d: Running", myproc.nspace, myproc.rank);
  64 
  65     /* get our universe size */
  66     (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
  67     proc.rank = PMIX_RANK_WILDCARD;
  68     if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, PMIX_UNIV_SIZE, NULL, 0, &val))) {
  69         pmix_output(0, "Client ns %s rank %d: PMIx_Get universe size failed: %d", myproc.nspace, myproc.rank, rc);
  70         goto done;
  71     }
  72     nprocs = val->data.uint32;
  73     PMIX_VALUE_RELEASE(val);
  74     pmix_output(0, "Client %s:%d universe size %d", myproc.nspace, myproc.rank, nprocs);
  75 
  76     /* call fence to sync */
  77     PMIX_PROC_CONSTRUCT(&proc);
  78     (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
  79     proc.rank = PMIX_RANK_WILDCARD;
  80     if (PMIX_SUCCESS != (rc = PMIx_Fence(&proc, 1, NULL, 0))) {
  81         pmix_output(0, "Client ns %s rank %d: PMIx_Fence failed: %d", myproc.nspace, myproc.rank, rc);
  82         goto done;
  83     }
  84 
  85     /* rank=0 calls spawn */
  86     if (0 == myproc.rank) {
  87         PMIX_APP_CREATE(app, 1);
  88         app->cmd = strdup("gumby");
  89         app->maxprocs = 2;
  90         pmix_argv_append_nosize(&app->argv, "gumby");
  91         pmix_argv_append_nosize(&app->argv, "-n");
  92         pmix_argv_append_nosize(&app->argv, "2");
  93         pmix_setenv("PMIX_ENV_VALUE", "3", true, &app->env);
  94         PMIX_INFO_CREATE(app->info, 2);
  95         (void)strncpy(app->info[0].key, "DARTH", PMIX_MAX_KEYLEN);
  96         app->info[0].value.type = PMIX_INT8;
  97         app->info[0].value.data.int8 = 12;
  98         (void)strncpy(app->info[1].key, "VADER", PMIX_MAX_KEYLEN);
  99         app->info[1].value.type = PMIX_DOUBLE;
 100         app->info[1].value.data.dval = 12.34;
 101 
 102         pmix_output(0, "Client ns %s rank %d: calling PMIx_Spawn", myproc.nspace, myproc.rank);
 103         if (PMIX_SUCCESS != (rc = PMIx_Spawn(NULL, 0, app, 1, nsp2))) {
 104             pmix_output(0, "Client ns %s rank %d: PMIx_Spawn failed: %d", myproc.nspace, myproc.rank, rc);
 105             goto done;
 106         }
 107         PMIX_APP_FREE(app, 1);
 108 
 109         /* check to see if we got the expected info back */
 110         if (0 != strncmp(nsp2, "DYNSPACE", PMIX_MAX_NSLEN)) {
 111             pmix_output(0, "Client ns %s rank %d: PMIx_Spawn returned incorrect nspace: %s", myproc.nspace, myproc.rank, nsp2);
 112             goto done;
 113         } else {
 114             pmix_output(0, "Client ns %s rank %d: PMIx_Spawn succeeded returning nspace: %s", myproc.nspace, myproc.rank, nsp2);
 115         }
 116         /* get their universe size */
 117         (void)strncpy(proc.nspace, nsp2, PMIX_MAX_NSLEN);
 118         proc.rank = PMIX_RANK_WILDCARD;
 119         val = NULL;
 120         if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, PMIX_UNIV_SIZE, NULL, 0, &val)) ||
 121             NULL == val) {
 122             pmix_output(0, "Client ns %s rank %d: PMIx_Get universe size failed: %d", myproc.nspace, myproc.rank, rc);
 123             goto done;
 124         }
 125         ntmp = val->data.uint32;
 126         PMIX_VALUE_RELEASE(val);
 127         pmix_output(0, "Client %s:%d universe %s size %d", myproc.nspace, myproc.rank, nsp2, (int)ntmp);
 128     }
 129 
 130     /* just cycle the connect/disconnect functions */
 131     if (PMIX_SUCCESS != (rc = PMIx_Connect(&proc, 1, NULL, 0))) {
 132         pmix_output(0, "Client ns %s rank %d: PMIx_Connect failed: %d", myproc.nspace, myproc.rank, rc);
 133         goto done;
 134     }
 135     pmix_output(0, "Client ns %s rank %d: PMIx_Connect succeeded",
 136                 myproc.nspace, myproc.rank);
 137     if (PMIX_SUCCESS != (rc = PMIx_Disconnect(&proc, 1, NULL, 0))) {
 138         pmix_output(0, "Client ns %s rank %d: PMIx_Disonnect failed: %d", myproc.nspace, myproc.rank, rc);
 139         goto done;
 140     }
 141     pmix_output(0, "Client ns %s rank %d: PMIx_Disconnect succeeded", myproc.nspace, myproc.rank);
 142 
 143     /* finally, test the resolve functions */
 144     if (0 == myproc.rank) {
 145         if (PMIX_SUCCESS != (rc = PMIx_Resolve_peers(hostname, NULL, &peers, &npeers))) {
 146             pmix_output(0, "Client ns %s rank %d: PMIx_Resolve_peers failed for nspace %s: %d", myproc.nspace, myproc.rank, nsp2, rc);
 147             goto done;
 148         }
 149         if ((nprocs+ntmp) != npeers) {
 150             pmix_output(0, "Client ns %s rank %d: PMIx_Resolve_peers returned incorrect npeers: %d vs %d", myproc.nspace, myproc.rank, (int)(nprocs+ntmp), (int)npeers);
 151             goto done;
 152         }
 153         pmix_output(0, "Client ns %s rank %d: PMIx_Resolve_peers returned %d npeers", myproc.nspace, myproc.rank, (int)npeers);
 154         if (PMIX_SUCCESS != (rc = PMIx_Resolve_nodes(nsp2, &nodelist))) {
 155             pmix_output(0, "Client ns %s rank %d: PMIx_Resolve_nodes failed for nspace %s: %d", myproc.nspace, myproc.rank, nsp2, rc);
 156             goto done;
 157         }
 158         pmix_output(0, "Client ns %s rank %d: PMIx_Resolve_nodes %s", myproc.nspace, myproc.rank, nodelist);
 159     } else {
 160         if (PMIX_SUCCESS != (rc = PMIx_Resolve_peers(hostname, myproc.nspace, &peers, &npeers))) {
 161             pmix_output(0, "Client ns %s rank %d: PMIx_Resolve_peers failed for nspace %s: %d", myproc.nspace, myproc.rank, myproc.nspace, rc);
 162             goto done;
 163         }
 164         if (nprocs != npeers) {
 165             pmix_output(0, "Client ns %s rank %d: PMIx_Resolve_peers returned incorrect npeers: %d vs %d", myproc.nspace, myproc.rank, nprocs, (int)npeers);
 166             goto done;
 167         }
 168         pmix_output(0, "Client ns %s rank %d: PMIx_Resolve_peers returned %d npeers", myproc.nspace, myproc.rank, (int)npeers);
 169         if (PMIX_SUCCESS != (rc = PMIx_Resolve_nodes(myproc.nspace, &nodelist))) {
 170             pmix_output(0, "Client ns %s rank %d: PMIx_Resolve_nodes failed: %d", myproc.nspace, myproc.rank, rc);
 171             goto done;
 172         }
 173         pmix_output(0, "Client ns %s rank %d: PMIx_Resolve_nodes %s", myproc.nspace, myproc.rank, nodelist);
 174     }
 175     PMIX_PROC_FREE(peers, npeers);
 176     free(nodelist);
 177 
 178  done:
 179     /* call fence to sync */
 180     PMIX_PROC_CONSTRUCT(&proc);
 181     (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
 182     proc.rank = PMIX_RANK_WILDCARD;
 183     if (PMIX_SUCCESS != (rc = PMIx_Fence(&proc, 1, NULL, 0))) {
 184         pmix_output(0, "Client ns %s rank %d: PMIx_Fence failed: %d", myproc.nspace, myproc.rank, rc);
 185         goto done;
 186     }
 187 
 188     /* finalize us */
 189     pmix_output(0, "Client ns %s rank %d: Finalizing", myproc.nspace, myproc.rank);
 190 
 191     if (PMIX_SUCCESS != (rc = PMIx_Finalize(NULL, 0))) {
 192         fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize failed: %d\n", myproc.nspace, myproc.rank, rc);
 193     } else {
 194         fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize successfully completed\n", myproc.nspace, myproc.rank);
 195     }
 196     fflush(stderr);
 197     return(0);
 198 }

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