root/orte/test/mpi/pubsub.c

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

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /* -*- C -*-
   2  *
   3  * $HEADER$
   4  *
   5  * The most basic of MPI applications
   6  */
   7 
   8 #include <stdio.h>
   9 #include <stdbool.h>
  10 #include <string.h>
  11 #include "mpi.h"
  12 
  13 int main(int argc, char* argv[])
  14 {
  15     int rank, size;
  16     MPI_Info info, srch;
  17     char port[MPI_MAX_PORT_NAME];
  18     bool local=false;
  19 
  20     if (1 < argc) {
  21         if (0 == strcmp("local", argv[1])) {
  22             local = true;
  23         }
  24     }
  25 
  26     MPI_Init(&argc, &argv);
  27 
  28     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  29     MPI_Comm_size(MPI_COMM_WORLD, &size);
  30 
  31     printf("Hello, World, I am %d of %d\n", rank, size);
  32 
  33     MPI_Info_create(&info);
  34     if (local) {
  35         MPI_Info_set(info, "ompi_global_scope", "false");
  36     } else {
  37         MPI_Info_set(info, "ompi_global_scope", "true");
  38     }
  39 
  40     if (0 == rank) {
  41         MPI_Open_port(MPI_INFO_NULL, port);
  42         MPI_Publish_name("pubsub-test", info, port);
  43         printf("Rank %d published port %s\n", rank, port);
  44     }
  45 
  46     MPI_Barrier(MPI_COMM_WORLD);
  47 
  48     MPI_Info_create(&srch);
  49     MPI_Info_set(srch, "ompi_lookup_order", "local,global");
  50     if (rank != 0) {
  51         MPI_Lookup_name("pubsub-test", srch, port);
  52         printf("Rank %d got port %s\n", rank, port);
  53     }
  54 
  55     MPI_Barrier(MPI_COMM_WORLD);
  56 
  57     if (0 == rank) {
  58         MPI_Unpublish_name("pubsub-test", info, port);
  59     }
  60     MPI_Info_free(&info);
  61     MPI_Info_free(&srch);
  62     MPI_Finalize();
  63     return 0;
  64 }

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