1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // using namespace std;
21 //=============================================================================
22 // File : TestMPIContainer.cxx
23 // Created : mer jui 4 13:11:27 CEST 2003
24 // Author : Bernard SECHER, 2003
27 //=============================================================================
29 #include "utilities.h"
33 #include <SALOMEconfig.h>
34 #include CORBA_CLIENT_HEADER(SALOME_MPIContainer)
35 #include CORBA_CLIENT_HEADER(SALOME_TestMPIComponent)
37 # include "Utils_ORB_INIT.hxx"
38 # include "Utils_SINGLETON.hxx"
39 #include "SALOME_NamingService.hxx"
43 int main (int argc, char * argv[])
46 // Initializing omniORB
47 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
48 CORBA::ORB_var &orb = init( argc , argv ) ;
49 // SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
56 if( argc != 3 || strcmp(argv[1],"-np") ){
57 cout << "Usage: TestMPIContainer -np nbproc" << endl;
61 // Obtain a reference to the root POA
62 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
63 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
65 // Use Name Service to find container
66 SALOME_NamingService NS(orb) ;
67 string containerName = "/Containers/" ;
68 string hostName = GetHostname();
69 containerName += hostName + "/MPIFactoryServer_" + argv[2];
71 string dirn(getenv("KERNEL_ROOT_DIR"));
72 dirn += "/lib/salome/libSalomeTestMPIComponentEngine.so";
74 // Try to resolve MPI Container
75 obj = NS.Resolve(containerName.c_str()) ;
76 Engines::MPIContainer_var iGenFact = Engines::MPIContainer::_narrow(obj);
78 if(CORBA::is_nil(iGenFact)){
80 // Launch MPI Container
81 string cmd("mpirun -np ");
84 cmd += getenv("KERNEL_ROOT_DIR");
85 cmd += "/bin/salome/SALOME_MPIContainer MPIFactoryServer_";
89 status = system(cmd.c_str());
91 INFOS("TestMPIContainer launch MPI Container failed (system command status -1)") ;
93 else if (status == 217) {
94 INFOS("TestMPIContainer launch MPI Container failed (system command status 217)") ;
97 // Try to resolve MPI Container
101 obj = NS.Resolve(containerName.c_str()) ;
102 iGenFact = Engines::MPIContainer::_narrow(obj);
103 MESSAGE("Waiting for MPI Container " << containerName << " : it = " << it );
104 }while( CORBA::is_nil(iGenFact) && (it++<15) );
108 if(CORBA::is_nil(iGenFact)){
109 MESSAGE("launching container failed");
114 Engines::TestMPIComponent_var m1;
116 // for (int iter = 0; iter < 1 ; iter++){
117 // MESSAGE("----------------------------------------------------" << iter);
118 obj = iGenFact->load_impl("TestMPIComponent",dirn.c_str());
120 INFOS("Get Handle on MPI Component");
121 m1 = Engines::TestMPIComponent::_narrow(obj);
122 if(CORBA::is_nil(m1)){
123 INFOS("getting handle on MPI component failed");
128 INFOS("Unload MPI Component");
129 iGenFact->remove_impl(m1) ;
133 // // iGenFact->finalize_removal() ;
135 iGenFact->Shutdown();
136 // INFOS("shut down corba server for Test MPI Container");
139 catch(CORBA::COMM_FAILURE& ex) {
140 INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.");
142 catch(CORBA::SystemException&) {
143 INFOS("Caught a CORBA::SystemException.");
145 catch(CORBA::Exception&) {
146 INFOS("Caught CORBA::Exception.");
149 INFOS("Caught unknown exception.");
153 // delete myThreadTrace;