1 // Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 //=============================================================================
24 // File : TestMPIContainer.cxx
25 // Created : mer jui 4 13:11:27 CEST 2003
26 // Author : Bernard SECHER, 2003
29 //=============================================================================
31 #include "utilities.h"
35 #include <SALOMEconfig.h>
36 #include CORBA_CLIENT_HEADER(SALOME_MPIContainer)
37 #include CORBA_CLIENT_HEADER(SALOME_TestMPIComponent)
39 #include "ArgvKeeper.hxx"
40 #include "Basics_Utils.hxx"
41 #include "SALOME_NamingService.hxx"
44 int main (int argc, char * argv[])
47 // Initializing omniORB
48 SetArgcArgv(argc, argv);
49 CORBA::ORB_ptr orb = KERNEL::GetRefToORB();
50 // SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
57 if( argc != 3 || strcmp(argv[1],"-np") ){
58 std::cout << "Usage: TestMPIContainer -np nbproc" << std::endl;
62 // Obtain a reference to the root POA
63 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
64 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
66 // Use Name Service to find container
67 SALOME_NamingService NS(orb) ;
68 std::string containerName = "/Containers/" ;
69 std::string hostName = Kernel_Utils::GetHostname();
70 containerName += hostName + "/MPIFactoryServer_" + argv[2];
72 std::string dirn(getenv("KERNEL_ROOT_DIR"));
74 dirn += "/lib/salome/libSalomeTestMPIComponentEngine.dylib";
76 dirn += "/lib/salome/libSalomeTestMPIComponentEngine.so";
79 // Try to resolve MPI Container
80 obj = NS.Resolve(containerName.c_str()) ;
81 Engines::MPIContainer_var iGenFact = Engines::MPIContainer::_narrow(obj);
83 if(CORBA::is_nil(iGenFact)){
85 // Launch MPI Container
86 std::string cmd("mpirun -np ");
89 cmd += getenv("KERNEL_ROOT_DIR");
90 cmd += "/bin/salome/SALOME_MPIContainer MPIFactoryServer_";
94 status = system(cmd.c_str());
96 INFOS("TestMPIContainer launch MPI Container failed (system command status -1)") ;
98 else if (status == 217) {
99 INFOS("TestMPIContainer launch MPI Container failed (system command status 217)") ;
102 // Try to resolve MPI Container
106 obj = NS.Resolve(containerName.c_str()) ;
107 iGenFact = Engines::MPIContainer::_narrow(obj);
108 MESSAGE("Waiting for MPI Container " << containerName << " : it = " << it );
109 }while( CORBA::is_nil(iGenFact) && (it++<15) );
113 if(CORBA::is_nil(iGenFact)){
114 MESSAGE("launching container failed");
119 Engines::TestMPIComponent_var m1;
121 // for (int iter = 0; iter < 1 ; iter++){
122 // MESSAGE("----------------------------------------------------" << iter);
123 obj = iGenFact->load_impl("TestMPIComponent",dirn.c_str());
125 INFOS("Get Handle on MPI Component");
126 m1 = Engines::TestMPIComponent::_narrow(obj);
127 if(CORBA::is_nil(m1)){
128 INFOS("getting handle on MPI component failed");
132 // Display MPI component in naming service
133 std::string cmdn = "nameclt list Containers.dir/";
136 system(cmdn.c_str());
137 cmdn = "nameclt list Containers.dir/";
139 cmdn += ".dir/MPIFactoryServer_";
142 system(cmdn.c_str());
144 INFOS("Unload MPI Component");
145 iGenFact->remove_impl(m1) ;
149 // // iGenFact->finalize_removal() ;
151 iGenFact->Shutdown();
152 // INFOS("shut down corba server for Test MPI Container");
155 catch(CORBA::COMM_FAILURE& ex) {
156 INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.");
158 catch(CORBA::SystemException&) {
159 INFOS("Caught a CORBA::SystemException.");
161 catch(CORBA::Exception&) {
162 INFOS("Caught CORBA::Exception.");
165 INFOS("Caught unknown exception.");
169 // delete myThreadTrace;