getBlocksOfEntitiesPartition.c
Aller à la documentation de ce fichier.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <med.h>
00020 #define MESGERR 1
00021 #include "med_utils.h"
00022
00023
00024 #include "getBlocksOfEntitiesPartition.h"
00025
00026
00027 void getContinuousBlocksOfEntities(const int myrank, const int nproc, const int nbofentities,
00028 med_size * const start, med_size * const stride, med_size * const count, med_size * blocksize,
00029 int * const lastusedrank, med_size * const lastblocksize ) {
00030
00031 int _nusedproc = nproc;
00032 int _lastusedrank = nproc-1;
00033 med_size _blocksize = nbofentities/nproc;
00034 int _nblocks_pproc = 0;
00035
00036
00037 if ( _blocksize == 0 ) {
00038 if (myrank == 0 ) { _nblocks_pproc=1;_blocksize=nbofentities;}
00039 _lastusedrank = 0;
00040 _nusedproc = 1;
00041 _blocksize = nbofentities;
00042 } else {
00043 _nblocks_pproc = 1;
00044 }
00045
00046 *start = myrank*_nblocks_pproc*_blocksize;
00047 *stride = _blocksize;
00048 *count = _nblocks_pproc;
00049 *lastblocksize = 0;
00050
00051 if ( myrank == _lastusedrank ) {
00052 *blocksize = nbofentities+_blocksize*(1-_nusedproc);
00053 } else {
00054 *blocksize =_blocksize;
00055 }
00056 ++(*start);
00057 *lastusedrank=_lastusedrank;
00058 printf("My rank %d, start %l, stride %l, blocksize %l, count %l, lastblocksize %l\n",myrank,*start,*stride,*blocksize,*count,*lastblocksize);
00059 return;
00060 }
00061
00062 void getCyclicBlocksOfEntities(const int myrank, const int nproc, const int nbofentities,
00063 med_size * const start, med_size * const stride, med_size * const io_count, med_size * blocksize,
00064 int * const lastusedrank, med_size * const lastblocksize ) {
00065
00066 int _nusedproc = nproc;
00067 int _lastusedrank = nproc-1;
00068 int _nblocks_pproc = *io_count;
00069 int _nblocks = _nblocks_pproc*nproc;
00070 med_size _blocksize = 0;
00071
00072 if (_nblocks) _blocksize=nbofentities/_nblocks;
00073
00074 for (; (_blocksize < 1) && ( _nblocks_pproc > 1 ) ; ) {
00075 --_nblocks_pproc;
00076 _nblocks = _nblocks_pproc*nproc;
00077 _blocksize = nbofentities/_nblocks;
00078 }
00079
00080
00081
00082
00083 if ( _blocksize == 0 ) {
00084 MESSAGE("Downcasting getCyclicBlocksOfEntities by getContinuousBlocksOfEntities");
00085 getContinuousBlocksOfEntities(myrank, nproc, nbofentities,
00086 start, stride, io_count, blocksize, lastusedrank, lastblocksize );
00087 return;
00088 }
00089
00090 *blocksize = _blocksize;
00091 *stride = _blocksize*nproc;
00092 *start = _blocksize*myrank;
00093 *io_count = _nblocks_pproc;
00094
00095 if (myrank == _lastusedrank) {
00096 *lastblocksize = nbofentities + _blocksize*(1-_nusedproc*_nblocks_pproc);
00097 if ( _nblocks_pproc == 1 ) *blocksize=*lastblocksize;
00098 } else
00099 *lastblocksize=0;
00100
00101 ++(*start);
00102 *lastusedrank=_lastusedrank;
00103
00104 return;
00105 }
00106
00107
00108
00109
00110
00111