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-bcast / coll-bcast.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 <stdio.h>
8 #include <mpi.h>
9
10 int main(int argc, char **argv)
11 {
12   int i;
13   int size;
14   int rank;
15   int count = 2048;
16   int status;
17
18   MPI_Init(&argc, &argv);
19   MPI_Comm_size(MPI_COMM_WORLD, &size);
20   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
21   MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
22
23   int *values = (int *) xbt_malloc(count * sizeof(int));
24
25   for (i = 0; i < count; i++)
26     values[i] = (0 == rank) ? 17 : 3;
27
28   status = MPI_Bcast(NULL, count, MPI_INT, 0, MPI_COMM_WORLD);
29   if(status!=MPI_ERR_BUFFER)
30     printf("MPI_Bcast did not return MPI_ERR_BUFFER for empty sendbuf\n");
31   status = MPI_Bcast(values, -1, MPI_INT, 0, MPI_COMM_WORLD);
32   if(status!=MPI_ERR_COUNT)
33     printf("MPI_Bcast did not return MPI_ERR_COUNT for -1 sendcount\n");
34   status = MPI_Bcast(values, count, MPI_DATATYPE_NULL, 0, MPI_COMM_WORLD);
35   if(status!=MPI_ERR_TYPE)
36     printf("MPI_Bcast did not return MPI_ERR_TYPE for MPI_DATATYPE_NULL sendtype\n");
37   status = MPI_Bcast(values, count, MPI_INT, -1, MPI_COMM_WORLD);
38   if(status!=MPI_ERR_ROOT)
39     printf("MPI_Bcast did not return MPI_ERR_ROOT for -1 root\n");
40   status = MPI_Bcast(values, count, MPI_INT, size, MPI_COMM_WORLD);
41   if(status!=MPI_ERR_ROOT)
42     printf("MPI_Bcast did not return MPI_ERR_ROOT for root > size\n");
43   status = MPI_Bcast(values, count, MPI_INT, 0, MPI_COMM_NULL);
44   if(status!=MPI_ERR_COMM)
45     printf("MPI_Bcast did not return MPI_ERR_COMM for MPI_COMM_NULL comm\n");
46
47   MPI_Bcast(values, count, MPI_INT, 0, MPI_COMM_WORLD);
48
49   int good = 0;
50   for (i = 0; i < count; i++)
51     if (values[i]==17) good++;
52   printf("[%d] number of values equals to 17: %d\n", rank, good);
53
54   MPI_Barrier(MPI_COMM_WORLD);
55   xbt_free(values);
56
57   count = 4096;
58   values = (int *) xbt_malloc(count * sizeof(int));
59
60   for (i = 0; i < count; i++)
61     values[i] = (size -1 == rank) ? 17 : 3;
62
63   status = MPI_Bcast(values, count, MPI_INT, size-1, MPI_COMM_WORLD);
64
65   good = 0;
66   for (i = 0; i < count; i++)
67     if (values[i]==17) good++;
68   printf("[%d] number of values equals to 17: %d\n", rank, good);
69
70   if (rank == 0 && status != MPI_SUCCESS) {
71     printf("bcast returned %d\n", status);
72     fflush(stdout);
73   }
74   xbt_free(values);
75   MPI_Finalize();
76   return 0;
77 }