13
int rank; // unused, required by print0 in utils.h
15
void printUsage(char *prgname)
17
print0("Usage: %s N M dim1 ... dimN np1 ... npN\n"
18
" N Number of dimensions\n"
19
" M Number of processes\n"
20
" dim1..dimN Dimensions\n"
21
" np1..npN list of decomposition numbers e.g. 32 8 4\n"
22
" Decomposition values in each dimension of an array\n"
23
" The product of these number must be less then the number\n"
24
" of processes. Processes whose rank is higher than the\n"
25
" product, will not write anything.\n"
26
" Arrays with less dimensions than the number of values,\n"
27
" will be decomposed with using the appropriate number of\n"
32
int processArgs(int argc, char ** argv)
43
ndim = strtol(argv[1], &end, 10);
44
if (errno || (end != 0 && *end != '\0')) {
45
print0 ("ERROR: Invalid decomposition number in argument 1: '%s'\n", argv[j]);
51
nproc = strtol(argv[2], &end, 10);
52
if (errno || (end != 0 && *end != '\0')) {
53
print0 ("ERROR: Invalid decomposition number in argument 2: '%s'\n", argv[j]);
58
if (argc != 3+2*ndim) {
59
print0 ("ERROR: Expected number of arguments is %d\n", 2*ndim+2);
64
dims = (uint64_t*) malloc (sizeof(uint64_t) * ndim);
65
np = (int*) malloc (sizeof(int) * ndim);
69
for (nd=0; nd < ndim; nd++) { // get ndim dimensions
71
dims[nd] = strtoll(argv[j], &end, 10);
72
if (errno || (end != 0 && *end != '\0')) {
73
print0 ("ERROR: Invalid decomposition number in argument %d: '%s'\n",
81
for (nd=0; nd < ndim; nd++) { // get ndim decomposition values
83
np[nd] = strtoll(argv[j], &end, 10);
84
if (errno || (end != 0 && *end != '\0')) {
85
print0 ("ERROR: Invalid decomposition number in argument %d: '%s'\n",
94
for (i=0; i<ndim; i++) {
99
print0 ("ERROR: Product of decomposition numbers %d > number of processes %d\n",
108
int main (int argc, char ** argv)
111
uint64_t count[10], start[10], totalsize;
114
if (processArgs(argc, argv))
117
print("# of proc: %d\n", nproc);
118
ints_to_str(ndim, np, ints);
119
print("decomposition: %s\n", ints);
121
for (nd = ndim; nd > 0; nd--)
123
int64s_to_str(nd, dims, ints);
124
print("--------------------------------------------\n");
125
print("%d dimensions: %s\n", nd, ints);
126
for (i=0; i<nproc; i++) {
127
decompose (nproc, i, nd, dims, np, count, start, &totalsize);