File: win_shared_query_null.c

package info (click to toggle)
mpich 4.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 423,384 kB
  • sloc: ansic: 1,088,434; cpp: 71,364; javascript: 40,763; f90: 22,829; sh: 17,463; perl: 14,773; xml: 14,418; python: 10,265; makefile: 9,246; fortran: 8,008; java: 4,355; asm: 324; ruby: 176; lisp: 19; php: 8; sed: 4
file content (84 lines) | stat: -rw-r--r-- 2,575 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
/*
 * Copyright (C) by Argonne National Laboratory
 *     See COPYRIGHT in top-level directory
 */

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

/*
 * Check return values of MPI_Win_allocate_shared with MPI_PROC_NULL.
 * It should return the first non-zero window segments on the node.
 * In this test, rank 0 allocates zero window and others allocate non-zero.
 * Thus, it should return the segment belonging to rank 1.
 */

int main(int argc, char **argv)
{
    int rank, errors = 0;
    int shm_rank, shm_nproc;
    MPI_Aint size, query_size;
    int *query_base, *my_base;
    int query_disp_unit;
    MPI_Win shm_win;
    MPI_Comm shm_comm;

    MTest_Init(&argc, &argv);

    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank, MPI_INFO_NULL, &shm_comm);

    MPI_Comm_rank(shm_comm, &shm_rank);
    MPI_Comm_size(shm_comm, &shm_nproc);

    /* Only single process is on the node or the platform does not support shared memory.
     * Just wait for others' completion*/
    if (shm_nproc < 2)
        goto exit;

    size = sizeof(int) * 4;

    /* Allocate zero-byte window on rank 0 and non-zero for others */
    if (shm_rank == 0) {
        MPI_Win_allocate_shared(0, sizeof(int), MPI_INFO_NULL, shm_comm, &my_base, &shm_win);
    } else {
        MPI_Win_allocate_shared(size, sizeof(int), MPI_INFO_NULL, shm_comm, &my_base, &shm_win);
    }

    /* Query the segment belonging the lowest rank with size > 0 */
    MPI_Win_shared_query(shm_win, MPI_PROC_NULL, &query_size, &query_disp_unit, &query_base);
    MTestPrintfMsg(1, "%d --   shared query with PROC_NULL: base %p, size %ld, unit %d\n",
                   shm_rank, query_base, query_size, query_disp_unit);

    if (query_base == NULL) {
        fprintf(stderr, "%d --   shared query with PROC_NULL: base %p, expected non-NULL pointer\n",
                shm_rank, query_base);
        fflush(stderr);
        errors++;
    }

    if (query_size != size) {
        fprintf(stderr, "%d --   shared query with PROC_NULL: size %ld, expected %ld\n",
                shm_rank, query_size, size);
        fflush(stderr);
        errors++;
    }

    if (query_disp_unit != sizeof(int)) {
        fprintf(stderr, "%d --   shared query with PROC_NULL: disp_unit %d, expected %ld\n",
                shm_rank, query_disp_unit, sizeof(int));
        fflush(stderr);
        errors++;
    }

    MPI_Win_free(&shm_win);

  exit:

    MPI_Comm_free(&shm_comm);
    MTest_Finalize(errors);

    return MTestReturnValue(errors);
}