File: copy_bench.c

package info (click to toggle)
armci-mpi 0.0~git20160222-2
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 1,756 kB
  • sloc: ansic: 12,698; sh: 229; makefile: 53; fortran: 44
file content (60 lines) | stat: -rw-r--r-- 1,161 bytes parent folder | download | duplicates (6)
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <mpi.h>

#define NITER 100000
#define MAXSZ 65536*2*2

int main(int argc, char **argv) {
  int      i, j;
  char    *in, *out;
  double   t_start, t_stop;
  MPI_Comm copy_comm;

  MPI_Init(&argc, &argv);

  MPI_Comm_dup(MPI_COMM_SELF, &copy_comm);

  in  = malloc(MAXSZ);
  out = malloc(MAXSZ);

  for (i = 0; i < MAXSZ; i++) {
    in[i]  = 0xAA;
    out[i] = 0x55;
  }

  for (i = 1; i <= MAXSZ; i *= 2) {
    t_start = MPI_Wtime();
    for (j = 0; j < NITER; j++) {
      memcpy(out, in, i);
    }
    t_stop = MPI_Wtime();
    printf("MEMCPY: %7d\t%0.9f\n", i, t_stop-t_start);
  }

  for (i = 0; i < MAXSZ; i++) {
    in[i]  = 0xAA;
    out[i] = 0x55;
  }

  for (i = 1; i <= MAXSZ; i *= 2) {
    t_start = MPI_Wtime();
    for (j = 0; j < NITER; j++) {
      MPI_Sendrecv(in, i, MPI_BYTE,
          0 /* rank */, 0 /* tag */,
          out, i, MPI_BYTE,
          0 /* rank */, 0 /* tag */,
          copy_comm, MPI_STATUS_IGNORE);
    }
    t_stop = MPI_Wtime();
    printf("SNDRCV: %7d\t%0.9f\n", i, t_stop-t_start);
  }


  MPI_Comm_free(&copy_comm);
  MPI_Finalize();

  return 0;
}