Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / teshsuite / smpi / coll-allgatherv / coll-allgatherv.c
1 /* Copyright (c) 2009-2021. 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 i;
16   int rank;
17   int size;
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   int* recv_counts = (int *) xbt_malloc(size * sizeof(int));
26   int* recv_disps = (int *) xbt_malloc(size * sizeof(int));
27
28   int recv_sb_size = 0;
29   for (i = 0; i < size; i++) {
30     recv_counts[i] = i + 1;
31     recv_disps[i] = recv_sb_size;
32     recv_sb_size += i + 1;
33   }
34
35   int* sb = (int *) xbt_malloc(recv_counts[rank] * sizeof(int));
36   int* rb = (int *) xbt_malloc(recv_sb_size * sizeof(int));
37
38   status = MPI_Allgatherv(NULL, recv_counts[rank], MPI_INT, rb, recv_counts, recv_disps, MPI_INT, MPI_COMM_WORLD);
39   if(status!=MPI_ERR_BUFFER)
40     printf("MPI_Allgatherv did not return MPI_ERR_BUFFER for empty sendbuf\n");
41   status = MPI_Allgatherv(sb, -1, MPI_INT, rb, recv_counts, recv_disps, MPI_INT, MPI_COMM_WORLD);
42   if(status!=MPI_ERR_COUNT)
43     printf("MPI_Allgatherv did not return MPI_ERR_COUNT for -1 sendcount\n");
44   status = MPI_Allgatherv(sb, recv_counts[rank], MPI_DATATYPE_NULL, rb, recv_counts, recv_disps, MPI_INT, MPI_COMM_WORLD);
45   if(status!=MPI_ERR_TYPE)
46     printf("MPI_Allgatherv did not return MPI_ERR_TYPE for MPI_DATATYPE_NULL sendtype\n");
47   status = MPI_Allgatherv(sb, recv_counts[rank], MPI_INT, NULL, recv_counts, recv_disps, MPI_INT, MPI_COMM_WORLD);
48   if(status!=MPI_ERR_BUFFER)
49     printf("MPI_Allgatherv did not return MPI_ERR_BUFFER for empty recvbuf\n");
50   status = MPI_Allgatherv(sb, recv_counts[rank], MPI_INT, rb, NULL, recv_disps, MPI_INT, MPI_COMM_WORLD);
51   if(status!=MPI_ERR_COUNT)
52     printf("MPI_Allgatherv did not return MPI_ERR_COUNT for NULL recvcounts\n");
53   status = MPI_Allgatherv(sb, recv_counts[rank], MPI_INT, rb, recv_counts, NULL, MPI_INT, MPI_COMM_WORLD);
54   if(status!=MPI_ERR_ARG)
55     printf("MPI_Allgatherv did not return MPI_ERR_ARG for NULL recvdisps\n");
56   status = MPI_Allgatherv(sb, recv_counts[rank], MPI_INT, rb, recv_counts, recv_disps, MPI_DATATYPE_NULL, MPI_COMM_WORLD);
57   if(status!=MPI_ERR_TYPE)
58     printf("MPI_Allgatherv did not return MPI_ERR_TYPE for MPI_DATATYPE_NULL recvtype\n");
59   status = MPI_Allgatherv(sb, recv_counts[rank], MPI_INT, rb, recv_counts, recv_disps, MPI_INT, MPI_COMM_NULL);
60   if(status!=MPI_ERR_COMM)
61     printf("MPI_Allgatherv did not return MPI_ERR_COMM for MPI_COMM_NULL comm\n");
62
63   printf("[%d] sndbuf=[", rank);
64   for (i = 0; i < recv_counts[rank]; i++){
65     sb[i] = recv_disps[rank] + i;
66     printf("%d ", sb[i]);
67   }
68   printf("]\n");
69
70   for (i = 0; i < recv_sb_size; i++)
71     rb[i] = -1;
72
73   status = MPI_Allgatherv(sb, recv_counts[rank], MPI_INT, rb, recv_counts, recv_disps, MPI_INT, MPI_COMM_WORLD);
74
75   printf("[%d] rcvbuf=[", rank);
76   for (i = 0; i < recv_sb_size; i++)
77     printf("%d ", rb[i]);
78   printf("]\n");
79
80   if (rank == 0 && status != MPI_SUCCESS) {
81     printf("allgatherv returned %d\n", status);
82     fflush(stdout);
83   }
84   xbt_free(sb);
85   xbt_free(rb);
86   xbt_free(recv_counts);
87   xbt_free(recv_disps);
88   MPI_Finalize();
89   return (EXIT_SUCCESS);
90 }