1 /* Copyright (c) 2009-2022. 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);
23 MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
25 unsigned long long* sb = (unsigned long long *) xbt_malloc(size * sizeof(unsigned long long));
26 unsigned long long* rb = (unsigned long long *) xbt_malloc(size * sizeof(unsigned long long));
28 for (i = 0; i < size; ++i) {
29 sb[i] = rank*size + i;
32 printf("[%d] sndbuf=[", rank);
33 for (i = 0; i < size; i++)
34 printf("%llu ", sb[i]);
38 status = MPI_Reduce(NULL, rb, size, MPI_UNSIGNED_LONG_LONG, MPI_SUM, root, MPI_COMM_WORLD);
39 if(status!=MPI_ERR_BUFFER)
40 printf("MPI_Reduce did not return MPI_ERR_BUFFER for empty sendbuf\n");
41 status = MPI_Reduce(sb, rb, -1, MPI_UNSIGNED_LONG_LONG, MPI_SUM, root, MPI_COMM_WORLD);
42 if(status!=MPI_ERR_COUNT)
43 printf("MPI_Reduce did not return MPI_ERR_COUNT for -1 count\n");
44 status = MPI_Reduce(sb, rb, size, MPI_DATATYPE_NULL, MPI_SUM, root, MPI_COMM_WORLD);
45 if(status!=MPI_ERR_TYPE)
46 printf("MPI_Reduce did not return MPI_ERR_TYPE for MPI_DATATYPE_NULL type\n");
47 status = MPI_Reduce(sb, rb, size, MPI_UNSIGNED_LONG_LONG, MPI_OP_NULL, root, MPI_COMM_WORLD);
48 if(status!=MPI_ERR_OP)
49 printf("MPI_Reduce did not return MPI_ERR_OP for MPI_OP_NULL op\n");
50 status = MPI_Reduce(sb, rb, size, MPI_UNSIGNED_LONG_LONG, MPI_SUM, -1, MPI_COMM_WORLD);
51 if(status!=MPI_ERR_ROOT)
52 printf("MPI_Reduce did not return MPI_ERR_ROOT for root -1\n");
53 status = MPI_Reduce(sb, rb, size, MPI_UNSIGNED_LONG_LONG, MPI_SUM, size+1, MPI_COMM_WORLD);
54 if(status!=MPI_ERR_ROOT)
55 printf("MPI_Reduce did not return MPI_ERR_ROOT for root > size\n");
56 status = MPI_Reduce(sb, rb, size, MPI_UNSIGNED_LONG_LONG, MPI_SUM, root, MPI_COMM_NULL);
57 if(status!=MPI_ERR_COMM)
58 printf("MPI_Reduce did not return MPI_ERR_COMM for MPI_COMM_NULL comm\n");
60 status = MPI_Reduce(sb, rb, size, MPI_UNSIGNED_LONG_LONG, MPI_SUM, root, MPI_COMM_WORLD);
61 MPI_Barrier(MPI_COMM_WORLD);
64 printf("[%d] rcvbuf=[", rank);
65 for (i = 0; i < size; i++)
66 printf("%llu ", rb[i]);
68 if (status != MPI_SUCCESS) {
69 printf("all_to_all returned %d\n", status);
74 printf("[%d] second sndbuf=[", rank);
75 for (i = 0; i < 1; i++)
76 printf("%llu ", sb[i]);
80 status = MPI_Reduce(sb, rb, 1, MPI_UNSIGNED_LONG_LONG, MPI_PROD, root, MPI_COMM_WORLD);
81 MPI_Barrier(MPI_COMM_WORLD);
84 printf("[%d] rcvbuf=[", rank);
85 for (i = 0; i < 1; i++)
86 printf("%llu ", rb[i]);
88 if (status != MPI_SUCCESS) {
89 printf("all_to_all returned %d\n", status);