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"
25 int main (int argc, char * argv[])
33 if( argc != 3 || strcmp(argv[1],"-np") ){
34 cout << "Usage: TestMPIContainer -np nbproc" << endl;
38 // Initializing omniORB
39 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
41 // Obtain a reference to the root POA
42 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
43 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
45 // Use Name Service to find container
46 SALOME_NamingService NS(orb) ;
47 string containerName = "/Containers/" ;
48 string hostName = GetHostname();
49 containerName += hostName + "/MPIFactoryServer_" + argv[2];
51 MESSAGE(containerName);
53 string dirn(getenv("KERNEL_ROOT_DIR"));
54 dirn += "/lib/salome/libSalomeTestMPIComponentEngine.so";
55 MESSAGE(dirn.c_str());
57 // Try to resolve MPI Container
58 obj = NS.Resolve(containerName.c_str()) ;
59 Engines::Container_var iGenFact = Engines::Container::_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::Container::_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("echec recuperation poignee container");
96 Engines::TestMPIComponent_var m1;
98 for (int iter = 0; iter < 1 ; iter++){
99 MESSAGE("----------------------------------------------------" << iter);
100 obj = iGenFact->load_impl("TestMPIComponent",dirn.c_str());
102 m1 = Engines::TestMPIComponent::_narrow(obj);
103 if(CORBA::is_nil(m1)){
104 INFOS("echec recuperation poignee composant");
109 SCRUTE(m1->instanceName());
110 INFOS("Lancement de coucou");
112 INFOS("On remove le composant");
113 iGenFact->remove_impl(m1) ;
118 iGenFact->finalize_removal() ;
121 catch(CORBA::COMM_FAILURE& ex) {
122 INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.");
124 catch(CORBA::SystemException&) {
125 INFOS("Caught a CORBA::SystemException.");
127 catch(CORBA::Exception&) {
128 INFOS("Caught CORBA::Exception.");
131 INFOS("Caught unknown exception.");