55 #define pow2(x) ( 1<<(x) )
75 if ( in != NULL ) in->numUses ++;
81 if ( in == NULL )
return in;
90 int result = MPI_Comm_split( in->comm, group, in->selfRank, &(ptopo->comm) );
92 MPI_Comm_rank( ptopo->comm, &(ptopo->selfRank) );
93 MPI_Comm_size( ptopo->comm, &(ptopo->numProcs) );
97 ptopo->global = in->global;
99 MPI_Group globalGroup, localGroup;
100 MPI_Comm_group( in->global->comm, &globalGroup );
101 MPI_Comm_group( ptopo->comm, &localGroup ),
102 MPI_Group_difference( globalGroup, localGroup, &(ptopo->antiCommGroup) );
111 hit_errInternal( __FUNCTION__,
"Trying to free a null pointer",
"", __FILE__, __LINE__);
114 fprintf(stderr,
"hit_ptopFree PTOP %d, %d, %d\n", (*in)->numUses, (*in)->selfRank, (*in)->numProcs );
117 if ( (*in)->numUses < 1 )
118 hit_errInternal( __FUNCTION__,
"Trying to free a null physical topology",
"", __FILE__, __LINE__);
121 if ( (*in)->numUses < 1 ) {
122 MPI_Comm_free( &((*in)->comm) );
131 hit_errInternal( __FUNCTION__,
"Trying to free a null topology",
"", __FILE__, __LINE__);
144 res.
card[0] = ptopo->numProcs;
148 res.
active = ( ptopo->selfRank < ptopo->numProcs ) ? 1 : 0;
162 res.
card[0] = (int)(
pow2( (
int)log2( ptopo->numProcs ) ) );
166 res.
active = ( ptopo->selfRank < res.
card[0] ) ? 1 : 0;
182 double dsize = sqrt( (
double)(ptopo->numProcs) );
183 int size = (int)dsize;
215 low = high = (int)sqrt( (
double)(ptopo->numProcs) );
219 while ( product != ptopo->numProcs ) {
220 if (product < ptopo->numProcs) {
222 product = product + low;
226 if (low==1) { high=ptopo->numProcs; product=ptopo->numProcs; }
227 else product = product - high;
235 res.
self.
rank[0] = ptopo->selfRank / low;
236 res.
self.
rank[1] = ptopo->selfRank % low;
264 logn = (int)floor(log((
double)(ptopo->numProcs))/log(2.0));
268 logs[i] = logn / dims + ((logn % dims > i) ? 1 : 0 );
269 cards[i] =
pow2(logs[i]);
275 for(i=0;i<
dims;i++) oldcards[i] = cards[i];
281 product *= cards[j] + ( j == i ? 1 : 0 );
283 if( product <= ptopo->numProcs ) cards[i]++;
289 if(cards[i] != oldcards[i]) goon = 1;
296 for(i=0;i<
dims;i++) res.
card[i] = cards[i];
307 res.
active = ( ptopo->selfRank < product ) ? 1 : 0;
324 hit_errInternal( __FUNCTION__,
"Trying to use a number of dimensions greater above the maximum\n. Increment HIT_MAXDIMS and recompile Hitmap",
"", __FILE__, __LINE__);
327 hit_errInternal( __FUNCTION__,
"You cannot define a number of dimensions equal to zero",
"", __FILE__, __LINE__);
333 res.
card[i] = virprocelems[i];
338 int totalProcNumber=1;
340 totalProcNumber *= virprocelems[i];
346 HitPTopology *ptopo2;
351 ptopo2->numProcs = totalProcNumber;
352 ptopo2->selfRank = 0;
353 ptopo2->comm = MPI_COMM_SELF;
381 int newDimRank = topo.
self.
rank[dim] + shift;
384 if ( newDimRank < 0 || newDimRank > topo.
card[dim]-1 )
399 for ( i=topo.
numDims-1; i>=0; i--) {
401 if ( i == dim ) newRank = newRank + newDimRank * acumCard;
403 else newRank = newRank + topo.
self.
rank[i] * acumCard;
406 acumCard = acumCard * topo.
card[i];
424 for(dim=topo.
numDims-1; dim>=0; dim--) {
426 linear = linear + acumCard * ranks.
rank[dim];
427 acumCard = acumCard * topo.
card[dim];
431 if ( linear < 0 || linear >= acumCard )
return HIT_RANK_NULL;
449 for(dim=topo.
numDims-1; dim>=0; dim--) {
450 res.
rank[dim] = (linealRank / acumCard) % topo.
card[dim];
451 acumCard *= topo.
card[dim];
HitTopology hit_topology_plug_topSquare(HitPTopology *topo)
HitPTopology HIT_PTOPOLOGY_NULL
HitTopology hit_topology_plug_topPlainPower2(HitPTopology *topo)
HitPTopology * hit_ptopSplit(HitPTopology *in, int group)
#define HIT_TOPOLOGY_DUMMYDIMS
int hit_topRankInternal(HitTopology topo, HitRanks ranks)
#define hit_topDimCard(topo, i)
HitPTopology * HIT_TOPOLOGY_INFO
#define HIT_TOPOLOGY_ARRAY2DCOMP
HitTopology hit_topology_plug_topDummyDims(HitPTopology *topo, int dims, int *virprocelems)
#define HIT_RANK_NULL_STATIC
#define hit_ranksCmp(a, b)
HitPTopology * hit_ptopDup(HitPTopology *in)
#define HIT_TOPOLOGY_PLAIN_POWER2
#define hit_topDims(topo)
HitRanks hit_topRanksInternal(HitTopology topo, int linealRank)
#define hit_mpiTestError(ok, cad)
#define HIT_TOPOLOGY_ARRAYDIMS
void hit_topFree(HitTopology topo)
HitTopology hit_topology_plug_topPlain(HitPTopology *topo)
#define hit_malloc(ptr, type, nmemb)
void hit_ptopFree(HitPTopology **in)
HitTopology hit_topology_plug_topArrayDims(HitPTopology *topo, int dims)
#define HIT_TOPOLOGY_PLAIN
int hit_topDimNeighbor(HitTopology topo, int dim, int shift)
int hit_topCard(HitTopology topo)
#define HIT_RANKS_NULL_STATIC
#define HIT_TOPOLOGY_SQUARE
HitTopology hit_topology_plug_topArray2DComplete(HitPTopology *topo)
HitTopology HIT_TOPOLOGY_NULL
#define HIT_TOPOLOGY_NULL_STATIC
#define hit_errInternal(routine, text, extraParam, file, numLine)