1 // SALOME ParallelContainerNodeMpi : Launch mpi PaCO++ object nodes
3 // Copyright (C) 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.
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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SALOME_ParallelContainerNodeMpi.cxx
25 // Author : André Ribes, EDF
26 // Module : SALOME PARALLEL
38 #include "SALOME_ParallelContainer_i.hxx"
41 #include <paco_omni.h>
46 #include "SALOME_NamingService.hxx"
48 #include "utilities.h"
49 #include "Utils_ORB_INIT.hxx"
50 #include "Utils_SINGLETON.hxx"
51 #include "SALOMETraceCollector.hxx"
59 void test(int sigval) {
60 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
61 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
62 cerr << "SIGSEGV in :" << getpid() << endl;
63 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
64 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
69 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
70 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
71 cerr << "SIGSEGV in :" << getpid() << endl;
72 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
73 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
78 typedef void (*sighandler_t)(int);
79 sighandler_t setsig(int sig, sighandler_t handler)
81 struct sigaction context, ocontext;
82 context.sa_handler = handler;
83 sigemptyset(&context.sa_mask);
85 if (sigaction(sig, &context, &ocontext) == -1)
87 return ocontext.sa_handler;
92 if(getenv ("DEBUGGER"))
94 std::stringstream exec;
95 exec << "$DEBUGGER SALOME_ParallelContainerNodeMpi " << getpid() << "&";
96 std::cerr << exec.str() << std::endl;
97 system(exec.str().c_str());
102 void Handler(int theSigId)
104 std::cerr << "SIGSEGV: " << std::endl;
106 //to exit or not to exit
110 void terminateHandler(void)
112 std::cerr << "Terminate: not managed exception !" << std::endl;
116 void unexpectedHandler(void)
118 std::cerr << "Unexpected: unexpected exception !" << std::endl;
122 int main(int argc, char* argv[])
124 INFOS("Launching a parallel Mpi container node");
129 MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE ,&provided);
130 MPI_Comm_rank(MPI_COMM_WORLD,&myid);
132 if(getenv ("DEBUGGER"))
134 std::cerr << "Unexpected: unexpected exception !" << std::endl;
135 setsig(SIGSEGV,&Handler);
136 set_terminate(&terminateHandler);
137 set_unexpected(&unexpectedHandler);
139 cerr << "Level MPI_THREAD_SINGLE : " << MPI_THREAD_SINGLE << endl;
140 cerr << "Level MPI_THREAD_SERIALIZED : " << MPI_THREAD_SERIALIZED << endl;
141 cerr << "Level MPI_THREAD_FUNNELED : " << MPI_THREAD_FUNNELED << endl;
142 cerr << "Level MPI_THREAD_MULTIPLE : " << MPI_THREAD_MULTIPLE << endl;
143 cerr << "Level provided : " << provided << endl;
144 // Initialise the ORB.
145 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
147 // Code pour choisir le reseau infiniband .....
148 /* string hostname_temp = GetHostname();
149 hostent * t = gethostbyname(hostname_temp.c_str());
150 cerr << " AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " << t->h_addr << " " << hostname_temp << endl;
151 cerr << t->h_addr << endl;
152 in_addr * address=(in_addr * ) t->h_addr;
153 cerr << inet_ntoa(* address) << endl;
154 string ip = inet_ntoa(* address);
155 cerr << " AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " << endl;
156 string com = "giop:tcp:" + ip + ":";
157 const char* options[][2] = { { "endPoint", com.c_str() }, { 0, 0 } };
158 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB4", options);
160 std::string containerName("");
161 containerName = argv[1];
163 std::string hostname("");
169 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
170 PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
171 PortableServer::POAManager_var pman = root_poa->the_POAManager();
174 // add this container to the kill list
176 sprintf(aCommand, "addToKillList.py %d SALOME_ParallelContainerNodeMpi", getpid());
180 SALOME_NamingService * ns = new SALOME_NamingService(CORBA::ORB::_duplicate(orb));
181 // On récupère le proxy
182 string proxyNameInNS = ns->BuildContainerNameForNS(containerName.c_str(),
184 obj = ns->Resolve(proxyNameInNS.c_str());
185 char * proxy_ior = orb->object_to_string(obj);
188 string node_name = containerName + "Node";
189 Engines_Parallel_Container_i * servant =
190 new Engines_Parallel_Container_i(CORBA::ORB::_duplicate(orb),
194 (char*) node_name.c_str(),
197 paco_fabrique_manager * pfm = paco_getFabriqueManager();
198 pfm->register_com("mpi", new paco_mpi_fabrique());
199 pfm->register_thread("omni", new paco_omni_fabrique());
200 MPI_Comm group = MPI_COMM_WORLD;
201 servant->setLibCom("mpi", &group);
202 servant->setLibThread("omni");
205 PortableServer::ObjectId * _id = root_poa->activate_object(servant);
206 servant->set_id(_id);
207 obj = root_poa->id_to_reference(*_id);
209 // In the NamingService
210 string hostname = GetHostname();
213 MPI_Comm_rank(MPI_COMM_WORLD, &myid);
215 snprintf(buffer, 5, "%d", myid);
216 node_name = node_name + buffer;
217 string _containerName = ns->BuildContainerNameForNS(node_name.c_str(),
219 cerr << "---------" << _containerName << "----------" << endl;
220 ns->Register(obj, _containerName.c_str());
224 catch (PaCO::PACO_Exception& e)
226 INFOS("Caught PaCO::PACO_Exception");
227 std::cerr << e << std::endl;
229 catch(CORBA::SystemException&)
231 INFOS("Caught CORBA::SystemException.");
233 catch(PortableServer::POA::ServantAlreadyActive&)
235 INFOS("Caught CORBA::ServantAlreadyActiveException");
237 catch(CORBA::Exception&)
239 INFOS("Caught CORBA::Exception.");
241 catch(std::exception& exc)
243 INFOS("Caught std::exception - "<<exc.what());
247 INFOS("Caught unknown exception.");