#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MESGERR 1
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#ifdef PPRO_NT_CALL
# include <windows.h>
# include <Lmcons.h>
# include <sys/timeb.h>
# include <time.h>
#else
# if HAVE_SYS_TIME_H
# include <sys/time.h>
# endif
#include <time.h>
#ifndef HAVE_UNISTD_H
#error "unistd.h required."
#endif
#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;
}