1 // using namespace std;
2 //=============================================================================
3 // File : TestMPIContainer.cxx
4 // Created : mer jui 4 13:11:27 CEST 2003
5 // Author : Bernard SECHER, 2003
7 // Copyright : CEA 2003
9 //=============================================================================
11 #include "utilities.h"
15 #include <SALOMEconfig.h>
16 #include CORBA_CLIENT_HEADER(SALOME_MPIContainer)
17 #include CORBA_CLIENT_HEADER(SALOME_TestMPIComponent)
19 # include "Utils_ORB_INIT.hxx"
20 # include "Utils_SINGLETON.hxx"
21 #include "SALOME_NamingService.hxx"
23 #include "LocalTraceCollector.hxx"
26 int main (int argc, char * argv[])
29 // Initializing omniORB
30 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
31 CORBA::ORB_var &orb = init( argc , argv ) ;
32 LocalTraceCollector *myThreadTrace = LocalTraceCollector::instance(orb);
39 if( argc != 3 || strcmp(argv[1],"-np") ){
40 cout << "Usage: TestMPIContainer -np nbproc" << endl;
44 // Obtain a reference to the root POA
45 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
46 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
48 // Use Name Service to find container
49 SALOME_NamingService NS(orb) ;
50 string containerName = "/Containers/" ;
51 string hostName = GetHostname();
52 containerName += hostName + "/MPIFactoryServer_" + argv[2];
54 string dirn(getenv("KERNEL_ROOT_DIR"));
55 dirn += "/lib/salome/libSalomeTestMPIComponentEngine.so";
57 // Try to resolve MPI Container
58 obj = NS.Resolve(containerName.c_str()) ;
59 Engines::MPIContainer_var iGenFact = Engines::MPIContainer::_narrow(obj);
61 if(CORBA::is_nil(iGenFact)){
63 // Launch MPI Container
64 string cmd("mpirun -np ");
67 cmd += getenv("KERNEL_ROOT_DIR");
68 cmd += "/bin/salome/SALOME_MPIContainer MPIFactoryServer_";
72 status = system(cmd.c_str());
74 INFOS("TestMPIContainer launch MPI Container failed (system command status -1)") ;
76 else if (status == 217) {
77 INFOS("TestMPIContainer launch MPI Container failed (system command status 217)") ;
80 // Try to resolve MPI Container
84 obj = NS.Resolve(containerName.c_str()) ;
85 iGenFact = Engines::MPIContainer::_narrow(obj);
86 MESSAGE("Waiting for MPI Container " << containerName << " : it = " << it );
87 }while( CORBA::is_nil(iGenFact) && (it++<15) );
91 if(CORBA::is_nil(iGenFact)){
92 MESSAGE("launching container failed");
97 Engines::TestMPIComponent_var m1;
99 // for (int iter = 0; iter < 1 ; iter++){
100 // MESSAGE("----------------------------------------------------" << iter);
101 obj = iGenFact->load_impl("TestMPIComponent",dirn.c_str());
103 INFOS("Get Handle on MPI Component");
104 m1 = Engines::TestMPIComponent::_narrow(obj);
105 if(CORBA::is_nil(m1)){
106 INFOS("getting handle on MPI component failed");
111 INFOS("Unload MPI Component");
112 iGenFact->remove_impl(m1) ;
116 // // iGenFact->finalize_removal() ;
118 iGenFact->MPIShutdown();
119 // INFOS("shut down corba server for Test MPI Container");
122 catch(CORBA::COMM_FAILURE& ex) {
123 INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.");
125 catch(CORBA::SystemException&) {
126 INFOS("Caught a CORBA::SystemException.");
128 catch(CORBA::Exception&) {
129 INFOS("Caught CORBA::Exception.");
132 INFOS("Caught unknown exception.");
136 delete myThreadTrace;