Salome HOME
Copyright update 2021
[tools/medcoupling.git] / src / ParaMEDMEMTest / MPI2Connector.cxx
index 8535c6f55ba29666114e01e899e8b53515ce208c..c64e456101bd4fe3a70fd2cd861e7c9cd42be6bf 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2021  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 #include <unistd.h>
 #endif
 
+
+#ifdef OMPI_MAJOR_VERSION 
+#   if OMPI_MAJOR_VERSION >= 4
+#      define MPI_ERROR_HANDLER(var) MPI_Comm_set_errhandler(MPI_COMM_WORLD, var)
+#   else
+#      define MPI_ERROR_HANDLER(var) MPI_Errhandler_set(MPI_COMM_WORLD, var)
+#   endif
+#else  // MPICH and other versions:
+#   define MPI_ERROR_HANDLER(var) MPI_Errhandler_set(MPI_COMM_WORLD, var)
+#endif
+
 MPI2Connector::MPI2Connector()
 {
   MPI_Comm_size( MPI_COMM_WORLD, &_nb_proc );
@@ -54,8 +65,7 @@ MPI_Comm MPI2Connector::remoteMPI2Connect(const std::string& service)
   _srv = false;
 
   MPI_Barrier(MPI_COMM_WORLD);
-
-  MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
+  MPI_ERROR_HANDLER(MPI_ERRORS_RETURN);
   if( _num_proc == 0 )
     { 
       /* rank 0 try to be a server. If service is already published, try to be a cient */
@@ -104,7 +114,7 @@ MPI_Comm MPI2Connector::remoteMPI2Connect(const std::string& service)
           throw std::exception();
         }
     }
-  MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_ARE_FATAL);
+  MPI_ERROR_HANDLER(MPI_ERRORS_ARE_FATAL);
   
   /* If rank 0 is server, all processes call MPI_Comm_accept */
   /* If rank 0 is not server, all processes call MPI_Comm_connect */