File: non_zero_root.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 (80 lines) | stat: -rw-r--r-- 2,040 bytes parent folder | download | duplicates (5)
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
/*
 * Copyright (C) by Argonne National Laboratory
 *     See COPYRIGHT in top-level directory
 */

#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>

#define SIZE 100000
#define ITER 1000

#define ERROR_MARGIN 0.5

static int verbose = 0;

int main(int argc, char *argv[])
{
    char *sbuf, *rbuf;
    int i, j;
    double t1, t2, t, ts;
    int rank, size;
    MPI_Status status;

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);

    if (getenv("MPITEST_VERBOSE"))
        verbose = 1;

    /* Allocate memory regions to communicate */
    sbuf = (char *) malloc(SIZE);
    rbuf = (char *) malloc(size * SIZE);

    /* Touch the buffers to make sure they are allocated */
    for (i = 0; i < SIZE; i++)
        sbuf[i] = '0';
    for (i = 0; i < SIZE * size; i++)
        rbuf[i] = '0';

    /* Time when rank 0 gathers the data */
    MPI_Barrier(MPI_COMM_WORLD);
    t1 = MPI_Wtime();
    for (i = 0; i < ITER; i++) {
        MPI_Gather(sbuf, SIZE, MPI_BYTE, rbuf, SIZE, MPI_BYTE, 0, MPI_COMM_WORLD);
        MPI_Barrier(MPI_COMM_WORLD);
    }
    t2 = MPI_Wtime();
    t = (t2 - t1) / ITER;

    /* Time when rank 1 gathers the data */
    MPI_Barrier(MPI_COMM_WORLD);
    t1 = MPI_Wtime();
    for (j = 0; j < ITER; j++) {
        MPI_Gather(sbuf, SIZE, MPI_BYTE, rbuf, SIZE, MPI_BYTE, 1, MPI_COMM_WORLD);
        MPI_Barrier(MPI_COMM_WORLD);
    }
    t2 = MPI_Wtime();
    ts = (t2 - t1) / ITER;

    if (rank == 1)
        MPI_Send(&ts, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD);
    if (rank == 0)
        MPI_Recv(&ts, 1, MPI_DOUBLE, 1, 0, MPI_COMM_WORLD, &status);

    /* Print out the results */
    if (!rank) {
        if ((ts / t) > (1 + ERROR_MARGIN)) {    /* If the difference is more than 10%, it's an error */
            printf("%.3f\t%.3f\n", 1000000.0 * ts, 1000000.0 * t);
            printf("Too much difference in performance\n");
        } else
            printf(" No Errors\n");
    }

    MPI_Finalize();

    return 0;
}