#define MAX(a,b) ((a) > (b) ? (a) : (b))
#include <med.h>
#define MESGERR 1
#include "med_utils.h"
#include "med_config.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# if HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#endif
#ifndef HAVE_UNISTD_H
#error "unistd.h required."
#endif
#ifdef DEF_LECT_ECR
#define MODE_ACCES MED_ACC_RDWR
#elif DEF_LECT_AJOUT
#define MODE_ACCES MED_ACC_RDEXT
#else
#define MODE_ACCES MED_ACC_CREAT
#endif
typedef struct {
MPI_Info info;
MPI_Comm comm;
int mpi_size;
int mpi_rank;
char _filename [255]="";
char *componentname,*componentunit;
int _i=0,_j=0,_k=0, _lastusedrank=0;
med_size _blocksize=0,_lastblocksize=0,_count=0,_stride=0,_start=0,_index=0;
MPI_Info info = cominfo->
info;
MPI_Comm comm = cominfo->
comm;
char *_MED_MODE_SWITCH_MSG[3]={"MED_FULL_INTERLACE", "MED_NO_INTERLACE","MED_UNDEF_INTERLACE",};
char *_MED_STORAGE_MODE_MSG[3]={"MED_NO_STMODE","MED_GLOBAL_STMODE", "MED_COMPACT_STMODE"};
med_int _ipoint = nvaluesperentity;
sprintf(_filename,"%s_CPU-%03d_@_%s_%s.med",fieldnameprefix,mpi_size,_MED_MODE_SWITCH_MSG[constituentmode],_MED_STORAGE_MODE_MSG[storagemode]);
goto ERROR;
}
goto ERROR;
};
componentname = (
char*) malloc((nconstituentpervalue*
MED_SNAME_SIZE+1)*
sizeof(char));
componentunit = (
char*) malloc((nconstituentpervalue*
MED_SNAME_SIZE+1)*
sizeof(char));
strcpy(componentname,"");
strcpy(componentunit,"");
strcpy(_fieldname,fieldnameprefix);
if (
MEDfieldCr(_fid,_fieldname,
MED_FLOAT64,nconstituentpervalue,componentname,componentunit,
"s",_meshname ) < 0) {
goto ERROR;
};
free(componentname);
free(componentunit);
if ( _ipoint > 1 ) {
MESSAGE(
"Creating a localization of integration points...");
strcpy(_ipointname,_fieldname);
strcat(_ipointname,"_loc");
if (
MEDlocalizationWr(_fid, _ipointname, _geotype, _geotype/100, _ipointrefcoo, constituentmode,
goto ERROR;
}
free(_ipointrefcoo );
free(_ipointcoo );
free(_ipointwg );
} else {
}
if (profilearraysize) {
strcpy(_profilename,_fieldname);strcat(_profilename,"_profile");
for (_i=0; _i < profilearraysize; ++_i) _profilearray[_i]=_i;
if (
MEDprofileWr(_fid,_profilename,profilearraysize,_profilearray) < 0) {
goto ERROR;
};
_nusedentities = profilearraysize;
} else {
}
MESSAGE(
"Generating partition...");
getBlockOfEntities ( mpi_rank , mpi_size, _nusedentities,
&_start, &_stride, &_io_count, &_blocksize,
&_lastusedrank, &_lastblocksize);
_count=_io_count;
_start,_stride,_count,_blocksize,_lastblocksize, &filter) < 0 ) {
goto ERROR;
}
generateDatas(mpi_rank, _lastusedrank,
sizeof(
med_float),
storagemode, profilearraysize, _profilearray,
_start, _stride, _count, _blocksize, _lastblocksize,
nentities, nvaluesperentity, nconstituentpervalue,
&_arrayvalues );
_ipointname, &filter, (unsigned char*)_arrayvalues ) < 0) {
goto ERROR;
}
H5Fflush(_fid, H5F_SCOPE_GLOBAL );
if (mpi_rank == 0 ) {
int _ind=0;
FILE * _asciifile;
char _asciifilename[255]="";
goto ERROR;
}
sprintf(_asciifilename,"%s_CPU-%03d_@_%s_%s.ascii",fieldnameprefix,mpi_size,_MED_MODE_SWITCH_MSG[constituentmode],_MED_STORAGE_MODE_MSG[storagemode]);
_asciifile=fopen(_asciifilename, "w");
profilearraysize, _profilearray,
goto ERROR;
}
}
fprintf(_asciifile,"\n") ;
if ( profilearraysize ) {
_nentitiesarrayvalues = profilearraysize;
} else {
_nentitiesarrayvalues = nentities;
}
_filteredarrayvalues = (
med_float*) malloc(_nentitiesarrayvalues*
nvaluesperentity*
for (_i=0;_i<_nentitiesarrayvalues*nvaluesperentity*nconstituentpervalue; ++_i)
_filteredarrayvalues[_i]=-_i;
goto ERROR;
}
&filter2, (unsigned char*)_filteredarrayvalues ) < 0) {
goto ERROR;
}
switch (constituentmode) {
for (_j=0; _j < nvaluesperentity; ++_j)
for (_k=0; _k < nconstituentpervalue; ++_k) {
_ind = (cominfo->
filterarray[_i]-1)*nvaluesperentity*nconstituentpervalue+ _j*nconstituentpervalue+_k;
fprintf(_asciifile,"%f\n",_filteredarrayvalues[_ind]) ;
}
break;
for (_k=0; _k < nvaluesperentity; ++_k)
for (_i=0; _i < nconstituentpervalue; ++_i) {
_ind =_i*nentities*nvaluesperentity+ (cominfo->
filterarray[_j]-1)*nvaluesperentity +_k;
fprintf(_asciifile,"%f\n",_filteredarrayvalues[_ind]);
}
break;
}
} else
switch (constituentmode) {
for (_j=0; _j < nvaluesperentity; ++_j)
for (_k=0; _k < nconstituentpervalue; ++_k) {
_ind = _i*nvaluesperentity*nconstituentpervalue+_j*nconstituentpervalue+_k;
fprintf(_asciifile,"%f\n",_filteredarrayvalues[_ind]) ;
}
break;
for (_k=0; _k < nvaluesperentity; ++_k)
for (_i=0; _i < nconstituentpervalue; ++_i) {
fprintf(_asciifile,"%f\n",_filteredarrayvalues[_ind]);
}
break;
}
free(_filteredarrayvalues);
fclose(_asciifile);
goto ERROR;
}
}
goto ERROR;
}
_ret=0;
ERROR:
if (_arrayvalues) free(_arrayvalues);
if (profilearraysize) free(_profilearray);
}
if (mpi_rank == 0 ) {
}
}
return _ret;
}
int main (
int argc,
char **argv)
{
_cominfo.
comm = MPI_COMM_WORLD;
_cominfo.
info = MPI_INFO_NULL;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &(_cominfo.
mpi_size));
MPI_Comm_rank(MPI_COMM_WORLD, &(_cominfo.
mpi_rank));
int _nentities = 0;
int _nvaluesperentity = 0;
int _nconstituentpervalue = 0;
struct tm *_tm ;
time_t _tt=time(0);
_tm = localtime(&_tt);
srandom((*_tm).tm_sec * (*_tm).tm_min );
_nbblocksperproc = 1 + (int) (_cominfo.
mpi_size * (random() / (RAND_MAX + 1.0)));
_nentities = 1 + (int) (1000.0 * (random() / (RAND_MAX + 1.0)));
_nvaluesperentity = 1 + (int) (11.0 * (random() / (RAND_MAX + 1.0)));
_nconstituentpervalue = 1 + (int) (7.0 * (random() / (RAND_MAX + 1.0)));
}
if ( (
sizeof(
med_size)%(
sizeof(MPI_LONG)))==0 ) {
MPI_Bcast(&_nbblocksperproc ,
sizeof(
med_size)/
sizeof(MPI_LONG), MPI_LONG, 0, MPI_COMM_WORLD);
MPI_Bcast(&_nentities ,
sizeof(
med_size)/
sizeof(MPI_LONG), MPI_LONG, 0, MPI_COMM_WORLD);
MPI_Bcast(&_nvaluesperentity ,
sizeof(
med_size)/
sizeof(MPI_LONG), MPI_LONG, 0, MPI_COMM_WORLD);
MPI_Bcast(&_nconstituentpervalue ,
sizeof(
med_size)/
sizeof(MPI_LONG), MPI_LONG, 0, MPI_COMM_WORLD);
} else {
assert(
sizeof(
med_size) == (
sizeof(MPI_LONG)));
}
char _fieldnameprefix[256] = "";
sprintf(_fieldnameprefix,"NENT-%03d_NVAL-%03d_NCST-%03d_NBL-%03llu",_nentities,_nvaluesperentity,
_nconstituentpervalue,_nbblocksperproc);
if ( (_storagemode ==
MED_GLOBAL_STMODE ) && (_profilearraysize) ) _profilearraysize=0;
_storagemode, _profilearraysize, _fieldnameprefix, & _cominfo) < 0 ) {
goto ERROR;
}
}
}
_ret = 0;
ERROR:
MPI_Finalize();
return _ret;
}
int main(int argc, char **argv)
#define MED_NO_LOCALIZATION
#define MED_NO_INTERPOLATION
#define MED_ALL_CONSTITUENT
#define MED_NO_MESH_SUPPORT
#define MED_ERR_(rt, r1, r2, r3)
#define ISCRUTE_int(entier)
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_ERR_LOCALIZATION
med_int nentitiesfiltered