Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
bf88289e5f481b83ca40d309b836c0eb104cccb6
[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
22   int *values = (int *) xbt_malloc(count * sizeof(int));
23
24   for (i = 0; i < count; i++)
25     values[i] = (0 == rank) ? 17 : 3;
26
27   status = MPI_Bcast(NULL, count, MPI_INT, 0, MPI_COMM_WORLD);
28   if(status!=MPI_ERR_BUFFER)
29     printf("MPI_Bcast did not return MPI_ERR_BUFFER for empty sendbuf\n");
30   status = MPI_Bcast(values, -1, MPI_INT, 0, MPI_COMM_WORLD);
31   if(status!=MPI_ERR_COUNT)
32     printf("MPI_Bcast did not return MPI_ERR_COUNT for -1 sendcount\n");
33   status = MPI_Bcast(values, count, MPI_DATATYPE_NULL, 0, MPI_COMM_WORLD);
34   if(status!=MPI_ERR_TYPE)
35     printf("MPI_Bcast did not return MPI_ERR_TYPE for MPI_DATATYPE_NULL sendtype\n");
36   status = MPI_Bcast(values, count, MPI_INT, -1, MPI_COMM_WORLD);
37   if(status!=MPI_ERR_ROOT)
38     printf("MPI_Bcast did not return MPI_ERR_ROOT for -1 root\n");
39   status = MPI_Bcast(values, count, MPI_INT, size, MPI_COMM_WORLD);
40   if(status!=MPI_ERR_ROOT)
41     printf("MPI_Bcast did not return MPI_ERR_ROOT for root > size\n");
42   status = MPI_Bcast(values, count, MPI_INT, 0, MPI_COMM_NULL);
43   if(status!=MPI_ERR_COMM)
44     printf("MPI_Bcast did not return MPI_ERR_COMM for MPI_COMM_NULL comm\n");
45
46   MPI_Bcast(values, count, MPI_INT, 0, MPI_COMM_WORLD);
47
48   int good = 0;
49   for (i = 0; i < count; i++)
50     if (values[i]==17) good++;
51   printf("[%d] number of values equals to 17: %d\n", rank, good);
52
53   MPI_Barrier(MPI_COMM_WORLD);
54   xbt_free(values);
55
56   count = 4096;
57   values = (int *) xbt_malloc(count * sizeof(int));
58
59   for (i = 0; i < count; i++)
60     values[i] = (size -1 == rank) ? 17 : 3;
61
62   status = MPI_Bcast(values, count, MPI_INT, size-1, MPI_COMM_WORLD);
63
64   good = 0;
65   for (i = 0; i < count; i++)
66     if (values[i]==17) good++;
67   printf("[%d] number of values equals to 17: %d\n", rank, good);
68
69   if (rank == 0 && status != MPI_SUCCESS) {
70     printf("bcast returned %d\n", status);
71     fflush(stdout);
72   }
73   xbt_free(values);
74   MPI_Finalize();
75   return 0;
76 }