Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
our coll-* tests include bad calls for coverage, they need MPI_ERRORS_RETURN
[simgrid.git] / teshsuite / smpi / coll-allreduce / coll-allreduce.c
1 /* Copyright (c) 2009-2019. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include <errno.h>
11 #include "mpi.h"
12
13 int main(int argc, char *argv[])
14 {
15   int rank;
16   int size;
17   int i;
18   int status;
19   int mult=1;
20
21   MPI_Init(&argc, &argv);
22   int maxlen = argc >= 2 ? atoi(argv[1]) : 1;
23
24   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
25   MPI_Comm_size(MPI_COMM_WORLD, &size);
26   MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
27
28   if (maxlen > 1)
29     mult = maxlen > size ? size : maxlen;
30   int* sb = xbt_new0(int, size * maxlen);
31   int* rb = xbt_new0(int, size * maxlen);
32
33   for (i = 0; i < size *maxlen; ++i) {
34     sb[i] = rank*size + i;
35     rb[i] = 0;
36   }
37
38   status = MPI_Allreduce(NULL, rb, size, MPI_UNSIGNED_LONG_LONG, MPI_SUM, MPI_COMM_WORLD);
39   if(status!=MPI_ERR_BUFFER)
40     printf("MPI_Allreduce did not return MPI_ERR_BUFFER for empty sendbuf\n");
41   status = MPI_Allreduce(sb, NULL, size, MPI_UNSIGNED_LONG_LONG, MPI_SUM, MPI_COMM_WORLD);
42   if(status!=MPI_ERR_BUFFER)
43     printf("MPI_Allreduce did not return MPI_ERR_BUFFER for empty recvbuf\n");
44   status = MPI_Allreduce(sb, rb, -1, MPI_UNSIGNED_LONG_LONG, MPI_SUM, MPI_COMM_WORLD);
45   if(status!=MPI_ERR_COUNT)
46     printf("MPI_Allreduce did not return MPI_ERR_COUNT for -1 count\n");
47   status = MPI_Allreduce(sb, rb, size, MPI_DATATYPE_NULL, MPI_SUM, MPI_COMM_WORLD);
48   if(status!=MPI_ERR_TYPE)
49     printf("MPI_Allreduce did not return MPI_ERR_TYPE for MPI_DATATYPE_NULL type\n");
50   status = MPI_Allreduce(sb, rb, size, MPI_UNSIGNED_LONG_LONG, MPI_OP_NULL, MPI_COMM_WORLD);
51   if(status!=MPI_ERR_OP)
52     printf("MPI_Allreduce did not return MPI_ERR_COMM for MPI_OP_NULL op\n");
53   status = MPI_Allreduce(sb, rb, size, MPI_UNSIGNED_LONG_LONG, MPI_SUM, MPI_COMM_NULL);
54   if(status!=MPI_ERR_COMM)
55     printf("MPI_Allreduce did not return MPI_ERR_COMM for MPI_COMM_NULL comm\n");
56
57   printf("[%d] sndbuf=[", rank);
58   for (i = 0; i < size *mult; i++)
59     printf("%d ", sb[i]);
60   printf("]\n");
61   status = MPI_Allreduce(sb, rb, size *maxlen, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
62
63   printf("[%d] rcvbuf=[", rank);
64   for (i =  0; i < size *mult; i++)//do not print everything
65     printf("%d ", rb[i]);
66   printf("]\n");
67
68   if (rank == 0 && status != MPI_SUCCESS) {
69     printf("all_to_all returned %d\n", status);
70     fflush(stdout);
71   }
72   xbt_free(sb);
73   xbt_free(rb);
74   MPI_Finalize();
75   return (EXIT_SUCCESS);
76 }