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-alltoallv / coll-alltoallv.c
index 107179f..7d88c60 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2014, 2016-2017. The SimGrid Team.
+/* Copyright (c) 2013-2019. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
    <2> sdisp: (#3):  [0][1][3]
    <2> rdisp: (#3):  [0][2][4]
 
-   after MPI_Alltoallv :
+   after MPI_Alltoallvv :
    <0> rbuf: (#9):   [-1][-1][-1][-1][-1][-1][-1][-1][-1]
    <1> rbuf: (#9):   [1][101][201][-1][-1][-1][-1][-1][-1]
    <2> rbuf: (#9):   [3][4][103][104][203][204][-1][-1][-1]
 */
 
-static void print_buffer_int(void *buf, int len, char *msg, int rank)
+static void print_buffer_int(const int* buf, int len, const char* msg, int rank)
 {
   printf("[%d] %s (#%d): ", rank, msg, len);
   for (int tmp = 0; tmp < len; tmp++) {
-    int* v = buf;
-    printf("[%d]", v[tmp]);
+    printf("[%d]", buf[tmp]);
   }
   printf("\n");
-  free(msg);
 }
 
 int main(int argc, char **argv)
@@ -68,16 +66,20 @@ int main(int argc, char **argv)
 
   /* Create the buffer */
   MPI_Comm_size(comm, &size);
+  MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
+
   if(size<=0){
     printf("error : comm size <= 0, run with mpirun\n");
     return -1;
   }
   MPI_Comm_rank(comm, &rank);
-  int* sbuf = (int *) xbt_malloc(size * size * sizeof(int));
-  int* rbuf = (int *) xbt_malloc(size * size * sizeof(int));
+  int size2 = size * size;
+  xbt_assert(size2 > 0);
+  int* sbuf = (int*)xbt_malloc(size2 * sizeof(int));
+  int* rbuf = (int*)xbt_malloc(size2 * sizeof(int));
 
   /* Load up the buffers */
-  for (i = 0; i < size * size; i++) {
+  for (i = 0; i < size2; i++) {
     sbuf[i] = i + 100 * rank;
     rbuf[i] = -1;
   }
@@ -93,16 +95,45 @@ int main(int argc, char **argv)
     rdispls[i] = i * rank;
     sdispls[i] = (i * (i + 1)) / 2;
   }
-
-  print_buffer_int( sbuf, size*size, strdup("sbuf:"),rank);
-  print_buffer_int( sendcounts, size, strdup("scount:"),rank);
-  print_buffer_int( recvcounts, size, strdup("rcount:"),rank);
-  print_buffer_int( sdispls, size, strdup("sdisp:"),rank);
-  print_buffer_int( rdispls, size, strdup("rdisp:"),rank);
+  int status;
+
+  status = MPI_Alltoallv(NULL, sendcounts, sdispls, MPI_INT, rbuf, recvcounts, rdispls, MPI_INT, MPI_COMM_WORLD);
+  if(status!=MPI_ERR_BUFFER)
+    printf("MPI_Alltoallv did not return MPI_ERR_BUFFER for empty sendbuf\n");
+  status = MPI_Alltoallv(sbuf, NULL, sdispls, MPI_INT, rbuf, recvcounts, rdispls, MPI_INT, MPI_COMM_WORLD);
+  if(status!=MPI_ERR_ARG)
+    printf("MPI_Alltoallv did not return MPI_ERR_ARG for NULL sendcounts\n");
+  status = MPI_Alltoallv(sbuf, sendcounts, NULL, MPI_INT, rbuf, recvcounts, rdispls, MPI_INT, MPI_COMM_WORLD);
+  if(status!=MPI_ERR_ARG)
+    printf("MPI_Alltoallv did not return MPI_ERR_ARG for NULL senddispl\n");
+  status = MPI_Alltoallv(sbuf, sendcounts, sdispls, MPI_DATATYPE_NULL, rbuf, recvcounts, rdispls, MPI_INT, MPI_COMM_WORLD);
+  if(status!=MPI_ERR_TYPE)
+    printf("MPI_Alltoallv did not return MPI_ERR_TYPE for MPI_DATATYPE_NULL sendtype\n");
+  status = MPI_Alltoallv(sbuf, sendcounts, sdispls, MPI_INT, NULL, recvcounts, rdispls, MPI_INT, MPI_COMM_WORLD);
+  if(status!=MPI_ERR_BUFFER)
+    printf("MPI_Alltoallv did not return MPI_ERR_BUFFER for empty recvbuf\n");
+  status = MPI_Alltoallv(sbuf, sendcounts, sdispls, MPI_INT, rbuf, NULL, rdispls, MPI_INT, MPI_COMM_WORLD);
+  if(status!=MPI_ERR_ARG)
+    printf("MPI_Alltoallv did not return MPI_ERR_ARG for NULL recvcounts\n");
+  status = MPI_Alltoallv(sbuf, sendcounts, sdispls, MPI_INT, rbuf, recvcounts, NULL, MPI_INT, MPI_COMM_WORLD);
+  if(status!=MPI_ERR_ARG)
+    printf("MPI_Alltoallv did not return MPI_ERR_ARG for NULL recvdispl\n");
+  status = MPI_Alltoallv(sbuf, sendcounts, sdispls, MPI_INT, rbuf, recvcounts, rdispls, MPI_DATATYPE_NULL, MPI_COMM_WORLD);
+  if(status!=MPI_ERR_TYPE)
+    printf("MPI_Alltoallv did not return MPI_ERR_TYPE for MPI_DATATYPE_NULL recvtype\n");
+  status = MPI_Alltoallv(sbuf, sendcounts, sdispls, MPI_INT, rbuf, recvcounts, rdispls, MPI_INT, MPI_COMM_NULL);
+  if(status!=MPI_ERR_COMM)
+    printf("MPI_Alltoallv did not return MPI_ERR_COMM for MPI_COMM_NULL comm\n");
+
+  print_buffer_int(sbuf, size2, "sbuf:", rank);
+  print_buffer_int(sendcounts, size, "scount:", rank);
+  print_buffer_int(recvcounts, size, "rcount:", rank);
+  print_buffer_int(sdispls, size, "sdisp:", rank);
+  print_buffer_int(rdispls, size, "rdisp:", rank);
 
   MPI_Alltoallv(sbuf, sendcounts, sdispls, MPI_INT, rbuf, recvcounts, rdispls, MPI_INT, comm);
 
-  print_buffer_int( rbuf, size*size, strdup("rbuf:"),rank);
+  print_buffer_int(rbuf, size2, "rbuf:", rank);
 
   MPI_Barrier(MPI_COMM_WORLD);
   if (0 == rank) {