1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-11-10 07:55:35 +00:00

Explicit error message instead of infinite loop in GlobalSharedMemory::GetShmDims

This commit is contained in:
Christoph Lehner 2020-06-02 07:44:38 -04:00
parent 8358ee38c4
commit 9fcb47ee63

View File

@ -170,17 +170,24 @@ void GlobalSharedMemory::GetShmDims(const Coordinate &WorldDims,Coordinate &ShmD
std::vector<int> primes({2,3,5}); std::vector<int> primes({2,3,5});
int dim = 0; int dim = 0;
int last_dim = ndimension - 1;
int AutoShmSize = 1; int AutoShmSize = 1;
while(AutoShmSize != WorldShmSize) { while(AutoShmSize != WorldShmSize) {
for(int p=0;p<primes.size();p++) { int p;
for(p=0;p<primes.size();p++) {
int prime=primes[p]; int prime=primes[p];
if ( divides(prime,WorldDims[dim]/ShmDims[dim]) if ( divides(prime,WorldDims[dim]/ShmDims[dim])
&& divides(prime,WorldShmSize/AutoShmSize) ) { && divides(prime,WorldShmSize/AutoShmSize) ) {
AutoShmSize*=prime; AutoShmSize*=prime;
ShmDims[dim]*=prime; ShmDims[dim]*=prime;
last_dim = (dim + ndimension - 1) % ndimension;
break; break;
} }
} }
if (p == primes.size() && last_dim == dim) {
std::cerr << "GlobalSharedMemory::GetShmDims failed" << std::endl;
exit(EXIT_FAILURE);
}
dim=(dim+1) %ndimension; dim=(dim+1) %ndimension;
} }
} }