File: reduce_local.c

package info (click to toggle)
mpich 3.2-7
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 81,040 kB
  • ctags: 68,664
  • sloc: ansic: 358,905; f90: 54,597; perl: 18,527; cpp: 10,203; sh: 9,839; xml: 8,195; fortran: 7,799; makefile: 4,868; ruby: 53; sed: 9; php: 8
file content (68 lines) | stat: -rw-r--r-- 1,882 bytes parent folder | download
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
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
/*
 *  (C) 2013 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 */

/* This test checks for proper error checking in MPI_Reduce_local, especially
 * handling of MPI_IN_PLACE and buffer aliasing. */

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

/* quick cop-out for now */
#define check(c_) assert(c_)

int main(int argc, char *argv[])
{
    int err, errs = 0, len, i, errclass;
    int rank = -1, size = -1;
    int *buf;
    int *recvbuf;
    char msg[MPI_MAX_ERROR_STRING];

    MTest_Init(&argc, &argv);
    MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_RETURN);

    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);

    buf = malloc(size * sizeof(int));
    recvbuf = malloc(size * sizeof(int));
    for (i = 0; i < size; ++i) {
        buf[i] = i;
        recvbuf[i] = -1;
    }

    /* check valid reduce_local does not fail */
    err = MPI_Reduce_local(buf, recvbuf, size, MPI_INT, MPI_SUM);
    check(err == MPI_SUCCESS);

    /* ERR: check inbuf==MPI_IN_PLACE */
    err = MPI_Reduce_local(MPI_IN_PLACE, recvbuf, size, MPI_INT, MPI_SUM);
    check(err != MPI_SUCCESS);
    MPI_Error_class(err, &errclass);
    check(errclass == MPI_ERR_BUFFER);

    /* ERR: check inoutbuf==MPI_IN_PLACE */
    err = MPI_Reduce_local(buf, MPI_IN_PLACE, size, MPI_INT, MPI_SUM);
    check(err != MPI_SUCCESS);
    MPI_Error_class(err, &errclass);
    check(errclass == MPI_ERR_BUFFER);

    /* ERR: check buffer aliasing is caught */
    err = MPI_Reduce_local(recvbuf, recvbuf, size, MPI_INT, MPI_SUM);
    check(err != MPI_SUCCESS);
    MPI_Error_class(err, &errclass);
    check(errclass == MPI_ERR_BUFFER);

    free(recvbuf);
    free(buf);

    MTest_Finalize(errs);
    MPI_Finalize();
    return 0;
}