File: win_shared_query.c

package info (click to toggle)
mpich 4.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 101,184 kB
  • sloc: ansic: 1,040,629; cpp: 82,270; javascript: 40,763; perl: 27,933; python: 16,041; sh: 14,676; xml: 14,418; f90: 12,916; makefile: 9,270; fortran: 8,046; java: 4,635; asm: 324; ruby: 103; awk: 27; lisp: 19; php: 8; sed: 4
file content (91 lines) | stat: -rw-r--r-- 2,548 bytes parent folder | download | duplicates (3)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * Copyright (C) by Argonne National Laboratory
 *     See COPYRIGHT in top-level directory
 */

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <mpi.h>
#include "mpitest.h"

#define ELEM_PER_PROC 100
#define ELEM_SIZE sizeof(int)
#define SIZE (ELEM_PER_PROC * ELEM_SIZE)

const int verbose = 0;

enum {
    CREATE,
    ALLOCATE,
    ALLOCATE_SHARED,
} opt_win_flavor = ALLOCATE;

int main(int argc, char **argv)
{
    int errors = 0;
    MPI_Comm comm;
    MPI_Win win;

    for (int i = 1; i < argc; i++) {
        if (strcmp(argv[i], "-flavor=create") == 0) {
            opt_win_flavor = CREATE;
        } else if (strcmp(argv[i], "-flavor=allocate") == 0) {
            opt_win_flavor = ALLOCATE;
        } else if (strcmp(argv[i], "-flavor=allocate_shared") == 0) {
            opt_win_flavor = ALLOCATE_SHARED;
        }
    }

    MTest_Init(&argc, &argv);

    if (opt_win_flavor == CREATE) {
        MTestPrintfMsg(1, "TEST MPI_Win_create\n");
        comm = MPI_COMM_WORLD;
    } else if (opt_win_flavor == ALLOCATE) {
        MTestPrintfMsg(1, "TEST MPI_Win_allocate\n");
        comm = MPI_COMM_WORLD;
    } else if (opt_win_flavor == ALLOCATE_SHARED) {
        MTestPrintfMsg(1, "TEST MPI_Win_allocate_shared\n");
        MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, 0, MPI_INFO_NULL, &comm);
    } else {
        printf("Invalid opt_win_flavor: %d\n", opt_win_flavor);
        goto fn_exit;
    }

    int rank, nproc;
    MPI_Comm_rank(comm, &rank);
    MPI_Comm_size(comm, &nproc);

    int *my_base;
    if (opt_win_flavor == CREATE) {
        my_base = malloc(SIZE);
        MPI_Win_create(my_base, SIZE, ELEM_SIZE, MPI_INFO_NULL, comm, &win);
    } else if (opt_win_flavor == ALLOCATE) {
        MPI_Win_allocate(SIZE, ELEM_SIZE, MPI_INFO_NULL, comm, &my_base, &win);
    } else if (opt_win_flavor == ALLOCATE_SHARED) {
        MPI_Win_allocate_shared(SIZE, ELEM_SIZE, MPI_INFO_NULL, comm, &my_base, &win);
    }

    for (int i = 0; i < nproc; i++) {
        MPI_Aint size;
        int disp_unit;
        void *base;
        MPI_Win_shared_query(win, i, &size, &disp_unit, &base);
        MTestPrintfMsg(1, "[%d] query [%d / %d]: %p - size=%ld, disp_unit=%d\n",
                       rank, i, nproc, base, (long) size, disp_unit);
    }

    MPI_Win_free(&win);

    if (opt_win_flavor == CREATE) {
        free(my_base);
    } else if (opt_win_flavor == ALLOCATE_SHARED) {
        MPI_Comm_free(&comm);
    }

  fn_exit:
    MTest_Finalize(errors);

    return MTestReturnValue(errors);
}