File: large_vec.c

package info (click to toggle)
mpich 3.3-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 131,836 kB
  • sloc: ansic: 975,868; cpp: 57,437; f90: 53,762; perl: 19,562; xml: 12,464; sh: 12,303; fortran: 7,875; makefile: 7,078; ruby: 126; java: 100; python: 98; lisp: 19; php: 8; sed: 4
file content (78 lines) | stat: -rw-r--r-- 2,234 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
69
70
71
72
73
74
75
76
77
78
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
/*
 *  (C) 2014 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 */
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include "mpitest.h"

/* tests non-contig send/recv of a message > 2GB. count=270M, type=long long
   run with 3 processes to exercise both shared memory and TCP in Nemesis tests*/

int main(int argc, char *argv[])
{
    int ierr, i, size, rank;
    int elems = 270000000;
    MPI_Status status;
    MPI_Datatype dtype;
    long long *cols;
    int errs = 0;


    MTest_Init(&argc, &argv);

    /* need large memory */
    if (sizeof(void *) < 8) {
        MTest_Finalize(errs);
        return MTestReturnValue(errs);
    }

    ierr = MPI_Comm_size(MPI_COMM_WORLD, &size);
    ierr = MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    if (size != 3) {
        fprintf(stderr, "[%d] usage: mpiexec -n 3 %s\n", rank, argv[0]);
        MPI_Abort(MPI_COMM_WORLD, 1);
    }

    cols = malloc(elems * sizeof(long long));
    if (cols == NULL) {
        printf("malloc of >2GB array failed\n");
        errs++;
        MTest_Finalize(errs);
        return MTestReturnValue(errs);
    }

    MPI_Type_vector(elems / 2, 1, 2, MPI_LONG_LONG_INT, &dtype);
    MPI_Type_commit(&dtype);

    if (rank == 0) {
        for (i = 0; i < elems; i++)
            cols[i] = i;
        /* printf("[%d] sending...\n",rank); */
        ierr = MPI_Send(cols, 1, dtype, 1, 0, MPI_COMM_WORLD);
        ierr = MPI_Send(cols, 1, dtype, 2, 0, MPI_COMM_WORLD);
    } else {
        /* printf("[%d] receiving...\n",rank); */
        for (i = 0; i < elems; i++)
            cols[i] = -1;
        ierr = MPI_Recv(cols, 1, dtype, 0, 0, MPI_COMM_WORLD, &status);
        /* ierr = MPI_Get_count(&status,MPI_LONG_LONG_INT,&cnt);
         * Get_count still fails because count is not 64 bit */
        for (i = 0; i < elems; i++) {
            if (i % 2)
                continue;
            if (cols[i] != i) {
                printf("Rank %d, cols[i]=%lld, should be %d\n", rank, cols[i], i);
                errs++;
            }
        }
    }

    MPI_Type_free(&dtype);
    free(cols);

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