1 /* Copyright (c) 2009-2019. The SimGrid Team.
2 * All rights reserved. */
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. */
13 int main(int argc, char *argv[])
20 MPI_Init(&argc, &argv);
21 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
22 MPI_Comm_size(MPI_COMM_WORLD, &size);
24 unsigned long long* sb = (unsigned long long *) xbt_malloc(size * sizeof(unsigned long long));
25 unsigned long long* rb = (unsigned long long *) xbt_malloc(size * sizeof(unsigned long long));
27 for (i = 0; i < size; ++i) {
28 sb[i] = rank*size + i;
31 printf("[%d] sndbuf=[", rank);
32 for (i = 0; i < size; i++)
33 printf("%llu ", sb[i]);
37 status = MPI_Reduce(NULL, rb, size, MPI_UNSIGNED_LONG_LONG, MPI_SUM, root, MPI_COMM_WORLD);
38 if(status!=MPI_ERR_BUFFER)
39 printf("MPI_Reduce did not return MPI_ERR_BUFFER for empty sendbuf\n");
40 status = MPI_Reduce(sb, rb, -1, MPI_UNSIGNED_LONG_LONG, MPI_SUM, root, MPI_COMM_WORLD);
41 if(status!=MPI_ERR_COUNT)
42 printf("MPI_Reduce did not return MPI_ERR_COUNT for -1 count\n");
43 status = MPI_Reduce(sb, rb, size, MPI_DATATYPE_NULL, MPI_SUM, root, MPI_COMM_WORLD);
44 if(status!=MPI_ERR_TYPE)
45 printf("MPI_Reduce did not return MPI_ERR_TYPE for MPI_DATATYPE_NULL type\n");
46 status = MPI_Reduce(sb, rb, size, MPI_UNSIGNED_LONG_LONG, MPI_OP_NULL, root, MPI_COMM_WORLD);
47 if(status!=MPI_ERR_OP)
48 printf("MPI_Reduce did not return MPI_ERR_COMM for MPI_OP_NULL op\n");
49 status = MPI_Reduce(sb, rb, size, MPI_UNSIGNED_LONG_LONG, MPI_SUM, -1, MPI_COMM_WORLD);
50 if(status!=MPI_ERR_ROOT)
51 printf("MPI_Reduce did not return MPI_ERR_ROOT for root -1\n");
52 status = MPI_Reduce(sb, rb, size, MPI_UNSIGNED_LONG_LONG, MPI_SUM, size+1, MPI_COMM_WORLD);
53 if(status!=MPI_ERR_ROOT)
54 printf("MPI_Reduce did not return MPI_ERR_ROOT for root > size\n");
55 status = MPI_Reduce(sb, rb, size, MPI_UNSIGNED_LONG_LONG, MPI_SUM, root, MPI_COMM_NULL);
56 if(status!=MPI_ERR_COMM)
57 printf("MPI_Reduce did not return MPI_ERR_COMM for MPI_COMM_NULL comm\n");
59 status = MPI_Reduce(sb, rb, size, MPI_UNSIGNED_LONG_LONG, MPI_SUM, root, MPI_COMM_WORLD);
60 MPI_Barrier(MPI_COMM_WORLD);
63 printf("[%d] rcvbuf=[", rank);
64 for (i = 0; i < size; i++)
65 printf("%llu ", rb[i]);
67 if (status != MPI_SUCCESS) {
68 printf("all_to_all returned %d\n", status);
73 printf("[%d] second sndbuf=[", rank);
74 for (i = 0; i < 1; i++)
75 printf("%llu ", sb[i]);
79 status = MPI_Reduce(sb, rb, 1, MPI_UNSIGNED_LONG_LONG, MPI_PROD, root, MPI_COMM_WORLD);
80 MPI_Barrier(MPI_COMM_WORLD);
83 printf("[%d] rcvbuf=[", rank);
84 for (i = 0; i < 1; i++)
85 printf("%llu ", rb[i]);
87 if (status != MPI_SUCCESS) {
88 printf("all_to_all returned %d\n", status);
95 return (EXIT_SUCCESS);