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-alltoall / coll-alltoall.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
20   MPI_Init(&argc, &argv);
21   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
22   MPI_Comm_size(MPI_COMM_WORLD, &size);
23   MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
24
25
26   int* sb = (int *) xbt_malloc(size * sizeof(int) * 2);
27   int* rb = (int *) xbt_malloc(size * sizeof(int) * 2);
28
29   for (i = 0; i < size; ++i) {
30     sb[i] = rank*size + i;
31     rb[i] = 0;
32   }
33
34   printf("[%d] sndbuf=[", rank);
35   for (i = 0; i < size; i++)
36     printf("%d ", sb[i]);
37   printf("]\n");
38   int count=1;
39
40   status = MPI_Alltoall(NULL, count, MPI_INT, rb, count, MPI_INT, MPI_COMM_WORLD);
41   if(status!=MPI_ERR_BUFFER)
42     printf("MPI_Alltoall did not return MPI_ERR_BUFFER for empty sendbuf\n");
43   status = MPI_Alltoall(sb, -1, MPI_INT, rb, count, MPI_INT, MPI_COMM_WORLD);
44   if(status!=MPI_ERR_COUNT)
45     printf("MPI_Alltoall did not return MPI_ERR_COUNT for -1 sendcount\n");
46   status = MPI_Alltoall(sb, count, MPI_DATATYPE_NULL, rb, count, MPI_INT, MPI_COMM_WORLD);
47   if(status!=MPI_ERR_TYPE)
48     printf("MPI_Alltoall did not return MPI_ERR_TYPE for MPI_DATATYPE_NULL sendtype\n");
49   status = MPI_Alltoall(sb, count, MPI_INT, NULL, count, MPI_INT, MPI_COMM_WORLD);
50   if(status!=MPI_ERR_BUFFER)
51     printf("MPI_Alltoall did not return MPI_ERR_BUFFER for empty recvbuf\n");
52   status = MPI_Alltoall(sb, count, MPI_INT, rb, -1, MPI_INT, MPI_COMM_WORLD);
53   if(status!=MPI_ERR_COUNT)
54     printf("MPI_Alltoall did not return MPI_ERR_COUNT for -1 recvcount\n");
55   status = MPI_Alltoall(sb, count, MPI_INT, rb, count, MPI_DATATYPE_NULL, MPI_COMM_WORLD);
56   if(status!=MPI_ERR_TYPE)
57     printf("MPI_Alltoall did not return MPI_ERR_TYPE for MPI_DATATYPE_NULL recvtype\n");
58   status = MPI_Alltoall(sb, count, MPI_INT, rb, count, MPI_INT, MPI_COMM_NULL);
59   if(status!=MPI_ERR_COMM)
60     printf("MPI_Alltoall did not return MPI_ERR_COMM for MPI_COMM_NULL comm\n");
61
62   status = MPI_Alltoall(sb, count, MPI_INT, rb, count, MPI_INT, MPI_COMM_WORLD);
63
64   printf("[%d] rcvbuf=[", rank);
65   for (i = 0; i < size; i++)
66     printf("%d ", rb[i]);
67   printf("]\n");
68
69   if (rank == 0 && status != MPI_SUCCESS) {
70     printf("all_to_all returned %d\n", status);
71     fflush(stdout);
72   }
73   xbt_free(sb);
74   xbt_free(rb);
75   MPI_Finalize();
76   return (EXIT_SUCCESS);
77 }