MED fichier
filterBlockOfentities.c
Aller à la documentation de ce fichier.
1 /* This file is part of MED.
2  *
3  * COPYRIGHT (C) 1999 - 2025 EDF R&D, CEA/DEN
4  * MED is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * MED is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with MED. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /* #define MED_PERF_MEASUREMENT */
19 
20 #ifndef MED_ACTIVATE_COMPARISON
21 #define MED_ACTIVATE_COMPARISON 1
22 #else
23 #define MED_ACTIVATE_COMPARISON 0
24 #endif
25 
26 #if MED_ACTIVATE_COMPARISON == 1
27 #ifdef MED_PERF_MEASUREMENT
28 #error "Defining comparaison mode for performance measurement will be under performing !"
29 #endif
30 #endif
31 
32 #ifdef DEF_LECT_ECR
33 #define MODE_ACCES MED_ACC_RDWR
34 #elif DEF_LECT_AJOUT
35 #define MODE_ACCES MED_ACC_RDEXT
36 #else
37 #define MODE_ACCES MED_ACC_CREAT
38 #warning "Not file open mode has been set, using MED_ACC_CREAT mode."
39 #endif
40 
41 #ifndef FILE_INTERLACING_MODE
42 #define FILE_INTERLACING_MODE MED_UNDEF_INTERLACE
43 /* #warning "Defining file interlacing mode as memory interlacing mode..." */
44 #else
45 #warning "Defining a specific file interlacing mode.."
46 #if MED_ACTIVATE_COMPARISON == 0
47 #error "Defining a spectific file interlacing mode will be under performing !"
48 #endif
49 #endif
50 
51 #define MAX(a,b) ((a) > (b) ? (a) : (b))
52 
53 #define MESGERR 1
54 
55 #include <med.h>
56 #include "med_utils.h"
57 #include "med_config.h"
58 
59 #include <stdlib.h>
60 #include <string.h>
61 #include <assert.h>
62 
63 #ifdef PPRO_NT_CALL
64 // Windows Header Files:
65 # include <windows.h>
66 # include <Lmcons.h>
67 # include <sys/timeb.h>
68 # include <time.h>
69 #else
70 
71 # if HAVE_SYS_TIME_H
72 # include <sys/time.h>
73 # endif
74 
75 #include <time.h>
76 
77 #ifndef HAVE_UNISTD_H
78 #error "unistd.h required."
79 #endif
80 #include <unistd.h>
81 #endif
82 
84 #include "generateDatas.h"
85 #include "generateFilterArray.h"
86 
87 
88 /* Transmit mpi and persistent information */
89 /* from main to successive calls to generateFieldFile */
90 typedef struct {
91  MPI_Info info;
92  MPI_Comm comm;
93  int mpi_size;
94  int mpi_rank;
98 } COM_info;
99 
100 /* DEFAULT VALUES FOR OPTIONS */
107 static int parse_args(int argc, char **argv);
108 
109 
110 static char *_MED_MODE_SWITCH_MSG[3]={"MED_FULL_INTERLACE", "MED_NO_INTERLACE", "MED_UNDEF_INTERLACE", };
111 static char *_MED_STORAGE_MODE_MSG[3]={"MED_NO_STMODE", "MED_GLOBAL_STMODE", "MED_COMPACT_STMODE"};
112 
113 med_err generateFieldFile( const med_size nentities, const med_size nvaluesperentity, const med_size nconstituentpervalue,
114  const med_switch_mode constituentmode,GetBlocksOfEntitiesType getBlockOfEntities, const med_int nbblocksperproc,
115  GenerateDataType generateDatas,
116  const med_storage_mode storagemode, const med_size profilearraysize, const char * const fieldnameprefix, COM_info * const cominfo ) {
117 
118 
119 /* static int _fileno=0; */
120  med_err _ret=-1;
121  char _filename [255]="";
122 
123  /* The used Mesh is fixed */
124  char _meshname[MED_NAME_SIZE+1]="Empty mesh";
125  med_int _meshdim=3;
126  char _meshcomponentname[3*MED_SNAME_SIZE+1] = "x y z ";
127  char _meshcomponentunit[3*MED_SNAME_SIZE+1] = "cm cm cm ";
128 
129  char _fieldname [MED_NAME_SIZE+1] = "";
130  char *componentname, *componentunit;
131  char _profilename[MED_NAME_SIZE+1] = MED_NO_PROFILE;
132  med_int *_profilearray=0;
133  med_int _i=0, _j=0, _k=0;
134  med_int _firstdim=0, _lastdim=0;
135 
136  int _lastusedrank=0;
137  med_size _blocksize=0, _lastblocksize=0, _count=0, _stride=0, _start=0;
138  med_float *_arrayvalues;
139  med_filter filter = MED_FILTER_INIT;
140  med_size _nusedentities = nentities;
141  med_size _io_count = nbblocksperproc;
142  med_idt _fidseq, _fid;
143  med_switch_mode _fileinterlacingmode = MED_UNDEF_INTERLACE;
144  MPI_Info info = cominfo->info;
145  MPI_Comm comm = cominfo->comm;
146  int mpi_size = cominfo->mpi_size;
147  int mpi_rank = cominfo->mpi_rank;
148 
149  med_geometry_type _geotype = MED_TRIA6;
150  med_int _geodim = _geotype/100;
151  med_int _geonnodes = _geotype%100;
152  char _ipointname[MED_NAME_SIZE+1];
153  med_float* _ipointrefcoo = 0;
154  med_int _ipoint = nvaluesperentity;
155  med_float* _ipointcoo = 0;
156  med_float* _ipointwg = 0;
157 
158 #ifdef MED_PERF_MEASUREMENT
159  double read_bw, write_bw;
160  double stim, etim;
161  double write_tim = 0;
162  double read_tim = 0;
163  double max_read_tim, max_write_tim;
164  double min_read_tim, min_write_tim;
165  double ave_read_tim, ave_write_tim;
166 #endif
167 
168  sprintf(_filename,"%s_CPU-%03d_@_%s_%s.med",fieldnameprefix,mpi_size,_MED_MODE_SWITCH_MSG[constituentmode],_MED_STORAGE_MODE_MSG[storagemode]);
169  /* SSCRUTE(_filename); */
170 
171  /* Ouverture du fichier en mode parallel */
172  if ((_fid = MEDparFileOpen(_filename, MODE_ACCES ,comm, info)) < 0){
173  MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_FILE,_filename);
174  goto ERROR;
175  }
176 
177  if (MEDmeshCr( _fid,_meshname,_meshdim,_meshdim, MED_UNSTRUCTURED_MESH,
178  "Un maillage pour le test parallel","s", MED_SORT_DTIT,
179  MED_CARTESIAN, _meshcomponentname, _meshcomponentunit) < 0) {
180  MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_MESH,_meshname);
181  goto ERROR;
182  };
183 
184  componentname = (char*) malloc((nconstituentpervalue*MED_SNAME_SIZE+1)*sizeof(char));
185  componentunit = (char*) malloc((nconstituentpervalue*MED_SNAME_SIZE+1)*sizeof(char));
186  /*TODO : Compléter le nom */
187  strcpy(componentname,"");
188  strcpy(componentunit,"");
189  strcpy(_fieldname,fieldnameprefix);
190  if ( MEDfieldCr(_fid,_fieldname,MED_FLOAT64,nconstituentpervalue,componentname,componentunit,"s",_meshname ) < 0) {
191  MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FIELD,_fieldname);
192  goto ERROR;
193  };
194  free(componentname);
195  free(componentunit);
196 
197 
198  /* LOCALIZATION OF INTEGRATION POINTS */
199  if ( _ipoint > 1 ) {
200 
201  MESSAGE("Creating a localization of integration points...");
202  strcpy(_ipointname,_fieldname);
203  strcat(_ipointname,"_loc");
204 
205  /*Attention ancienne spec*/
206  _ipointrefcoo = (med_float *) calloc(_geodim*_geonnodes,sizeof(med_float));
207  _ipointcoo = (med_float *) calloc(_ipoint*_geodim,sizeof(med_float));
208  _ipointwg = (med_float *) calloc(_ipoint,sizeof(med_float));
209 
210  if (MEDlocalizationWr(_fid, _ipointname, _geotype, _geotype/100, _ipointrefcoo, constituentmode,
211  _ipoint, _ipointcoo, _ipointwg, MED_NO_INTERPOLATION, MED_NO_MESH_SUPPORT ) < 0) {
212  MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_LOCALIZATION,_ipointname);
213  ISCRUTE_int(constituentmode);
214  goto ERROR;
215  }
216  free(_ipointrefcoo );
217  free(_ipointcoo );
218  free(_ipointwg );
219 
220  } else {
221  strcpy(_ipointname,MED_NO_LOCALIZATION);
222  }
223 
224  /* CREATING A PROFILE */
225  /* ISCRUTE(profilearraysize); */
226  if (profilearraysize) {
227  MESSAGE("Creating a profile...");
228 
229  strcpy(_profilename,_fieldname);strcat(_profilename,"_profile");
230 
231  _profilearray = (med_int*) calloc(profilearraysize,sizeof(med_int));
232 
233  /* TODO : générer un profil à trous, cf: création du filtre*/
234  for (_i=0; _i < profilearraysize; ++_i) _profilearray[_i]=_i+1;
235 
236  if ( MEDprofileWr(_fid,_profilename,profilearraysize,_profilearray) < 0) {
237  MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_PROFILE,_profilename);
238  goto ERROR;
239  };
240  _nusedentities = profilearraysize;
241  } else {
242  MESSAGE("No use of profile...");
243  strcpy(_profilename,MED_NO_PROFILE);
244  }
245 
246 
247  MESSAGE("Generating partition...");
248  getBlockOfEntities ( mpi_rank , mpi_size, _nusedentities,
249  &_start, &_stride, &_io_count, &_blocksize,
250  &_lastusedrank, &_lastblocksize);
251 
252  _count=_io_count;
253  MESSAGE("Generating filter...");
254 
255  /* Choisi une composante ou toutes les composantes */
257  if ( cominfo->constituentselect == MED_UNDEF_CONSTITUENT) {
258  cominfo->constituentselect = 1 + (int) (nconstituentpervalue * (random() / (RAND_MAX + 1.0)));
259  if (cominfo->constituentselect > nconstituentpervalue ) cominfo->constituentselect = MED_ALL_CONSTITUENT;
260  }
261  } else
263 
264  /* MEDfilterSetFileInterlacing peut-etre appelée avant MEDfilter...Cr */
265  /* (solution potentiellement moins couteuse) */
266  /* if ( FILE_INTERLACING_MODE == MED_UNDEF_INTERLACE ) { */
267  /* _fileinterlacingmode = constituentmode; */
268  /* } else */
269  /* _fileinterlacingmode = FILE_INTERLACING_MODE; */
270  /* MEDfilterSetFileInterlacing(_fid,&filter,_fileinterlacingmode); */
271 
272  if ( MEDfilterBlockOfEntityCr(_fid, nentities, nvaluesperentity, nconstituentpervalue,
273  /* MED_ALL_CONSTITUENT, constituentmode, storagemode, _profilename, */
274  cominfo->constituentselect, constituentmode, storagemode, _profilename,
275  _start,_stride,_count,_blocksize,_lastblocksize, &filter) < 0 ) {
277  goto ERROR;
278  }
279 
280  /* MEDfilterSetFileInterlacing peut-etre appelée après MEDfilter...Cr */
281  /* (solution plus couteuse mais teste plus ) */
283  _fileinterlacingmode = constituentmode;
284  } else
285  _fileinterlacingmode = FILE_INTERLACING_MODE;
286  MEDfilterSetFileInterlacing(_fid,&filter,_fileinterlacingmode);
287 
288  MESSAGE("Generating datas...");
289  /* ISCRUTE(profilearraysize); */
290  generateDatas(mpi_rank, _lastusedrank, sizeof(med_float),
291  storagemode, profilearraysize, _profilearray,
292  _start, _stride, _count, _blocksize, _lastblocksize,
293  nentities, nvaluesperentity, nconstituentpervalue,
294  &_arrayvalues );
295 
296  MESSAGE("Writing field...");
297 #ifdef MED_PERF_MEASUREMENT
298  MPI_Barrier(MPI_COMM_WORLD);
299  stim = MPI_Wtime();
300 #endif
301 
302  if ( MEDfieldValueAdvancedWr(_fid,_fieldname,MED_NO_DT,MED_NO_IT,0.0, MED_CELL, _geotype,
303  _ipointname, &filter, (unsigned char*)_arrayvalues ) < 0) {
304  MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_FIELD,_fieldname);
305  ISCRUTE(mpi_rank);
306  goto ERROR;
307  }
308 #ifdef MED_PERF_MEASUREMENT
309 
310  etim = MPI_Wtime();
311  write_tim = (etim - stim);
312  MPI_Allreduce(&write_tim, &max_write_tim, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
313  MPI_Allreduce(&write_tim, &min_write_tim, 1, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD);
314  MPI_Allreduce(&write_tim, &ave_write_tim, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
315  ave_write_tim = ave_write_tim / mpi_size; /*TODO : / par le nbre de proc vraiment utilisés .*/
316 
317  if ( (mpi_rank == 0) ) {
318 
319  FILE * _perffile;
320  char _perffilename[255]="";
321  int64_t _write_size = _nusedentities*nvaluesperentity*nconstituentpervalue*sizeof(med_float);
322  write_bw = (double)((int64_t)(_write_size)) / (max_write_tim * 1000000.0);
323 
324  sprintf(_perffilename,"%s_CPU-%03d_@_%s_%s.perf",fieldnameprefix,mpi_size,_MED_MODE_SWITCH_MSG[constituentmode],
325  _MED_STORAGE_MODE_MSG[storagemode]);
326  _perffile=fopen(_perffilename, "w");
327 
328  fprintf(_perffile, "# total_size = %ld\n", (long)(_write_size));
329  fprintf(_perffile, "# Write: min_time = %f, max_time = %f, mean_time = %f\n", min_write_tim, max_write_tim,
330  ave_write_tim);
331  fprintf(_perffile, "Write bandwidth = %f Mbytes/sec\n", write_bw);
332 
333  fclose(_perffile);
334 
335  }
336 #endif
337 
338  /* Test de lecture du même fichier avec filtre simple par un seul processeur */
339  /* TODO : Créer MEDflush */
340  H5Fflush(_fid, H5F_SCOPE_GLOBAL );
341 
342  /*Le flush suffit pas besoin de synchroniser les processus : MPI_Barrier(MPI_COMM_WORLD); */
343  if (mpi_rank == 0 && MED_ACTIVATE_COMPARISON ) {
344  MESSAGE("Reading field...");
345 
346 
347  med_int _nentitiesarrayvalues=0;
348  med_float *_filteredarrayvalues=NULL;
349  med_filter filter2=MED_FILTER_INIT;
350  int _ind=0;
351  FILE * _asciifile;
352  char _asciifilename[255]="";
353 
354 
355  if ((_fidseq = MEDfileOpen(_filename, MED_ACC_RDONLY )) < 0){
356  MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_FILE,_filename);
357  goto ERROR;
358  }
359 
360  sprintf(_asciifilename,"%s_CPU-%03d_@_%s_%s.ascii",fieldnameprefix,mpi_size,_MED_MODE_SWITCH_MSG[constituentmode],_MED_STORAGE_MODE_MSG[storagemode]);
361  _asciifile=fopen(_asciifilename, "w");
362 
363  /* ISCRUTE(profilearraysize); */
364  /*Génère un filtre de selection simple s'il n'a pas déjà été généré lors d'un précédent appel */
365  /*TODO : Déplacer cette appel dans le main après avoir externaliser la génération du profile */
366  if (!(cominfo->filterarray))
367  if ( generateFilterArray( nentities, nvaluesperentity, nconstituentpervalue,
368  profilearraysize, _profilearray,
369  &(cominfo->nentitiesfiltered), &(cominfo->filterarray) ) < 0 ) {
370  goto ERROR;
371  }
372 
373  ISCRUTE(cominfo->nentitiesfiltered);
374  /*Stocke le filtre utilisé dans le fichier .ascii*/
375  for (_i=0; _i < cominfo->nentitiesfiltered; ++_i ) {
376 /* ISCRUTE(cominfo->filterarray[_i]); */
377  fprintf(_asciifile,"%d ",cominfo->filterarray[_i]) ;
378  }
379  fprintf(_asciifile,"\n") ;
380 
381 
382  /*Pas de profile possible (profilearraysize == 0) en MED_GLOBAL_STMODE sur un fichier géré en parallel */
383  if ( profilearraysize ) {
384  _nentitiesarrayvalues = profilearraysize;
385  } else {
386  _nentitiesarrayvalues = nentities;
387  }
388 
389  /*Attention allocation mémoire potentiellement grosse car réalisée uniquement par le processus 0
390  qui rassemble les données.*/
391  /* C'est une taille maxi qui ne prend pas en compte le COMPACT+filter */
392  /* TODO : Ajuster la taille au storage_mode*/
393  _filteredarrayvalues = (med_float*) malloc(_nentitiesarrayvalues*
394  nvaluesperentity*
395  nconstituentpervalue*sizeof(med_float));
396 
397  /* Permet de vérifier une erreur d'indiçage après la lecture */
398  for (_i=0;_i<_nentitiesarrayvalues*nvaluesperentity*nconstituentpervalue; ++_i)
399  _filteredarrayvalues[_i]=-_i;
400 
401  if ( cominfo->constituentselect != MED_ALL_CONSTITUENT) {
402  _firstdim = cominfo->constituentselect-1;
403  _lastdim = cominfo->constituentselect;
404  } else {
405  _firstdim = 0;
406  _lastdim = nconstituentpervalue;
407  }
408 
409  ISCRUTE(cominfo->constituentselect);
410  fprintf(_asciifile,"%s : %d \n","Number of constituents selected", cominfo->constituentselect);
411 
412  /*Création d'un filtre de sélection simple, pour une lecture séquentielle par le processys 0*/
413  if ( MEDfilterEntityCr(_fidseq, nentities, nvaluesperentity, nconstituentpervalue,
414  /* MED_ALL_CONSTITUENT, constituentmode, storagemode, _profilename, */
415  cominfo->constituentselect, constituentmode, storagemode, _profilename,
416  cominfo->nentitiesfiltered,cominfo->filterarray, &filter2) < 0 ) {
418  goto ERROR;
419  }
420 
421  if ( MEDfieldValueAdvancedRd(_fidseq,_fieldname,MED_NO_DT,MED_NO_IT, MED_CELL, _geotype,
422  &filter2, (unsigned char*)_filteredarrayvalues ) < 0) {
423  MED_ERR_(_ret,MED_ERR_READ,MED_ERR_FIELD,_fieldname);
424  ISCRUTE(mpi_rank);
425  goto ERROR;
426  }
427 
428  /*AFFICHAGE TOUJOURS EN FULL INTERLACE QUELQUES SOIENT LES COMBINAISONS*/
429  /*TODO : Externaliser l'affichage*/
430  if ( storagemode == MED_GLOBAL_STMODE ) {
431  switch (constituentmode) {
432  case MED_FULL_INTERLACE:
433  for (_i=0; _i < cominfo->nentitiesfiltered; ++_i)
434  for (_j=0; _j < nvaluesperentity; ++_j)
435  /* for (_k=0; _k < nconstituentpervalue; ++_k) { */
436  for (_k=_firstdim; _k < _lastdim; ++_k) {
437  _ind = (cominfo->filterarray[_i]-1)*nvaluesperentity*nconstituentpervalue+ _j*nconstituentpervalue+_k;
438 /* fprintf(stdout,"%s%3d%s = %f\n","_filteredarrayvaluesFULLGLB[",_ind,"]",_filteredarrayvalues[_ind]) ; */
439  fprintf(_asciifile,"%f\n",_filteredarrayvalues[_ind]) ;
440  }
441  break;
442  case MED_NO_INTERLACE:
443  for (_j=0; _j < cominfo->nentitiesfiltered; ++_j)
444  for (_k=0; _k < nvaluesperentity; ++_k)
445  /* for (_i=0; _i < nconstituentpervalue; ++_i) { */
446  for (_i=_firstdim; _i < _lastdim; ++_i) {
447  _ind =_i*nentities*nvaluesperentity+ (cominfo->filterarray[_j]-1)*nvaluesperentity +_k;
448 /* fprintf(stdout,"%s%3d%s = %f\n","_filteredarrayvaluesNOGLB[",_ind,"]",_filteredarrayvalues[_ind]); */
449  fprintf(_asciifile,"%f\n",_filteredarrayvalues[_ind]);
450  }
451  break;
452  }
453  } else
454  switch (constituentmode) {
455  case MED_FULL_INTERLACE:
456  for (_i=0; _i < cominfo->nentitiesfiltered; ++_i )
457  for (_j=0; _j < nvaluesperentity; ++_j)
458  /* for (_k=0; _k < nconstituentpervalue; ++_k) { */
459  for (_k=_firstdim; _k < _lastdim; ++_k) {
460  _ind = _i*nvaluesperentity*nconstituentpervalue+_j*nconstituentpervalue+_k;
461 /* fprintf(stdout,"%s%3d%s = %f\n","_filteredarrayvaluesFULLCP[",_ind,"]",_filteredarrayvalues[_ind]) ; */
462  fprintf(_asciifile,"%f\n",_filteredarrayvalues[_ind]) ;
463  }
464  break;
465  case MED_NO_INTERLACE:
466  for (_j=0; _j < cominfo->nentitiesfiltered; ++_j)
467  for (_k=0; _k < nvaluesperentity; ++_k)
468  /* for (_i=0; _i < nconstituentpervalue; ++_i) { */
469  for (_i=_firstdim; _i < _lastdim; ++_i) {
470  _ind =_i*cominfo->nentitiesfiltered*nvaluesperentity+ _j*nvaluesperentity +_k;
471  /* _ind =_i*_nentitiesarrayvalues*nvaluesperentity+ (_filterarray[_j]-1)*nvaluesperentity +_k; */
472 /* fprintf(stdout,"%s%3d%s = %f\n","_filteredarrayvaluesNOCP[",_ind,"]",_filteredarrayvalues[_ind]); */
473  fprintf(_asciifile,"%f\n",_filteredarrayvalues[_ind]);
474  }
475  break;
476  }
477 
478 
479  free(_filteredarrayvalues);
480 
481  fclose(_asciifile);
482 
483  if ( MEDfilterClose(&filter2) < 0 ) {
485  goto ERROR;
486  }
487 
488  } /*fin if (mpi_rank == 0) */
489 
490  if ( MEDfilterClose(&filter) < 0 ) {
492  goto ERROR;
493  }
494 
495 
496  _ret=0;
497  ERROR:
498  if (_arrayvalues) free(_arrayvalues);
499  if (profilearraysize) free(_profilearray);
500 
501  if ( MEDfileClose(_fid) < 0) {
502  MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILE,""); _ret = -1;
503  }
504 
505  if (mpi_rank == 0 && MED_ACTIVATE_COMPARISON) {
506  if ( MEDfileClose(_fidseq) < 0) {
507  MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILE,""); _ret = -1;
508  }
509  }
510 
511  return _ret;
512 }
513 
514 
515 
516 int main (int argc, char **argv)
517 
518 
519 {
520  med_err _ret = 0;
521 
522  COM_info _cominfo;
523  _cominfo.comm = MPI_COMM_WORLD;
524  _cominfo.info = MPI_INFO_NULL;
525  _cominfo.nentitiesfiltered = 0;
526  _cominfo.filterarray = NULL;
528 
529  MPI_Init(&argc, &argv);
530  MPI_Comm_size(MPI_COMM_WORLD, &(_cominfo.mpi_size));
531  MPI_Comm_rank(MPI_COMM_WORLD, &(_cominfo.mpi_rank));
532 
533  parse_args(argc,argv);
534 
535  med_size _nbblocksperproc = __nbblocksperproc ;
536  med_size _nentities = __nentities ;
537  med_size _nvaluesperentity = __nvaluesperentity ;
538  med_size _nconstituentpervalue = __nconstituentpervalue;
539  /* Pour que les 4 fichiers générés soient identiques,
540  on désactive l'utilisation des profils
541  qui ne sont pas utilisables en mode GLOBAL et // */
542  med_size _profilearraysize=_nentities/2;
543  if ( __profilearraysize >= 0 )
544  _profilearraysize = __profilearraysize;
545  med_size _pflsize = _profilearraysize;
546  ISCRUTE_long(_profilearraysize);
547  med_size _constituentselect = MED_ALL_CONSTITUENT;
548  if ( (0 <= __constituentselect) && ( __constituentselect <= _nconstituentpervalue) )
549  _constituentselect = __constituentselect;
550  _cominfo.constituentselect = _constituentselect;
551  ISCRUTE_long(_constituentselect);
552 
553  if (_cominfo.mpi_rank == 0 ) {
554  struct tm *_tm ;
555  time_t _tt=time(0);
556  _tm = localtime(&_tt);
557 
558  srandom((*_tm).tm_sec * (*_tm).tm_min );
559  if (!_nbblocksperproc ) _nbblocksperproc = 1 + (int) (_cominfo.mpi_size * (random() / (RAND_MAX + 1.0)));
560  if (!_nentities ) _nentities = 1 + (int) (1000.0 * (random() / (RAND_MAX + 1.0)));
561  if (!_nvaluesperentity ) _nvaluesperentity = 1 + (int) (11.0 * (random() / (RAND_MAX + 1.0)));
562  if (!_nconstituentpervalue) _nconstituentpervalue = 1 + (int) (7.0 * (random() / (RAND_MAX + 1.0)));
563  }
564 
565  if ( (sizeof(med_size)%(sizeof(MPI_LONG)))==0 ) {
566  MPI_Bcast(&_nbblocksperproc , sizeof(med_size)/sizeof(MPI_LONG), MPI_LONG, 0, MPI_COMM_WORLD);
567  MPI_Bcast(&_nentities , sizeof(med_size)/sizeof(MPI_LONG), MPI_LONG, 0, MPI_COMM_WORLD);
568  MPI_Bcast(&_nvaluesperentity , sizeof(med_size)/sizeof(MPI_LONG), MPI_LONG, 0, MPI_COMM_WORLD);
569  MPI_Bcast(&_nconstituentpervalue , sizeof(med_size)/sizeof(MPI_LONG), MPI_LONG, 0, MPI_COMM_WORLD);
570  } else {
571  assert(sizeof(med_size) == (sizeof(MPI_LONG)));
572  }
573 
574  char _fieldnameprefix[256] = "";
575  sprintf(_fieldnameprefix,"NENT-%03llu_NVAL-%03llu_NCST-%03lld_NBL-%03llu",
576  _nentities, _nvaluesperentity, _nconstituentpervalue, _nbblocksperproc);
577 
578  GenerateDataType generateDatas = 0;
579  med_switch_mode _switchmode = MED_UNDEF_INTERLACE;
580  med_storage_mode _storagemode = MED_UNDEF_STMODE;
581 
582  for (_switchmode = MED_FULL_INTERLACE ; _switchmode <= MED_NO_INTERLACE; ++_switchmode) {
583 
584  if ( _switchmode == MED_FULL_INTERLACE )
585  generateDatas = generateFullIDatas;
586  else
587  generateDatas = generateNoIDatas;
588 
589  /* for (_storagemode = MED_GLOBAL_STMODE ; _storagemode <= MED_COMPACT_STMODE; ++_storagemode) { */
590  /* On itére d'abord par le mode COMPACT car la généreration du filtre pour la lecture du processus 0 */
591  /* est réutilisé lors des itérations suivantes. Il ne doit pas être d'une taille supérieure aux
592  nombres d'entités du profil. */
593  for (_storagemode = MED_COMPACT_STMODE ; _storagemode >= MED_GLOBAL_STMODE; --_storagemode) {
594 
595  if ( _storagemode == MED_GLOBAL_STMODE ) _pflsize=0; else _pflsize=_profilearraysize;
596 
597  SSCRUTE(_MED_MODE_SWITCH_MSG[_switchmode]);SSCRUTE(_MED_STORAGE_MODE_MSG[_storagemode]);
598  if ( generateFieldFile( _nentities, _nvaluesperentity, _nconstituentpervalue,
599  _switchmode, getCyclicBlocksOfEntities, _nbblocksperproc, generateDatas,
600  _storagemode, _pflsize, _fieldnameprefix, & _cominfo) < 0 ) {
601  MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_FIELD,_fieldnameprefix);
602  ISCRUTE(_cominfo.mpi_rank);
603  goto ERROR;
604  }
605 
606  }
607  }
608 
609  _ret = 0;
610  ERROR:
611 
612  if ( _cominfo.filterarray != NULL ) free( _cominfo.filterarray );
613 
614  /*pour arch. BLueGene : Sync entre GPFS et LSF : sleep(360) */
615 
616  /* MPI_Finalize must be called AFTER MEDclose which may use MPI calls */
617  MPI_Finalize();
618 
619  /* Catcher l'erreur en retour mpirun et .sh*/
620  return _ret;
621 }
622 
623 
624 
625 
626 static int
627 parse_args(int argc, char **argv)
628 {
629  int c;
630 
631  while ((c = getopt(argc, argv, "n:v:c:b:p:s:")) != EOF) {
632  switch (c) {
633  case 'n':
634  __nentities = atol(optarg);
635  break;
636  case 'v': /* nval per entity */
637  __nvaluesperentity = atol(optarg);
638  break;
639  case 'c': /* nb constituents per value */
640  __nconstituentpervalue = atol(optarg);
641  break;
642  case 'b': /* nb block */
643  __nbblocksperproc = atol(optarg);
644  break;
645  case 'p': /* taille du profile */
646  __profilearraysize = atol(optarg);
647  break;
648  case 's': /* sélection d'une constituent */
649  __constituentselect = atol(optarg);
650  break;
651  case '?': /* unknown */
652  default:
653  break;
654  }
655  }
656 
657  return (0);
658 }
MED_FLOAT64
Definition: med.h:176
COM_info::mpi_rank
int mpi_rank
Definition: filterBlockOfentities.c:94
FILE_INTERLACING_MODE
#define FILE_INTERLACING_MODE
Definition: filterBlockOfentities.c:42
MED_ACC_RDONLY
Definition: med.h:130
MED_TRIA6
#define MED_TRIA6
Definition: med.h:216
parse_args
static int parse_args(int argc, char **argv)
Definition: filterBlockOfentities.c:627
MED_NO_MESH_SUPPORT
#define MED_NO_MESH_SUPPORT
Definition: med.h:284
MED_ERR_
#define MED_ERR_(rt, r1, r2, r3)
Definition: med_utils.h:160
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:89
MED_ERR_CLOSE
#define MED_ERR_CLOSE
Definition: med_err.h:30
MED_ERR_PROFILE
#define MED_ERR_PROFILE
Definition: med_err.h:94
MEDparFileOpen
med_idt MEDparFileOpen(const char *const filename, const med_access_mode accessmode, const MPI_Comm comm, const MPI_Info info)
Ouverture d'un fichier MED pour une utilisation parallèle.
Definition: MEDparFileOpen.c:49
__profilearraysize
med_size __profilearraysize
Definition: filterBlockOfentities.c:105
MED_CARTESIAN
Definition: med.h:269
MEDfilterBlockOfEntityCr
MEDC_EXPORT med_err MEDfilterBlockOfEntityCr(const med_idt fid, const med_int nentity, const med_int nvaluesperentity, const med_int nconstituentpervalue, const med_int constituentselect, const med_switch_mode switchmode, const med_storage_mode storagemode, const char *const profilename, const med_size start, const med_size stride, const med_size count, const med_size blocksize, const med_size lastblocksize, med_filter *const filter)
Crée un filtre en sélectionnant par blocs les entités pour lesquelles on veut lire/écrire des valeurs...
Definition: MEDfilterBlockOfEntityCr.c:52
MED_COMPACT_STMODE
Definition: med.h:120
generateFieldFile
med_err generateFieldFile(const med_size nentities, const med_size nvaluesperentity, const med_size nconstituentpervalue, const med_switch_mode constituentmode, GetBlocksOfEntitiesType getBlockOfEntities, const med_int nbblocksperproc, GenerateDataType generateDatas, const med_storage_mode storagemode, const med_size profilearraysize, const char *const fieldnameprefix, COM_info *const cominfo)
Definition: filterBlockOfentities.c:113
MED_NO_DT
#define MED_NO_DT
Definition: med.h:339
MED_ERR_OPEN
#define MED_ERR_OPEN
Definition: med_err.h:37
MED_SORT_DTIT
Definition: med.h:328
MED_ALL_CONSTITUENT
#define MED_ALL_CONSTITUENT
Definition: med.h:310
__constituentselect
med_size __constituentselect
Definition: filterBlockOfentities.c:106
generateNoIDatas
void generateNoIDatas(const int myrank, const int lastrank, const int sizeoftype, const med_storage_mode storagemode, const med_size profilearraysize, const med_int *const profilearray, const med_size start, const med_size stride, const med_size count, const med_size blocksize, const med_size lastblocksize, const med_int nentities, const int nvaluesperentity, const int nconstituentpervalue, med_float **valuesarray)
Definition: generateDatas.c:103
MED_ERR_CREATE
#define MED_ERR_CREATE
Definition: med_err.h:27
MED_ERR_WRITE
#define MED_ERR_WRITE
Definition: med_err.h:29
generateDatas.h
MED_NO_IT
#define MED_NO_IT
Definition: med.h:340
med_int
int med_int
Definition: med.h:361
med_err
herr_t med_err
Definition: med.h:351
MED_ERR_READ
#define MED_ERR_READ
Definition: med_err.h:28
MEDlocalizationWr
MEDC_EXPORT med_err MEDlocalizationWr(const med_idt fid, const char *const localizationname, const med_geometry_type geotype, const med_int spacedimension, const med_float *const elementcoordinate, const med_switch_mode switchmode, const med_int nipoint, const med_float *const ipointcoordinate, const med_float *const weight, const char *const geointerpname, const char *const ipointstructmeshname)
Cette routine permet l'écriture d'une localisation localizationname de points d'intégration dans/auto...
Definition: MEDlocalizationWr.c:49
MEDfieldCr
MEDC_EXPORT med_err MEDfieldCr(const med_idt fid, const char *const fieldname, const med_field_type fieldtype, const med_int ncomponent, const char *const componentname, const char *const componentunit, const char *const dtunit, const char *const meshname)
Cette fonction crée un champ dans un fichier.
Definition: MEDfieldCr.c:44
COM_info
Definition: filterBlockOfentities.c:90
MEDfieldValueAdvancedRd
MEDC_EXPORT med_err MEDfieldValueAdvancedRd(const med_idt fid, const char *const fieldname, const med_int numdt, const med_int numit, const med_entity_type entitype, const med_geometry_type geotype, const med_filter *const filter, unsigned char *const value)
Cette fonction permet de lire les valeurs d'un champ définies sur des entités d'un maillage pour une ...
Definition: MEDfieldValueAdvancedRd.c:43
med_size
hsize_t med_size
Definition: med.h:348
MED_UNDEF_CONSTITUENT
#define MED_UNDEF_CONSTITUENT
Definition: med.h:317
ISCRUTE_long
#define ISCRUTE_long(entier)
Definition: med_utils.h:316
MED_SNAME_SIZE
#define MED_SNAME_SIZE
Definition: med.h:90
__nconstituentpervalue
med_size __nconstituentpervalue
Definition: filterBlockOfentities.c:104
med_idt
hid_t med_idt
Definition: med.h:350
med_config.h
COM_info::comm
MPI_Comm comm
Definition: filterBlockOfentities.c:92
__nbblocksperproc
med_size __nbblocksperproc
Definition: filterBlockOfentities.c:101
MED_NO_INTERPOLATION
#define MED_NO_INTERPOLATION
Definition: med.h:288
MEDprofileWr
MEDC_EXPORT med_err MEDprofileWr(const med_idt fid, const char *const profilename, const med_int profilesize, const med_int *const profilearray)
Cette routine permet d'écrire un profil dans un fichier MED.
Definition: MEDprofileWr.c:40
__nentities
med_size __nentities
Definition: filterBlockOfentities.c:102
COM_info::filterarray
med_int * filterarray
Definition: filterBlockOfentities.c:96
MED_NO_INTERLACE
Definition: med.h:108
_MED_STORAGE_MODE_MSG
static char * _MED_STORAGE_MODE_MSG[3]
Definition: filterBlockOfentities.c:111
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:324
MED_FILTER_INIT
#define MED_FILTER_INIT
Definition: med.h:423
med_geometry_type
int med_geometry_type
Definition: med.h:205
MED_ERR_FILTER
#define MED_ERR_FILTER
Definition: med_err.h:93
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
MEDfilterSetFileInterlacing
MEDC_EXPORT med_err MEDfilterSetFileInterlacing(const med_idt fid, med_filter *const filter, const med_interlacing_mode switchmode)
Definition: MEDfilterSetFileInterlacing.c:27
COM_info::constituentselect
med_int constituentselect
Definition: filterBlockOfentities.c:97
COM_info::nentitiesfiltered
med_int nentitiesfiltered
Definition: filterBlockOfentities.c:95
MED_NO_LOCALIZATION
#define MED_NO_LOCALIZATION
Definition: med.h:286
ISCRUTE
#define ISCRUTE(entier)
Definition: med_utils.h:313
MEDmeshCr
MEDC_EXPORT med_err MEDmeshCr(const med_idt fid, const char *const meshname, const med_int spacedim, const med_int meshdim, const med_mesh_type meshtype, const char *const description, const char *const dtunit, const med_sorting_type sortingtype, const med_axis_type axistype, const char *const axisname, const char *const axisunit)
Cette routine permet de créer un maillage dans un fichier.
Definition: MEDmeshCr.c:45
generateFilterArray
med_err generateFilterArray(const med_size nentities, const med_size nvaluesperentity, const med_size nconstituentpervalue, const med_size profilearraysize, const med_int *const profilearray, med_int *const nentitiesfiltered, med_int **filterarray)
Definition: generateFilterArray.c:30
_MED_MODE_SWITCH_MSG
static char * _MED_MODE_SWITCH_MSG[3]
Definition: filterBlockOfentities.c:110
ISCRUTE_int
#define ISCRUTE_int(entier)
Definition: med_utils.h:314
SSCRUTE
#define SSCRUTE(chaine)
Definition: med_utils.h:323
getCyclicBlocksOfEntities
void getCyclicBlocksOfEntities(const int myrank, const int nproc, const med_int nentities, med_size *const start, med_size *const stride, med_size *const io_count, med_size *blocksize, int *const lastusedrank, med_size *const lastblocksize)
Definition: getBlocksOfEntitiesPartition.c:80
med_storage_mode
med_storage_mode
Definition: med.h:118
COM_info::info
MPI_Info info
Definition: filterBlockOfentities.c:91
MED_ERR_FILE
#define MED_ERR_FILE
Definition: med_err.h:82
MED_FULL_INTERLACE
Definition: med.h:106
COM_info::mpi_size
int mpi_size
Definition: filterBlockOfentities.c:93
MED_NO_PROFILE
#define MED_NO_PROFILE
Definition: med.h:292
MEDfilterClose
MEDC_EXPORT med_err MEDfilterClose(med_filter *const filter)
Dés-alloue les ressources hdf détenues par un filtre.
Definition: MEDfilterClose.c:35
med.h
MODE_ACCES
#define MODE_ACCES
Definition: filterBlockOfentities.c:37
__nvaluesperentity
med_size __nvaluesperentity
Definition: filterBlockOfentities.c:103
MED_ERR_MESH
#define MED_ERR_MESH
Definition: med_err.h:83
generateFullIDatas
void generateFullIDatas(const int myrank, const int lastrank, const int sizeoftype, const med_storage_mode profilemode, const med_size profilesize, const med_int *const profilearray, const med_size start, const med_size stride, const med_size count, const med_size blocksize, const med_size lastblocksize, const med_int nentities, const int nvaluesperentity, const int nconstituentpervalue, med_float **valuesarray)
Definition: generateDatas.c:31
GetBlocksOfEntitiesType
void(* GetBlocksOfEntitiesType)(const int myrank, const int nproc, const med_int nentities, med_size *const start, med_size *const stride, med_size *const count, med_size *blocksize, int *const lastusedrank, med_size *const lastblocksize)
Definition: getBlocksOfEntitiesPartition.h:28
MEDfilterEntityCr
MEDC_EXPORT med_err MEDfilterEntityCr(const med_idt fid, const med_int nentity, const med_int nvaluesperentity, const med_int nconstituentpervalue, const med_int constituentselect, const med_switch_mode switchmode, const med_storage_mode storagemode, const char *const profilename, const med_int filterarraysize, const med_int *const filterarray, med_filter *const filter)
Definition: MEDfilterEntityCr.c:55
med_switch_mode
med_switch_mode
Definition: med.h:106
med_float
double med_float
Definition: med.h:355
MED_ERR_FIELD
#define MED_ERR_FIELD
Definition: med_err.h:91
med_utils.h
MED_ACTIVATE_COMPARISON
#define MED_ACTIVATE_COMPARISON
Definition: filterBlockOfentities.c:21
med_filter
Filtre de sélection.
Definition: med.h:393
MED_GLOBAL_STMODE
Definition: med.h:119
MED_ERR_LOCALIZATION
#define MED_ERR_LOCALIZATION
Definition: med_err.h:89
MED_CELL
Definition: med.h:153
MED_UNSTRUCTURED_MESH
Definition: med.h:141
MEDfileOpen
MEDC_EXPORT med_idt MEDfileOpen(const char *const filename, const med_access_mode accessmode)
Ouverture d'un fichier MED.
Definition: MEDfileOpen.c:42
getBlocksOfEntitiesPartition.h
MEDfieldValueAdvancedWr
MEDC_EXPORT med_err MEDfieldValueAdvancedWr(const med_idt fid, const char *const fieldname, const med_int numdt, const med_int numit, const med_float dt, const med_entity_type entitype, const med_geometry_type geotype, const char *const localizationname, const med_filter *const filter, const unsigned char *const value)
Cette fonction permet d'écire les valeurs d'un champ définies sur des entités d'un maillage pour une ...
Definition: MEDfieldValueAdvancedWr.c:46
main
int main(int argc, char **argv)
Definition: filterBlockOfentities.c:516
MED_UNDEF_STMODE
Definition: med.h:118
generateFilterArray.h
MED_UNDEF_INTERLACE
Definition: med.h:110
GenerateDataType
void(* GenerateDataType)(const int myrank, const int lastrank, const int sizeoftype, const med_storage_mode profilemode, const med_size profilesize, const med_int *const profilearray, const med_size start, const med_size stride, const med_size count, const med_size blocksize, const med_size lastblocksize, const med_int nentities, const int nvaluesperentity, const int nconstituentpervalue, med_float **valuesarray)
Definition: generateDatas.h:27