18#define MAX(a,b) ((a) > (b) ? (a) : (b))
41#error "unistd.h required."
50#define MODE_ACCES MED_ACC_RDWR
52#define MODE_ACCES MED_ACC_RDEXT
54#define MODE_ACCES MED_ACC_CREAT
97 char _filename [255]=
"";
103 char *componentname,*componentunit;
106 int _i=0,_j=0,_k=0, _lastusedrank=0;
107 med_size _blocksize=0,_lastblocksize=0,_count=0,_stride=0,_start=0,_index=0;
110 med_size _nusedentities = nentities;
111 med_size _io_count = nbblocksperproc;
114 MPI_Info info = cominfo->
info;
115 MPI_Comm comm = cominfo->
comm;
119 char *_MED_MODE_SWITCH_MSG[3]={
"MED_FULL_INTERLACE",
"MED_NO_INTERLACE",
"MED_UNDEF_INTERLACE",};
120 char *_MED_STORAGE_MODE_MSG[3]={
"MED_NO_STMODE",
"MED_GLOBAL_STMODE",
"MED_COMPACT_STMODE"};
123 med_int _geodim = _geotype/100;
124 med_int _geonnodes = _geotype%100;
127 med_int _ipoint = nvaluesperentity;
131 sprintf(_filename,
"%s_CPU-%03d_@_%s_%s.med",fieldnameprefix,mpi_size,_MED_MODE_SWITCH_MSG[constituentmode],_MED_STORAGE_MODE_MSG[storagemode]);
142 MED_CARTESIAN, _meshcomponentname, _meshcomponentunit) < 0) {
147 componentname = (
char*) malloc((nconstituentpervalue*
MED_SNAME_SIZE+1)*
sizeof(char));
148 componentunit = (
char*) malloc((nconstituentpervalue*
MED_SNAME_SIZE+1)*
sizeof(char));
150 strcpy(componentname,
"");
151 strcpy(componentunit,
"");
152 strcpy(_fieldname,fieldnameprefix);
153 if (
MEDfieldCr(_fid,_fieldname,
MED_FLOAT64,nconstituentpervalue,componentname,componentunit,
"s",_meshname ) < 0) {
163 MESSAGE(
"Creating a localization of integration points...");
164 strcpy(_ipointname,_fieldname);
165 strcat(_ipointname,
"_loc");
172 if (
MEDlocalizationWr(_fid, _ipointname, _geotype, _geotype/100, _ipointrefcoo, constituentmode,
178 free(_ipointrefcoo );
186 if (profilearraysize) {
187 MESSAGE(
"Creating a profile...");
189 strcpy(_profilename,_fieldname);strcat(_profilename,
"_profile");
191 _profilearray = (
med_int*) calloc(profilearraysize,
sizeof(
med_int));
193 for (_i=0; _i < profilearraysize; ++_i) _profilearray[_i]=_i;
194 if (
MEDprofileWr(_fid,_profilename,profilearraysize,_profilearray) < 0) {
198 _nusedentities = profilearraysize;
204 MESSAGE(
"Generating partition...");
205 getBlockOfEntities ( mpi_rank , mpi_size, _nusedentities,
206 &_start, &_stride, &_io_count, &_blocksize,
207 &_lastusedrank, &_lastblocksize);
210 MESSAGE(
"Generating filter...");
213 _start,_stride,_count,_blocksize,_lastblocksize, &filter) < 0 ) {
218 MESSAGE(
"Generating datas...");
219 generateDatas(mpi_rank, _lastusedrank,
sizeof(
med_float),
220 storagemode, profilearraysize, _profilearray,
221 _start, _stride, _count, _blocksize, _lastblocksize,
222 nentities, nvaluesperentity, nconstituentpervalue,
227 _ipointname, &filter, (
unsigned char*)_arrayvalues ) < 0) {
235 H5Fflush(_fid, H5F_SCOPE_GLOBAL );
238 if (mpi_rank == 0 ) {
242 med_int _nentitiesarrayvalues=0;
247 char _asciifilename[255]=
"";
255 sprintf(_asciifilename,
"%s_CPU-%03d_@_%s_%s.ascii",fieldnameprefix,mpi_size,_MED_MODE_SWITCH_MSG[constituentmode],_MED_STORAGE_MODE_MSG[storagemode]);
256 _asciifile=fopen(_asciifilename,
"w");
262 profilearraysize, _profilearray,
271 fprintf(_asciifile,
"%d ",cominfo->
filterarray[_i]) ;
273 fprintf(_asciifile,
"\n") ;
277 if ( profilearraysize ) {
278 _nentitiesarrayvalues = profilearraysize;
280 _nentitiesarrayvalues = nentities;
287 _filteredarrayvalues = (
med_float*) malloc(_nentitiesarrayvalues*
292 for (_i=0;_i<_nentitiesarrayvalues*nvaluesperentity*nconstituentpervalue; ++_i)
293 _filteredarrayvalues[_i]=-_i;
297 if (
MEDfilterEntityCr(_fidseq, nentities, nvaluesperentity, nconstituentpervalue,
305 &filter2, (
unsigned char*)_filteredarrayvalues ) < 0) {
314 switch (constituentmode) {
317 for (_j=0; _j < nvaluesperentity; ++_j)
318 for (_k=0; _k < nconstituentpervalue; ++_k) {
319 _ind = (cominfo->
filterarray[_i]-1)*nvaluesperentity*nconstituentpervalue+ _j*nconstituentpervalue+_k;
321 fprintf(_asciifile,
"%f\n",_filteredarrayvalues[_ind]) ;
326 for (_k=0; _k < nvaluesperentity; ++_k)
327 for (_i=0; _i < nconstituentpervalue; ++_i) {
328 _ind =_i*nentities*nvaluesperentity+ (cominfo->
filterarray[_j]-1)*nvaluesperentity +_k;
330 fprintf(_asciifile,
"%f\n",_filteredarrayvalues[_ind]);
335 switch (constituentmode) {
338 for (_j=0; _j < nvaluesperentity; ++_j)
339 for (_k=0; _k < nconstituentpervalue; ++_k) {
340 _ind = _i*nvaluesperentity*nconstituentpervalue+_j*nconstituentpervalue+_k;
342 fprintf(_asciifile,
"%f\n",_filteredarrayvalues[_ind]) ;
347 for (_k=0; _k < nvaluesperentity; ++_k)
348 for (_i=0; _i < nconstituentpervalue; ++_i) {
352 fprintf(_asciifile,
"%f\n",_filteredarrayvalues[_ind]);
358 free(_filteredarrayvalues);
377 if (_arrayvalues) free(_arrayvalues);
378 if (profilearraysize) free(_profilearray);
384 if (mpi_rank == 0 ) {
395int main (
int argc,
char **argv)
401 _cominfo.
comm = MPI_COMM_WORLD;
402 _cominfo.
info = MPI_INFO_NULL;
408 MPI_Init(&argc, &argv);
409 MPI_Comm_size(MPI_COMM_WORLD, &(_cominfo.
mpi_size));
410 MPI_Comm_rank(MPI_COMM_WORLD, &(_cominfo.
mpi_rank));
414 int _nvaluesperentity = 0;
415 int _nconstituentpervalue = 0;
421 _tm = localtime(&_tt);
423 srandom((*_tm).tm_sec * (*_tm).tm_min );
424 _nbblocksperproc = 1 + (int) (_cominfo.
mpi_size * (random() / (RAND_MAX + 1.0)));
425 _nentities = 1 + (int) (1000.0 * (random() / (RAND_MAX + 1.0)));
426 _nvaluesperentity = 1 + (int) (11.0 * (random() / (RAND_MAX + 1.0)));
427 _nconstituentpervalue = 1 + (int) (7.0 * (random() / (RAND_MAX + 1.0)));
439 if ( (
sizeof(
med_size)%(
sizeof(MPI_LONG)))==0 ) {
441 MPI_Bcast(&_nbblocksperproc ,
sizeof(
med_size)/
sizeof(MPI_LONG), MPI_LONG, 0, MPI_COMM_WORLD);
442 MPI_Bcast(&_nentities ,
sizeof(
med_size)/
sizeof(MPI_LONG), MPI_LONG, 0, MPI_COMM_WORLD);
443 MPI_Bcast(&_nvaluesperentity ,
sizeof(
med_size)/
sizeof(MPI_LONG), MPI_LONG, 0, MPI_COMM_WORLD);
444 MPI_Bcast(&_nconstituentpervalue ,
sizeof(
med_size)/
sizeof(MPI_LONG), MPI_LONG, 0, MPI_COMM_WORLD);
446 assert(
sizeof(
med_size) == (
sizeof(MPI_LONG)));
449 char _fieldnameprefix[256] =
"";
451 sprintf(_fieldnameprefix,
"NENT-%03d_NVAL-%03d_NCST-%03d_NBL-%03llu",_nentities,_nvaluesperentity,
452 _nconstituentpervalue,_nbblocksperproc);
469 if ( (_storagemode ==
MED_GLOBAL_STMODE ) && (_profilearraysize) ) _profilearraysize=0;
473 _storagemode, _profilearraysize, _fieldnameprefix, & _cominfo) < 0 ) {
int main(int argc, char **argv)
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)
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 int nentities, const int nvaluesperentity, const int nconstituentpervalue, med_float **valuesarray)
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 int nentities, const int nvaluesperentity, const int nconstituentpervalue, med_float **valuesarray)
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 int nentities, const int nvaluesperentity, const int nconstituentpervalue, med_float **valuesarray)
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)
void getCyclicBlocksOfEntities(const int myrank, const int nproc, const 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)
void(* GetBlocksOfEntitiesType)(const int myrank, const int nproc, const int nentities, med_size *const start, med_size *const stride, med_size *const count, med_size *blocksize, int *const lastusedrank, med_size *const lastblocksize)
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 ...
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.
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 ...
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
MEDC_EXPORT med_idt MEDfileOpen(const char *const filename, const med_access_mode accessmode)
Ouverture d'un fichier MED.
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.
MEDC_EXPORT med_err MEDfilterClose(med_filter *const filter)
Désalloue les ressources hdf détenues par un filtre.
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)
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 selectionnant par blocs les entités pour lesquelles on veut lire/écrire des valeurs...
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...
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.
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.
#define MED_NO_LOCALIZATION
#define MED_NO_INTERPOLATION
#define MED_ALL_CONSTITUENT
#define MED_NO_MESH_SUPPORT
#define MED_ERR_LOCALIZATION
#define MED_ERR_(rt, r1, r2, r3)
#define ISCRUTE_int(entier)
med_int nentitiesfiltered