Salome HOME
Build KERNEL with native openmpi on CentOS-8
[modules/kernel.git] / src / MPIContainer / testMPI2.cxx
index df04076a1e146c74d690fc01adabc08154f7dd10..163e1fa13486180ddcd36cd618a44f7531242180 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2011-2020  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 int main(int argc, char**argv)
 {
   int *indg;
-  double *vector, sum=0., norm, etalon;
+  double *vector, sum=0., norm=1., etalon=0.;
   int rank, size, grank, gsize, rsize;
   int vsize=20, lvsize, rlvsize;
   int i, k1, k2, imin, imax, nb;
   int srv=0;
   MPI_Comm com, icom;
-  MPI_Status status; 
+  MPI_Status status;
+  MPI_Info info;
   char   port_name     [MPI_MAX_PORT_NAME]; 
   char   port_name_clt [MPI_MAX_PORT_NAME]; 
   std::string service = "SERVICE";
   bool debug=false;
 
-#ifndef WITHOPENMPI
-  std::cout << "This test only works with openmpi implementation" << std::endl;
-  exit(1);
-#endif
-
   for(i=1;i<argc;i++){
     std::string sargv = argv[i];
     if(sargv.find("-debug")!=std::string::npos)
@@ -62,8 +58,15 @@ int main(int argc, char**argv)
   MPI_Comm_rank( MPI_COMM_WORLD, &rank );
 
   MPI_Barrier(MPI_COMM_WORLD);
-
+#if OMPI_MAJOR_VERSION >= 4
+  MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
+#else
   MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
+#endif
+
+#ifdef HAVE_MPI2
+  MPI_Info_create(&info);
+  MPI_Info_set(info, "ompi_unique", "true");
   if(rank==0){
     MPI_Open_port(MPI_INFO_NULL, port_name); 
     if ( MPI_Lookup_name((char*)service.c_str(), MPI_INFO_NULL, port_name_clt) == MPI_SUCCESS )  {
@@ -71,7 +74,7 @@ int main(int argc, char**argv)
         std::cout << "[" << rank << "] I am client: I get the service " << service << " !" << std::endl;
       MPI_Close_port( port_name );
     } 
-    else if ( MPI_Publish_name((char*)service.c_str(), MPI_INFO_NULL, port_name) == MPI_SUCCESS )  {
+    else if ( MPI_Publish_name((char*)service.c_str(), info, port_name) == MPI_SUCCESS )  {
       if(debug)
         std::cout << "[" << rank << "] I am server: I've managed to publish the service " << service << " !" << std::endl;
       srv = 1;
@@ -106,7 +109,11 @@ int main(int argc, char**argv)
       exit(1);
     }
   }
+#if OMPI_MAJOR_VERSION >= 4
+  MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_ARE_FATAL);
+#else
   MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_ARE_FATAL);
+#endif
   MPI_Bcast(&srv,1,MPI_INT,0,MPI_COMM_WORLD);
   if ( srv )
     MPI_Comm_accept( port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &icom );
@@ -206,6 +213,7 @@ int main(int argc, char**argv)
 
   free(indg);
   free(vector);
+#endif
   MPI_Finalize();
 
   if(rank==0){