12#include "arcane/IMesh.h"
13#include "arcane/IApplication.h"
14#include "arcane/IParallelMng.h"
15#include "arcane/utils/ValueConvert.h"
16#include "arcane/FactoryService.h"
17#include "arcane/ServiceFinder2.h"
18#include "arcane/SharedVariable.h"
19#include "arcane/CommonVariables.h"
20#include "arcane/utils/ScopedPtr.h"
21#include "arcane/AbstractService.h"
23#include "arcane/utils/PlatformUtils.h"
24#include "arcane/utils/IOnlineDebuggerService.h"
25#include "arcane/ITransferValuesParallelOperation.h"
26#include "arcane/ServiceBuilder.h"
28#include "arcane/hyoda/HyodaArc.h"
29#include "arcane/hyoda/HyodaTcp.h"
30#include "arcane/hyoda/HyodaIceT.h"
31#include "arcane/hyoda/HyodaMatrix.h"
32#include "arcane/hyoda/HyodaPapi.h"
51# define SWAP(n) (((n)<<24)|(((n)&0xff00)<<8)|(((n)>>8)&0xff00)|((n)>>24))
56Hyoda::Hyoda(
const ServiceBuildInfo& sbi): AbstractService(sbi),
57 m_break_at_startup(false),
59 m_init_configured(false),
63 m_qhyoda_adrs(0x100007Ful),
67 m_qhyoda_pyld(8*1024),
69 m_qhyoda_width_height(0x04000300ul),
75 m_variables_names(NULL),
76 m_application(sbi.application()),
77 m_papi(new HyodaPapi(this, sbi.application(),traceMng())),
78 m_matrix_render(false){
79 debug()<<
"Hooking Hyoda";
80 if ((m_data=(hyoda_shared_data*)malloc(
sizeof(hyoda_shared_data)))==NULL)
82 m_data->global_iteration=0;
83 m_data->global_time=0.;
84 m_data->global_deltat=0.;
85 m_data->global_cpu_time=0.;
86 m_data->global_mesh_nb_cells=0;
87 m_data->target_cell_uid=m_target_cell_uid;
88 m_data->target_cell_rank=0;
89 m_data->target_cell_nb_nodes=0;
90 for(
int i=0;i<HYODA_CELL_NB_NODES_MAX;++i)
91 m_data->coords[i][0]=m_data->coords[i][1]=m_data->coords[i][2]=0.;
94 if (!platform::getEnvironmentVariable(
"ARCANE_HYODA").null()) m_break_at_startup=
true;
95 if (!platform::getEnvironmentVariable(
"ARCANE_HYODA_MATRIX_RENDER").null()) m_matrix_render=
true;
97 if (m_break_at_startup) debug()<<
"\33[7m[Hyoda] m_break_at_startup == Single shot!\33[m";
101 if (!(hyoda_host=platform::getEnvironmentVariable(
"ARCANE_HYODA_HOST")).null()){
102 debug()<<
"\33[7m[Hyoda] hyoda_host="<<hyoda_host<<
"\33[m";
107 if (!(hyoda_adrs=platform::getEnvironmentVariable(
"ARCANE_HYODA_ADRS")).null()){
109 if (!builtInGetValue(adrs,hyoda_adrs)){
112 m_qhyoda_adrs=SWAP(adrs);
113 debug()<<
"\33[7m[Hyoda] hyoda_adrs="<<m_qhyoda_adrs<<
"\33[m";
119 if (!(hyoda_port=platform::getEnvironmentVariable(
"ARCANE_HYODA_PORT")).null()){
121 if (!builtInGetValue(port,hyoda_port)){
123 debug()<<
"\33[7m[Hyoda] hyoda_port="<<m_qhyoda_port<<
"\33[m";
134 debug()<<
"\33[7m[Hyoda::~ Hyoda]\33[m";
147LocalIdType Hyoda::targetCellIdToLocalId(ISubDomain *sd, UniqueIdType target_cell_uid){
148 UniqueArray<UniqueIdType> uid(1);
151 uid[0]=target_cell_uid;
152 debug()<<
"[Hyoda::targetCellIdToLocalId] uid="<<target_cell_uid;
153 sd->defaultMesh()->itemFamily(IK_Cell)->itemsUniqueIdToLocalId(lid.view(),uid.constView(),
false);
154 debug()<<
"[Hyoda::targetCellIdToLocalId] lid="<<lid[0];
156 if (lid[0]!=NULL_ITEM_ID){
157 if (!sd->defaultMesh()->cellFamily()->itemsInternal()[lid[0]]->isOwn())
171void Hyoda::broadcast_configuration(ISubDomain *sd, UniqueIdType target_cell_uid){
172 debug()<<
"[Hyoda::broadcast_configuration] target_cell_uid="<<target_cell_uid;
175 if (!sd->parallelMng()->isParallel()){
177 m_data->global_mesh_nb_cells=sd->defaultMesh()->ownCells().size();
179 m_data->target_cell_nb_nodes=sd->defaultMesh()->cellFamily()->itemsInternal()[target_cell_uid]->nbNode();
185 LocalIdType target_cell_lid=targetCellIdToLocalId(sd, target_cell_uid);
186 UniqueArray<Integer> gather(4*sd->parallelMng()->commSize());
187 UniqueArray<Integer> all;
189 if (m_break_at_startup==
false)
190 all.add(m_qhyoda_hooked>0.?3883:0);
192 all.add(sd->parallelMng()->commRank()==0?3883:0);
193 all.add(target_cell_lid);
194 all.add(target_cell_lid!=NULL_ITEM_ID
195 ?sd->defaultMesh()->cellFamily()->itemsInternal()[target_cell_lid]->nbNode():0);
196 all.add(sd->defaultMesh()->ownCells().size());
198 debug()<<
"[Hyoda::broadcast_where_gdbserver_is_hooked] Gathering, all="<<all<<
"...";
199 sd->parallelMng()->allGather(all,gather);
202 m_data->target_cell_rank=-1;
203 m_data->target_cell_nb_nodes=-1;
204 m_data->global_mesh_nb_cells=0;
205 for(
int iRnk=4*sd->parallelMng()->commSize();iRnk>0;iRnk-=4){
206 if (gather[iRnk-4]==3883){
207 if (m_gdbserver_rank!=-1)
208 throw FatalErrorException(
"[Hyoda::broadcast_where_gdbserver_is_hooked] more than one m_gdbserver_rank");
209 m_gdbserver_rank=(iRnk/4)-1;
210 debug()<<
"[Hyoda::broadcast_where_gdbserver_is_hooked] m_gdbserver_rank="<<m_gdbserver_rank;
212 if (gather[iRnk-3]!=NULL_ITEM_ID){
213 if (m_data->target_cell_rank!=-1)
214 throw FatalErrorException(
"[Hyoda::broadcast_where_gdbserver_is_hooked] more than one m_data->target_cell_rank");
215 m_data->target_cell_rank=(iRnk/4)-1;
216 debug() <<
"\33[7m[Hyoda::broadcast_where_gdbserver_is_hooked] m_data->target_cell_rank="
217 << m_data->target_cell_rank
220 if (gather[iRnk-2]!=0){
221 if (m_data->target_cell_nb_nodes!=-1)
222 throw FatalErrorException(
"[Hyoda::broadcast_where_gdbserver_is_hooked] more than one m_data->target_cell_nb_nodes");
223 m_data->target_cell_nb_nodes=gather[iRnk-2];
224 debug()<<
"[Hyoda::broadcast_where_gdbserver_is_hooked] m_data->target_cell_nb_nodes="<<m_data->target_cell_nb_nodes;
226 if (gather[iRnk-1]!=0) m_data->global_mesh_nb_cells+=gather[iRnk-1];
228 if (m_data->target_cell_rank>=sd->parallelMng()->commSize())
229 throw FatalErrorException(
"[Hyoda::broadcast_where_gdbserver_is_hooked] ERROR with m_data->target_cell_rank (>commSize)");
242loopbreak(ISubDomain* sd)
247 if (m_target_cell_uid!=m_data->target_cell_uid)
248 return HYODA_HOOK_CONFIGURE;
250 if (m_break_at_startup)
251 return HYODA_HOOK_BREAK;
253 if (m_qhyoda_hooked>0.)
254 return HYODA_HOOK_BREAK;
261Real Hyoda::softbreak(ISubDomain* sd,
const char *fileName,
const char *prettyFunction,
int lineNumber){
263 if (m_qhyoda_hooked==0.)
return 0.;
264 debug() <<
"[Hyoda::softbreak] Was @ " << ((fileName)?fileName:
"(NoFileNameInfo)")<<
":" << lineNumber;
265 debug() <<
"[Hyoda::softbreak] Was @ " << ((prettyFunction)?prettyFunction:
"(NoFunctionInfo)");
275void Hyoda::hook(ISubDomain* sd,
Real tasks){
283 if (m_target_cell_uid!=m_data->target_cell_uid) tasks=HYODA_HOOK_CONFIGURE;
286 if (tasks==HYODA_HOOK_CONFIGURE && sd->parallelMng()->isParallel()){
287 debug()<<
"[Hyoda::hook] New requested cell #"<<m_target_cell_uid;
288 UniqueArray<UniqueIdType> send_buf(1,m_target_cell_uid);
289 sd->parallelMng()->broadcast(send_buf.view(),m_gdbserver_rank);
290 debug() <<
"[Hyoda::hook] broadcasted cell " << send_buf.at(0)
291 <<
", m_data->global_mesh_nb_cells=" << m_data->global_mesh_nb_cells;
292 if (send_buf.at(0)>m_data->global_mesh_nb_cells)
293 throw FatalErrorException(
"[Hyoda::hook] ERROR with broadcasted cell");
295 m_data->target_cell_uid=m_target_cell_uid=send_buf.at(0);
301 if (tasks==HYODA_HOOK_CONFIGURE && (!sd->parallelMng()->isParallel())){
302 debug()<<
"[Hyoda::hook (seq)] New cell sent from server "<<m_target_cell_uid;
303 if (m_target_cell_uid>m_data->global_mesh_nb_cells)
304 throw FatalErrorException(
"[Hyoda::hook] ERROR with broadcasted cell");
306 m_data->target_cell_uid=m_target_cell_uid;
312 if (!m_configured) broadcast_configuration(sd, m_target_cell_uid);
315 if (!m_init_configured){
316 m_init_configured=
true;
317 UniqueArray<Integer> wxh_to_broadcast(0);
318 wxh_to_broadcast.add(m_qhyoda_width_height);
319 debug()<<
"[Hyoda::hook] broadcasting wxh...";
320 sd->parallelMng()->broadcast(wxh_to_broadcast.view(), m_gdbserver_rank);
321 unsigned int width = (wxh_to_broadcast[0]>>16)&0xFFFFul;
322 unsigned int height = (wxh_to_broadcast[0])&0xFFFFul;
323 debug() <<
"[Hyoda::hook] Let's configure: m_qhyoda_width_height="
324 << wxh_to_broadcast[0] <<
", " << width <<
"x" << height;
325 debug()<<
"\33[7m[Hyoda::hook] Initializing HyodaTcp\33[m";
327 m_tcp =
new HyodaTcp(
this, sd, traceMng(),
328 m_qhyoda_adrs, m_qhyoda_port,
329 m_qhyoda_pyld, m_break_at_startup);
330 debug()<<
"\33[7m[Hyoda::hook] Initializing MESH HyodaIceT\33[m";
331 m_ice_mesh=
new HyodaIceT(
this, sd, traceMng(), width, height, m_tcp);
332 debug()<<
"\33[7m[Hyoda::hook] Initializing MATRIX HyodaIceT\33[m";
333 m_ice_matrix=
new HyodaMatrix(
this, sd, traceMng(), width, height, m_tcp);
334 m_papi->initialize(sd,m_tcp);
337 m_ice_mesh->render();
338 if (m_matrix_render) m_ice_matrix->render();
340 debug()<<
"[Hyoda::hook] now fetch_and_fill_data_to_be_dumped";
341 fetch_and_fill_data_to_be_dumped(sd,m_target_cell_uid);
343 debug()<<
"[Hyoda::hook] dump";
345 debug()<<
"[Hyoda::hook] done";
353void Hyoda::ijval(
int cpu,
int n,
int *i,
int *j,
double *val){
354 debug()<<
"\33[7m[HyodaArc::ijval] cpu="<<cpu<<
", n="<<n<<
"\33[m";
355 m_ice_matrix->setIJVal(cpu,n,i,j,val);
Fichier de configuration d'Arcane.
#define ARCANE_REGISTER_APPLICATION_FACTORY(aclass, ainterface, aname)
Enregistre un service de fabrique pour la classe aclass.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Exception lorsqu'une erreur fatale est survenue.
UniqueArray< Int32 > Int32UniqueArray
Tableau dynamique à une dimension d'entiers 32 bits.
Int32 LocalIdType
Type des entiers utilisés pour stocker les identifiants locaux des entités.
Int32 Integer
Type représentant un entier.
std::uint32_t UInt32
Type entier non signé sur 32 bits.