Salome HOME
Fix bos #26435 MG-Tetra_HPC failed with new licence mechanism:
[plugins/ghs3dprlplugin.git] / src / GHS3DPRLPlugin / GHS3DPRLPlugin_GHS3DPRL.cxx
index eb92f305a1ed48d3831a05c7024d524546c548b8..db4f829611840bf71bd44c96e55d872dae77b9ac 100644 (file)
@@ -279,11 +279,13 @@ bool GHS3DPRLPlugin_GHS3DPRL::Compute(SMESH_Mesh&         theMesh,
 
   map <int,int> aSmdsToGHS3DPRLIdMap;
   map <int,const SMDS_MeshNode*> aGHS3DPRLIdToNodeMap;
-  GHS3DPRL_In = path + "GHS3DPRL";
+  _genericName = GHS3DPRLPlugin_Hypothesis::GetFileName(_hypothesis);
+  TCollection_AsciiString aGenericName((char*) _genericName.c_str() );
+  GHS3DPRL_In = aGenericName + ".mesh";
   GHS3DPRL_Out = path + casenamemed;
-  GHS3DPRL_Out_Mesh = path + casenamemed + "_out.mesh";
+  GHS3DPRL_Out_Mesh = aGenericName + "_out.mesh";
   GHS3DPRL_Outxml = path + casenamemed + ".xml"; //master file
-  logFileName = path + casenamemed + ".log"; // MG library output
+  logFileName = aGenericName + ".log"; // MG library output
   NbPart=_NbPart;
   Gradation=_Gradation;
   MinSize=_MinSize;
@@ -295,7 +297,7 @@ bool GHS3DPRLPlugin_GHS3DPRL::Compute(SMESH_Mesh&         theMesh,
   //             --verbose=0 --menu=no --launchtetra=yes;
 
   run_GHS3DPRL = run_GHS3DPRL +
-    " --casename=" + GHS3DPRL_In +
+    " --casename=" + aGenericName +
     " --number=" + NbPart +
     " --medname=" + GHS3DPRL_Out +
     " --launchtetra=yes" +
@@ -310,8 +312,6 @@ bool GHS3DPRLPlugin_GHS3DPRL::Compute(SMESH_Mesh&         theMesh,
   system( run_nokeep_files.ToCString() ); //clean files
   run_nokeep_files = rm + GHS3DPRL_In + "* ";
 
-  fileskinmesh=path + "GHS3DPRL.mesh";
-  GHS3DPRL_Out = path + casenamemed;
   removeFile( GHS3DPRL_Outxml ); //only the master xml file
 
   MG_TetraHPC_API mgTetraHPC( _computeCanceled, _progress );
@@ -319,18 +319,25 @@ bool GHS3DPRLPlugin_GHS3DPRL::Compute(SMESH_Mesh&         theMesh,
   if ( !useLib )
     mgTetraHPC.SetUseExecutable();
 
-  exportGMF( &mgTetraHPC, fileskinmesh.ToCString(), meshDS );
+  exportGMF( &mgTetraHPC, GHS3DPRL_In.ToCString(), meshDS );
 
   if ( true /*useLib*/ )
   {
-    TCollection_AsciiString cmd = TCollection_AsciiString("mg-tetra_hpc.exe") + 
-      " --number_of_subdomains=" + NbPart +
-      " --gradation=" + Gradation +
-      " --min_size=" + MinSize +
-      " --max_size=" + MaxSize +
-      " --verbose=3" +
-      " --out=" + GHS3DPRL_Out_Mesh +
-      " " + _AdvOptions.c_str();
+    TCollection_AsciiString cmd = TCollection_AsciiString();
+    if (_Multithread)
+      cmd += "mg-tetra_hpc.exe";
+    else
+      cmd = cmd + "mpirun --n " + NbPart + " mg-tetra_hpc_mpi.exe";
+    cmd = cmd + " --in=" + GHS3DPRL_In;
+    if (_Multithread)
+      cmd = cmd +" --max_number_of_threads=" + NbPart;
+    cmd = cmd + " --gradation=" + Gradation;
+    cmd = cmd + " --min_size=" + MinSize;
+    cmd = cmd + " --max_size=" + MaxSize;
+    cmd = cmd + " --verbose=3";
+    cmd = cmd + " --out=" + GHS3DPRL_Out_Mesh;
+    cmd = cmd + " " + _AdvOptions.c_str();
+    cmd = cmd + " 1>" + logFileName;
 
     cout << endl
          << "  Run mg-tetra_hpc as library. Creating a mesh file " << GHS3DPRL_Out_Mesh << endl
@@ -338,13 +345,28 @@ bool GHS3DPRLPlugin_GHS3DPRL::Compute(SMESH_Mesh&         theMesh,
     mgTetraHPC.SetLogFile( logFileName.ToCString() );
 
     std::string log;
-    mgTetraHPC.Compute( cmd.ToCString(), log );
+    Ok = mgTetraHPC.Compute( cmd.ToCString(), log );
 
-    if ( log.empty() )
-      log = mgTetraHPC.GetLog();
-    if ( log.find(" Dlim "   ) != std::string::npos ||
-         log.find(" license ") != std::string::npos )
-      return error("License problem");
+    if (!Ok)
+    {
+      std::cout << "Error: " << std::endl;
+      std::cout << log << std::endl;
+      // try to guess an error from the output log
+      std::string log2 = mgTetraHPC.GetLog();
+      if ( log2.find(" Dlim "   ) != std::string::npos ||
+          log2.find(" license ") != std::string::npos )
+        return error("License problem");
+      std::cout << log2 << std::endl;
+      if ( log2.find("You are using an empty MPI stubs library") != std::string::npos )
+      {
+        std:string msg = "You are using an empty MPI stubs library. Please build it first to be able to use mg-tetra_hpc_mpi.exe.\n";
+        msg += "./salome context\n";
+        msg += "cd $MESHGEMSHOME/stubs\n";
+        msg += "mpicc meshgems_mpi.c -DMESHGEMS_LINUX_BUILD -I../include -shared -fPIC -o $MESHGEMSHOME/lib/Linux_64/libmeshgems_mpi.so";
+        return error(msg);
+      }
+      return error(log);
+    }
 
     // set --launchtetra=no
     int yesPos = run_GHS3DPRL.Search("launchtetra") + sizeof("launchtetra");
@@ -357,55 +379,62 @@ bool GHS3DPRLPlugin_GHS3DPRL::Compute(SMESH_Mesh&         theMesh,
     cout<<"  Write input file for mg-tetra_hpc "<<fileskinmesh<<"...";
     cout<<" ...done\n";
   }
-  fileskinmed=path + "GHS3DPRL_skin.med";
-  cout<<"  Write file "<<fileskinmed<<"...";
-  theMesh.ExportMED(fileskinmed.ToCString(),"SKIN_INITIAL",true);
-  cout<<" ...done\n\n";
-
-  cout<<"GHS3DPRL command :\n  "<<run_GHS3DPRL.ToCString()<<endl;
-  //sometimes it is better to wait flushing files on slow filesystem...
-  system( "sleep 3" );
-  //launch tetrahpc2med which launch mg-tetra_hpc.py which launch mg-tetra_hpc(_mpi?).exe
-  res = system( run_GHS3DPRL.ToCString() );
-  if (res > 0) 
+  // if mpi, convert meshes to med with xml master file
+  if (!_Multithread)
   {
-    pluginerror = pluginerror + "PROBLEM tetrahpc2med command";
-    cout<<pluginerror<<endl;
-    error(COMPERR_ALGO_FAILED, pluginerror.ToCString());
-    return false; //but it is not a problem but if true my message is overwritten
-  }
-  system( "sleep 3" );
-
-  if (_Background) {
-    pluginerror = pluginerror + "backgrounding... plugin is not waiting for output files "+ casenamemed + "_*.med";
-    cout<<pluginerror<<endl;
-    error(COMPERR_NO_MESH_ON_SHAPE, pluginerror.ToCString());
-    return false; //but it is not a problem but if true my message is overwritten
-    //return true; //but it is not a problem,
-  }
+    fileskinmed=path + casenamemed + "_skin.med";
+    cout<<"  Write file "<<fileskinmed<<"...";
+    theMesh.ExportMED(fileskinmed.ToCString(),"SKIN_INITIAL",true);
+    cout<<" ...done\n\n";
+
+    cout<<"GHS3DPRL command :\n  "<<run_GHS3DPRL.ToCString()<<endl;
+    //sometimes it is better to wait flushing files on slow filesystem...
+    system( "sleep 3" );
+    //launch tetrahpc2med which launch mg-tetra_hpc.py which launch mg-tetra_hpc(_mpi?).exe
+    std::cout << "run_GHS3DPRL cmd: " << run_GHS3DPRL << std::endl;
+    res = system( run_GHS3DPRL.ToCString() );
+    if (res > 0)
+    {
+      pluginerror = pluginerror + "PROBLEM tetrahpc2med command";
+      cout<<pluginerror<<endl;
+      error(COMPERR_ALGO_FAILED, pluginerror.ToCString());
+      return false; //but it is not a problem but if true my message is overwritten
+    }
+    system( "sleep 3" );
+
+    if (_Background) {
+      pluginerror = pluginerror + "backgrounding... plugin is not waiting for output files "+ path +casenamemed + "_*.med";
+      cout<<pluginerror<<endl;
+      error(COMPERR_NO_MESH_ON_SHAPE, pluginerror.ToCString());
+      return false; //but it is not a problem but if true my message is overwritten
+      //return true; //but it is not a problem,
+    }
 
-  // read a result, GHS3DPRL_Out is the name of master file (previous xml format)
-  FILE * aResultFile = fopen( GHS3DPRL_Outxml.ToCString(), "r" );
-  if (aResultFile){
-    Ok = true;
-    fclose(aResultFile);
-    cout<<"GHS3DPRL OK output master file "<<casenamemed<<".xml exist !\n\n";
-    pluginerror = pluginerror + "MG-tetra_hpc mesh(es) not loaded in memory, are stored in files "+ casenamemed + "_*.med";
-    cout<<pluginerror<<endl;
-    error(COMPERR_WARNING, pluginerror.ToCString() );
-    if (!_KeepFiles) system( run_nokeep_files.ToCString() );
-  }
-  else{
-    Ok = false; //it is a problem AND my message is NOT overwritten
-    pluginerror = pluginerror + "output master file " + casenamemed + ".xml do not exist";
-    cout<<pluginerror<<endl;
-    error(COMPERR_ALGO_FAILED, pluginerror.ToCString() );
-    cout<<"GHS3DPRL KO output files "<<GHS3DPRL_Out<<" do not exist ! see intermediates files keeped:\n";
-    TCollection_AsciiString run_list_files("ls -alt ");
-    run_list_files +=  GHS3DPRL_Out + "* " + GHS3DPRL_In + "* " + path + "tetrahpc.log";
-    system( run_list_files.ToCString() );
-    cout<<endl;
+    // read a result, GHS3DPRL_Out is the name of master file (previous xml format)
+    FILE * aResultFile = fopen( GHS3DPRL_Outxml.ToCString(), "r" );
+    if (aResultFile){
+      Ok = true;
+      fclose(aResultFile);
+      cout<<"GHS3DPRL OK output master file "<<casenamemed<<".xml exist !\n\n";
+      pluginerror = pluginerror + "MG-tetra_hpc mesh(es) not loaded in memory, are stored in files "+ path + casenamemed + "_*.med";
+      cout<<pluginerror<<endl;
+      error(COMPERR_WARNING, pluginerror.ToCString() );
+      if (!_KeepFiles) system( run_nokeep_files.ToCString() );
+    }
+    else{
+      Ok = false; //it is a problem AND my message is NOT overwritten
+      pluginerror = pluginerror + "output master file " + casenamemed + ".xml do not exist";
+      cout<<pluginerror<<endl;
+      error(COMPERR_ALGO_FAILED, pluginerror.ToCString() );
+      cout<<"GHS3DPRL KO output files "<<GHS3DPRL_Out<<" do not exist ! see intermediates files keeped:\n";
+      TCollection_AsciiString run_list_files("ls -alt ");
+      run_list_files +=  GHS3DPRL_Out + "* " + GHS3DPRL_In + "* " + logFileName;
+      system( run_list_files.ToCString() );
+      cout<<endl;
+    }
   }
+  else
+    Ok = true;
 
   return Ok;
 }