File: test_igop.c

package info (click to toggle)
armci-mpi 0.0~git20180917-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,768 kB
  • sloc: ansic: 12,777; sh: 236; makefile: 54; fortran: 44
file content (77 lines) | stat: -rw-r--r-- 1,555 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * Copyright (C) 2010. See COPYRIGHT in top-level directory.
 */

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#include <mpi.h>
#include <armci.h>

#define DATA_SZ 100
#define SHARED_BUF 1

int main(int argc, char ** argv) {
  int    rank, nproc, i;
  int   *buf;
#ifdef SHARED_BUF
  void **base_ptrs;
#endif

  MPI_Init(&argc, &argv);
  ARMCI_Init();

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

  if (rank == 0) printf("Starting ARMCI GOP test with %d processes\n", nproc);

#ifdef SHARED_BUF
  base_ptrs = malloc(nproc*sizeof(void*));
  ARMCI_Malloc(base_ptrs, DATA_SZ*sizeof(int));
  buf = base_ptrs[rank];
#else
  buf = malloc(DATA_SZ*sizeof(int));
#endif

  if (rank == 0) printf(" - Testing ABSMIN\n");

  for (i = 0; i < DATA_SZ; i++)
    buf[i] = (rank+1) * ((i % 2) ? -1 : 1);

  armci_msg_igop(buf, DATA_SZ, "absmin");

  for (i = 0; i < DATA_SZ; i++)
    if (buf[i] != 1) {
      printf("Err: buf[%d] = %d expected 1\n", i, buf[i]);
      ARMCI_Error("Fail", 1);
    }

  if (rank == 0) printf(" - Testing ABSMAX\n");

  for (i = 0; i < DATA_SZ; i++)
    buf[i] = (rank+1) * ((i % 2) ? -1 : 1);

  armci_msg_igop(buf, DATA_SZ, "absmax");

  for (i = 0; i < DATA_SZ; i++)
    if (buf[i] != nproc) {
      printf("Err: buf[%d] = %d expected %d\n", i, buf[i], nproc);
      ARMCI_Error("Fail", 1);
    }

#ifdef SHARED_BUF
  ARMCI_Free(base_ptrs[rank]);
  free(base_ptrs);
#else
  free(buf);
#endif

  if (rank == 0) printf("Pass.\n");

  ARMCI_Finalize();
  MPI_Finalize();

  return 0;
}