File: namepub_conn.c

package info (click to toggle)
mpich 5.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 251,828 kB
  • sloc: ansic: 1,323,147; cpp: 82,869; f90: 72,420; javascript: 40,763; perl: 28,296; sh: 19,399; python: 16,191; xml: 14,418; makefile: 9,468; fortran: 8,046; java: 4,635; pascal: 352; asm: 324; ruby: 176; awk: 27; lisp: 19; php: 8; sed: 4
file content (63 lines) | stat: -rw-r--r-- 1,541 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 * Copyright (C) by Argonne National Laboratory
 *     See COPYRIGHT in top-level directory
 */

#include "mpitest.h"
#include <stdio.h>
#include <string.h>

#define MTEST_LARGE_PORT_NAME
#ifdef MTEST_LARGE_PORT_NAME
#define PORT_SIZE 4096

#define INIT_PORT_INFO(info) \
    do { \
        MPI_Info_create(&(info)); \
        MPI_Info_set(info, "port_name_size", "4096"); \
    } while (0)

#define FREE_PORT_INFO(info) MPI_Info_free(&(info))

#else
#define PORT_SIZE MPI_MAX_PORT_NAME
#define INIT_PORT_INFO(info) do {info = MPI_INFO_NULL;} while (0)
#define FREE_PORT_INFO(info) do { } while (0)

#endif /* MTEST_LARGE_PORT_NAME */

int main(int argc, char *argv[])
{
    int errs = 0;
    char serv_name[256] = "MyTest";
    char port_name[PORT_SIZE];
    MPI_Info port_info;
    int rank;
    MPI_Comm inter_comm;

    MTest_Init(&argc, &argv);

    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    INIT_PORT_INFO(port_info);

    if (rank == 0) {
        MPI_Open_port(port_info, port_name);
        MPI_Publish_name(serv_name, port_info, port_name);
        MPI_Barrier(MPI_COMM_WORLD);

        MPI_Comm_accept(port_name, MPI_INFO_NULL, 0, MPI_COMM_SELF, &inter_comm);

        MPI_Unpublish_name(serv_name, MPI_INFO_NULL, port_name);
    } else {
        MPI_Barrier(MPI_COMM_WORLD);

        MPI_Lookup_name(serv_name, port_info, port_name);
        MPI_Comm_connect(port_name, MPI_INFO_NULL, 0, MPI_COMM_SELF, &inter_comm);
    }

    MPI_Comm_disconnect(&inter_comm);

    MTest_Finalize(errs);
    return MTestReturnValue(errs);
}