18 #define MAX(a,b) ((a) > (b) ? (a) : (b))
33 # include <sys/timeb.h>
38 # include <sys/time.h>
44 #error "unistd.h required."
55 #define MODE_ACCES MED_ACC_RDWR
57 #define MODE_ACCES MED_ACC_RDEXT
59 #define MODE_ACCES MED_ACC_CREAT
102 char _filename [255]=
"";
108 char *componentname,*componentunit;
111 int _i=0,_j=0,_k=0, _lastusedrank=0;
112 med_size _blocksize=0,_lastblocksize=0,_count=0,_stride=0,_start=0,_index=0;
115 med_size _nusedentities = nentities;
116 med_size _io_count = nbblocksperproc;
119 MPI_Info info = cominfo->
info;
120 MPI_Comm comm = cominfo->
comm;
124 char *_MED_MODE_SWITCH_MSG[3]={
"MED_FULL_INTERLACE",
"MED_NO_INTERLACE",
"MED_UNDEF_INTERLACE",};
125 char *_MED_STORAGE_MODE_MSG[3]={
"MED_NO_STMODE",
"MED_GLOBAL_STMODE",
"MED_COMPACT_STMODE"};
128 med_int _geodim = _geotype/100;
129 med_int _geonnodes = _geotype%100;
132 med_int _ipoint = nvaluesperentity;
136 sprintf(_filename,
"%s_CPU-%03d_@_%s_%s.med",fieldnameprefix,mpi_size,_MED_MODE_SWITCH_MSG[constituentmode],_MED_STORAGE_MODE_MSG[storagemode]);
147 MED_CARTESIAN, _meshcomponentname, _meshcomponentunit) < 0) {
152 componentname = (
char*) malloc((nconstituentpervalue*
MED_SNAME_SIZE+1)*
sizeof(char));
153 componentunit = (
char*) malloc((nconstituentpervalue*
MED_SNAME_SIZE+1)*
sizeof(char));
155 strcpy(componentname,
"");
156 strcpy(componentunit,
"");
157 strcpy(_fieldname,fieldnameprefix);
158 if (
MEDfieldCr(_fid,_fieldname,
MED_FLOAT64,nconstituentpervalue,componentname,componentunit,
"s",_meshname ) < 0) {
168 MESSAGE(
"Creating a localization of integration points...");
169 strcpy(_ipointname,_fieldname);
170 strcat(_ipointname,
"_loc");
177 if (
MEDlocalizationWr(_fid, _ipointname, _geotype, _geotype/100, _ipointrefcoo, constituentmode,
183 free(_ipointrefcoo );
191 if (profilearraysize) {
192 MESSAGE(
"Creating a profile...");
194 strcpy(_profilename,_fieldname);strcat(_profilename,
"_profile");
196 _profilearray = (
med_int*) calloc(profilearraysize,
sizeof(
med_int));
198 for (_i=0; _i < profilearraysize; ++_i) _profilearray[_i]=_i;
199 if (
MEDprofileWr(_fid,_profilename,profilearraysize,_profilearray) < 0) {
203 _nusedentities = profilearraysize;
209 MESSAGE(
"Generating partition...");
210 getBlockOfEntities ( mpi_rank , mpi_size, _nusedentities,
211 &_start, &_stride, &_io_count, &_blocksize,
212 &_lastusedrank, &_lastblocksize);
215 MESSAGE(
"Generating filter...");
218 _start,_stride,_count,_blocksize,_lastblocksize, &filter) < 0 ) {
223 MESSAGE(
"Generating datas...");
224 generateDatas(mpi_rank, _lastusedrank,
sizeof(
med_float),
225 storagemode, profilearraysize, _profilearray,
226 _start, _stride, _count, _blocksize, _lastblocksize,
227 nentities, nvaluesperentity, nconstituentpervalue,
232 _ipointname, &filter, (
unsigned char*)_arrayvalues ) < 0) {
240 H5Fflush(_fid, H5F_SCOPE_GLOBAL );
243 if (mpi_rank == 0 ) {
247 med_int _nentitiesarrayvalues=0;
252 char _asciifilename[255]=
"";
260 sprintf(_asciifilename,
"%s_CPU-%03d_@_%s_%s.ascii",fieldnameprefix,mpi_size,_MED_MODE_SWITCH_MSG[constituentmode],_MED_STORAGE_MODE_MSG[storagemode]);
261 _asciifile=fopen(_asciifilename,
"w");
267 profilearraysize, _profilearray,
276 fprintf(_asciifile,
"%d ",cominfo->
filterarray[_i]) ;
278 fprintf(_asciifile,
"\n") ;
282 if ( profilearraysize ) {
283 _nentitiesarrayvalues = profilearraysize;
285 _nentitiesarrayvalues = nentities;
292 _filteredarrayvalues = (
med_float*) malloc(_nentitiesarrayvalues*
297 for (_i=0;_i<_nentitiesarrayvalues*nvaluesperentity*nconstituentpervalue; ++_i)
298 _filteredarrayvalues[_i]=-_i;
302 if (
MEDfilterEntityCr(_fidseq, nentities, nvaluesperentity, nconstituentpervalue,
310 &filter2, (
unsigned char*)_filteredarrayvalues ) < 0) {
319 switch (constituentmode) {
322 for (_j=0; _j < nvaluesperentity; ++_j)
323 for (_k=0; _k < nconstituentpervalue; ++_k) {
324 _ind = (cominfo->
filterarray[_i]-1)*nvaluesperentity*nconstituentpervalue+ _j*nconstituentpervalue+_k;
326 fprintf(_asciifile,
"%f\n",_filteredarrayvalues[_ind]) ;
331 for (_k=0; _k < nvaluesperentity; ++_k)
332 for (_i=0; _i < nconstituentpervalue; ++_i) {
333 _ind =_i*nentities*nvaluesperentity+ (cominfo->
filterarray[_j]-1)*nvaluesperentity +_k;
335 fprintf(_asciifile,
"%f\n",_filteredarrayvalues[_ind]);
340 switch (constituentmode) {
343 for (_j=0; _j < nvaluesperentity; ++_j)
344 for (_k=0; _k < nconstituentpervalue; ++_k) {
345 _ind = _i*nvaluesperentity*nconstituentpervalue+_j*nconstituentpervalue+_k;
347 fprintf(_asciifile,
"%f\n",_filteredarrayvalues[_ind]) ;
352 for (_k=0; _k < nvaluesperentity; ++_k)
353 for (_i=0; _i < nconstituentpervalue; ++_i) {
357 fprintf(_asciifile,
"%f\n",_filteredarrayvalues[_ind]);
363 free(_filteredarrayvalues);
382 if (_arrayvalues) free(_arrayvalues);
383 if (profilearraysize) free(_profilearray);
389 if (mpi_rank == 0 ) {
400 int main (
int argc,
char **argv)
406 _cominfo.
comm = MPI_COMM_WORLD;
407 _cominfo.
info = MPI_INFO_NULL;
413 MPI_Init(&argc, &argv);
414 MPI_Comm_size(MPI_COMM_WORLD, &(_cominfo.
mpi_size));
415 MPI_Comm_rank(MPI_COMM_WORLD, &(_cominfo.
mpi_rank));
419 int _nvaluesperentity = 0;
420 int _nconstituentpervalue = 0;
426 _tm = localtime(&_tt);
428 srandom((*_tm).tm_sec * (*_tm).tm_min );
429 _nbblocksperproc = 1 + (int) (_cominfo.
mpi_size * (random() / (RAND_MAX + 1.0)));
430 _nentities = 1 + (int) (1000.0 * (random() / (RAND_MAX + 1.0)));
431 _nvaluesperentity = 1 + (int) (11.0 * (random() / (RAND_MAX + 1.0)));
432 _nconstituentpervalue = 1 + (int) (7.0 * (random() / (RAND_MAX + 1.0)));
444 if ( (
sizeof(
med_size)%(
sizeof(MPI_LONG)))==0 ) {
446 MPI_Bcast(&_nbblocksperproc ,
sizeof(
med_size)/
sizeof(MPI_LONG), MPI_LONG, 0, MPI_COMM_WORLD);
447 MPI_Bcast(&_nentities ,
sizeof(
med_size)/
sizeof(MPI_LONG), MPI_LONG, 0, MPI_COMM_WORLD);
448 MPI_Bcast(&_nvaluesperentity ,
sizeof(
med_size)/
sizeof(MPI_LONG), MPI_LONG, 0, MPI_COMM_WORLD);
449 MPI_Bcast(&_nconstituentpervalue ,
sizeof(
med_size)/
sizeof(MPI_LONG), MPI_LONG, 0, MPI_COMM_WORLD);
451 assert(
sizeof(
med_size) == (
sizeof(MPI_LONG)));
454 char _fieldnameprefix[256] =
"";
456 sprintf(_fieldnameprefix,
"NENT-%03d_NVAL-%03d_NCST-%03d_NBL-%03llu",_nentities,_nvaluesperentity,
457 _nconstituentpervalue,_nbblocksperproc);
474 if ( (_storagemode ==
MED_GLOBAL_STMODE ) && (_profilearraysize) ) _profilearraysize=0;
478 _storagemode, _profilearraysize, _fieldnameprefix, & _cominfo) < 0 ) {