1 // Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SALOME ParallelContainerNodeMpi : Launch mpi PaCO++ object nodes
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 "ArgvKeeper.hxx"
50 #include "Basics_Utils.hxx"
51 #include "SALOMETraceCollector.hxx"
54 #include "Container_init_python.hxx"
61 std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
62 std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
63 std::cerr << "SIGSEGV in :" << getpid() << std::endl;
64 std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
65 std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
70 typedef void (*sighandler_t)(int);
71 sighandler_t setsig(int sig, sighandler_t handler)
73 struct sigaction context, ocontext;
74 context.sa_handler = handler;
75 sigemptyset(&context.sa_mask);
77 if (sigaction(sig, &context, &ocontext) == -1)
79 return ocontext.sa_handler;
84 if(getenv ("DEBUGGER"))
86 std::stringstream exec;
87 exec << "$DEBUGGER SALOME_ParallelContainerNodeMpi " << getpid() << "&";
88 std::cerr << exec.str() << std::endl;
89 system(exec.str().c_str());
94 void Handler(int theSigId)
96 std::cerr << "SIGSEGV: " << std::endl;
98 //to exit or not to exit
102 void terminateHandler(void)
104 std::cerr << "Terminate: not managed exception !" << std::endl;
108 void unexpectedHandler(void)
110 std::cerr << "Unexpected: unexpected exception !" << std::endl;
114 int main(int argc, char* argv[])
116 INFOS("Launching a parallel Mpi container node");
121 MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE ,&provided);
122 MPI_Comm_rank(MPI_COMM_WORLD,&myid);
125 if(getenv ("DEBUGGER"))
127 std::cerr << "Unexpected: unexpected exception !" << std::endl;
128 setsig(SIGSEGV,&Handler);
129 set_terminate(&terminateHandler);
130 //set_terminate(__gnu_cxx::__verbose_terminate_handler);
131 set_unexpected(&unexpectedHandler);
135 std::cerr << "Level MPI_THREAD_SINGLE : " << MPI_THREAD_SINGLE << std::endl;
136 std::cerr << "Level MPI_THREAD_SERIALIZED : " << MPI_THREAD_SERIALIZED << std::endl;
137 std::cerr << "Level MPI_THREAD_FUNNELED : " << MPI_THREAD_FUNNELED << std::endl;
138 std::cerr << "Level MPI_THREAD_MULTIPLE : " << MPI_THREAD_MULTIPLE << std::endl;
139 std::cerr << "Level provided : " << provided << std::endl;
140 // Initialise the ORB.
141 SetArgcArgv(argc, argv);
142 CORBA::ORB_var orb = KERNEL::GetRefToORB();
143 KERNEL_PYTHON::init_python(argc,argv);
145 // Code pour choisir le reseau infiniband .....
146 /* std::string hostname_temp = GetHostname();
147 hostent * t = gethostbyname(hostname_temp.c_str());
148 std::cerr << " AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " << t->h_addr << " " << hostname_temp << std::endl;
149 std::cerr << t->h_addr << std::endl;
150 in_addr * address=(in_addr * ) t->h_addr;
151 std::cerr << inet_ntoa(* address) << std::endl;
152 std::string ip = inet_ntoa(* address);
153 std::cerr << " AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " << std::endl;
154 std::string com = "giop:tcp:" + ip + ":";
155 const char* options[][2] = { { "endPoint", com.c_str() }, { 0, 0 } };
156 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB4", options);
158 std::string containerName("");
159 containerName = argv[1];
161 std::string proxy_hostname("");
163 proxy_hostname = argv[3];
167 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
168 PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
169 PortableServer::POAManager_var pman = root_poa->the_POAManager();
172 // add this container to the kill list
174 sprintf(aCommand, "addToKillList.py %d SALOME_ParallelContainerNodeMpi", getpid());
178 SALOME_NamingService * ns = new SALOME_NamingService(CORBA::ORB::_duplicate(orb));
179 // On r�cup�re le proxy
180 std::string proxyNameInNS = ns->BuildContainerNameForNS(containerName.c_str(),
181 proxy_hostname.c_str());
182 obj = ns->Resolve(proxyNameInNS.c_str());
183 char * proxy_ior = orb->object_to_string(obj);
186 std::string node_name = containerName + "Node";
187 Engines_Parallel_Container_i * servant = new Engines_Parallel_Container_i(CORBA::ORB::_duplicate(orb),
193 paco_fabrique_manager * pfm = paco_getFabriqueManager();
194 pfm->register_com("mpi", new paco_mpi_fabrique());
195 pfm->register_thread("omni", new paco_omni_fabrique());
196 servant->setLibCom("mpi", MPI_COMM_WORLD);
197 servant->setLibThread("omni");
200 obj = servant->_this();
202 // In the NamingService
203 std::string hostname = Kernel_Utils::GetHostname();
206 MPI_Comm_rank(MPI_COMM_WORLD, &myid);
208 snprintf(buffer, 5, "%d", myid);
209 node_name = node_name + buffer;
211 // We register nodes in two different parts
212 // In the real machine name and in the proxy machine
213 std::string _containerName = ns->BuildContainerNameForNS(node_name.c_str(),
215 std::string _proxymachine_containerName = ns->BuildContainerNameForNS(node_name.c_str(),
216 proxy_hostname.c_str());
217 std::cerr << "Register container node : " << _containerName << std::endl;
218 std::cerr << "Register container node : " << _proxymachine_containerName << std::endl;
219 ns->Register(obj, _containerName.c_str());
220 ns->Register(obj, _proxymachine_containerName.c_str());
224 //Delete python container that destroy orb from python (pyCont._orb.destroy())
227 CORBA::string_free(proxy_ior);
230 catch (PaCO::PACO_Exception& e)
232 INFOS("Caught PaCO::PACO_Exception");
233 std::cerr << e << std::endl;
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.");