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");
127 // struct sigaction action;
128 // action.sa_handler = &test;
129 // sigaction(SIGSEGV, &action, NULL);
134 MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE ,&provided);
136 if(getenv ("DEBUGGER"))
138 std::cerr << "Unexpected: unexpected exception !" << std::endl;
139 setsig(SIGSEGV,&Handler);
140 set_terminate(&terminateHandler);
141 set_unexpected(&unexpectedHandler);
144 cerr << "Level MPI_THREAD_SINGLE : " << MPI_THREAD_SINGLE << endl;
145 cerr << "Level MPI_THREAD_SERIALIZED : " << MPI_THREAD_SERIALIZED << endl;
146 cerr << "Level MPI_THREAD_FUNNELED : " << MPI_THREAD_FUNNELED << endl;
147 cerr << "Level MPI_THREAD_MULTIPLE : " << MPI_THREAD_MULTIPLE << endl;
148 cerr << "Level provided : " << provided << endl;
150 // Initialise the ORB.
151 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
152 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
153 CORBA::ORB_var orb = init(0, 0);
154 //CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
156 // Code pour choisir le reseau infiniband .....
157 /* string hostname_temp = GetHostname();
158 hostent * t = gethostbyname(hostname_temp.c_str());
159 cerr << " AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " << t->h_addr << " " << hostname_temp << endl;
160 cerr << t->h_addr << endl;
161 in_addr * address=(in_addr * ) t->h_addr;
162 cerr << inet_ntoa(* address) << endl;
163 string ip = inet_ntoa(* address);
164 cerr << " AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " << endl;
165 string com = "giop:tcp:" + ip + ":";
166 const char* options[][2] = { { "endPoint", com.c_str() }, { 0, 0 } };
167 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB4", options);
169 char * containerName = "";
171 containerName = argv[1];
174 char * hostname = "";
180 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
181 PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
182 PortableServer::POAManager_var pman = root_poa->the_POAManager();
185 // add this container to the kill list
187 sprintf(aCommand, "addToKillList.py %d SALOME_ParallelContainerNodeMpi", getpid());
191 SALOME_NamingService * ns = new SALOME_NamingService(CORBA::ORB::_duplicate(orb));
192 // On récupère le proxy
193 string proxyNameInNS = ns->BuildContainerNameForNS(containerName, hostname);
194 obj = ns->Resolve(proxyNameInNS.c_str());
195 char * proxy_ior = orb->object_to_string(obj);
198 string name(containerName);
199 string node_name = name + "Node";
200 Engines_Parallel_Container_i * servant = new Engines_Parallel_Container_i(CORBA::ORB::_duplicate(orb), proxy_ior,
202 (char*) node_name.c_str(),
205 paco_fabrique_manager * pfm = paco_getFabriqueManager();
206 pfm->register_com("mpi", new paco_mpi_fabrique());
207 pfm->register_thread("omni", new paco_omni_fabrique());
210 PaCO_operation * global_ptr = servant->getContext("global_paco_context");
211 MPI_Comm group = MPI_COMM_WORLD;
212 global_ptr->setLibCom("mpi", &group);
213 global_ptr->setLibThread("omni");
216 PortableServer::ObjectId * _id = root_poa->activate_object(servant);
217 servant->set_id(_id);
218 obj = root_poa->id_to_reference(*_id);
220 // In the NamingService
221 string hostname = GetHostname();
224 MPI_Comm_rank(MPI_COMM_WORLD, &myid);
226 snprintf(buffer, 5, "%d", myid);
227 node_name = node_name + buffer;
228 string _containerName = ns->BuildContainerNameForNS((char*) node_name.c_str(),
230 cerr << "---------" << _containerName << "----------" << endl;
231 ns->Register(obj, _containerName.c_str());
235 catch(CORBA::SystemException&)
237 INFOS("Caught CORBA::SystemException.");
239 catch(PortableServer::POA::ServantAlreadyActive&)
241 INFOS("Caught CORBA::ServantAlreadyActiveException");
243 catch(CORBA::Exception&)
245 INFOS("Caught CORBA::Exception.");
247 catch(std::exception& exc)
249 INFOS("Caught std::exception - "<<exc.what());
253 INFOS("Caught unknown exception.");