Salome HOME
#18963 Minimize compiler warnings
[modules/med.git] / src / ParaMEDMEMComponent / MPIMEDCouplingFieldDoubleServant.cxx
1 // Copyright (C) 2007-2020  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "MPIMEDCouplingFieldDoubleServant.hxx"
21 #include "utilities.h"
22 using namespace std;
23 using namespace MEDCoupling;
24
25 typedef struct
26 {
27   bool exception;
28   string msg;
29 } except_st;
30
31 MPIMEDCouplingFieldDoubleServant::MPIMEDCouplingFieldDoubleServant(CORBA::ORB_ptr orb,PortableServer::POA_ptr poa,ParaMEDMEMComponent_i *pcompo,MEDCouplingFieldDouble* field):ParaMEDCouplingFieldDoubleServant(orb,field)
32 {
33   _pcompo = pcompo;
34   _field = field;
35
36   CORBA::Object_var my_ref = poa->servant_to_reference (pcompo);
37   SALOME_MED::ParaMEDMEMComponent_var compo = SALOME_MED::ParaMEDMEMComponent::_narrow(my_ref);
38   _ref = orb->object_to_string(compo);
39
40   Engines::MPIObject_var pobj = POA_SALOME_MED::MPIMEDCouplingFieldDoubleCorbaInterface::_this();
41   BCastIOR(orb,pobj,false);
42 }
43
44 void MPIMEDCouplingFieldDoubleServant::getDataByMPI(const char* coupling)
45 {
46   except_st *est;
47   void *ret_th;
48   pthread_t *th = 0;
49
50   if(_numproc == 0)
51     {
52       th = new pthread_t[_nbproc];
53       for(int ip=1;ip<_nbproc;ip++)
54         {
55           thread_st *st = new thread_st;
56           st->ip = ip;
57           st->tior = _tior;
58           st->coupling = coupling;
59           pthread_create(&(th[ip]),NULL,th_getdatabympi,(void*)st);
60         }
61     }
62
63   try
64     {
65       _pcompo->_getOutputField(coupling,_field);
66     }
67   catch(const std::exception &ex)
68     {
69       MESSAGE(ex.what());
70       THROW_SALOME_CORBA_EXCEPTION(ex.what(),SALOME::INTERNAL_ERROR);
71     }
72     
73   if(_numproc == 0)
74     {
75       for(int ip=1;ip<_nbproc;ip++)
76         {
77           pthread_join(th[ip],&ret_th);
78           est = (except_st*)ret_th;
79           if(est->exception)
80             {
81               ostringstream msg;
82               msg << "[" << ip << "] " << est->msg;
83               THROW_SALOME_CORBA_EXCEPTION(msg.str().c_str(),SALOME::INTERNAL_ERROR);
84             }
85           delete est;
86         }
87       delete[] th;
88     }
89 }
90
91 void *th_getdatabympi(void *s)
92 {
93   ostringstream msg;
94   thread_st *st = (thread_st*)s;
95   except_st *est = new except_st;
96   est->exception = false;
97
98   try
99     {
100       SALOME_MED::MPIMEDCouplingFieldDoubleCorbaInterface_var fieldPtr=SALOME_MED::MPIMEDCouplingFieldDoubleCorbaInterface::_narrow((*(st->tior))[st->ip]);
101       fieldPtr->getDataByMPI(st->coupling.c_str());
102     }
103   catch(const SALOME::SALOME_Exception &ex)
104     {
105       est->exception = true;
106       est->msg = ex.details.text;
107     }
108   catch(const CORBA::Exception &ex)
109     {
110       est->exception = true;
111       msg << "CORBA::Exception: " << ex;
112       est->msg = msg.str();
113     }
114   delete st;
115   return((void*)est);
116 }
117
118 char *MPIMEDCouplingFieldDoubleServant::getRef()
119 {
120   return CORBA::string_dup(_ref.c_str());
121 }
122