~ubuntu-branches/ubuntu/utopic/adios/utopic

« back to all changes in this revision

Viewing changes to examples/staging/stage_write/test_decompose.c

  • Committer: Package Import Robot
  • Author(s): Alastair McKinstry
  • Date: 2013-12-09 15:21:31 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20131209152131-jtd4fpmdv3xnunnm
Tags: 1.5.0-1
* New upstream.
* Standards-Version: 3.9.5
* Include latest config.{sub,guess} 
* New watch file.
* Create libadios-bin for binaries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
#include <string.h>
 
4
#include <unistd.h>
 
5
#include <errno.h>
 
6
 
 
7
#include "decompose.h"
 
8
#include "utils.h"
 
9
 
 
10
int ndim, nproc;
 
11
uint64_t *dims;
 
12
int *np;
 
13
int rank; // unused, required by print0 in utils.h
 
14
 
 
15
void printUsage(char *prgname)
 
16
{
 
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"
 
28
           "            values.\n"
 
29
        ,prgname);
 
30
}
 
31
 
 
32
int processArgs(int argc, char ** argv)
 
33
{   
 
34
    int i, j, nd, prod; 
 
35
    char *end;
 
36
 
 
37
    if (argc < 3) {
 
38
        printUsage (argv[0]);
 
39
        return 1;
 
40
    }
 
41
 
 
42
    errno = 0;
 
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]);
 
46
        printUsage(argv[0]);
 
47
        return 1;
 
48
    }
 
49
 
 
50
    errno = 0;
 
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]);
 
54
        printUsage(argv[0]);
 
55
        return 1;
 
56
    }
 
57
 
 
58
    if (argc != 3+2*ndim) {
 
59
        print0 ("ERROR: Expected number of arguments is %d\n", 2*ndim+2);
 
60
        printUsage (argv[0]);
 
61
        return 1;
 
62
    }
 
63
    
 
64
    dims = (uint64_t*) malloc (sizeof(uint64_t) * ndim);
 
65
    np   = (int*) malloc (sizeof(int) * ndim);
 
66
 
 
67
    nd = 0;
 
68
    j = 3;
 
69
    for (nd=0; nd < ndim; nd++) { // get ndim dimensions
 
70
        errno = 0;
 
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",
 
74
                    j, argv[j]);
 
75
            printUsage(argv[0]);
 
76
            return 1;
 
77
        }
 
78
        j++;
 
79
    }
 
80
 
 
81
    for (nd=0; nd < ndim; nd++) { // get ndim decomposition values
 
82
        errno = 0;
 
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",
 
86
                    j, argv[j]);
 
87
            printUsage(argv[0]);
 
88
            return 1;
 
89
        }
 
90
        j++;
 
91
    }
 
92
 
 
93
    prod = 1;
 
94
    for (i=0; i<ndim; i++) {
 
95
        prod *= np[i];
 
96
    }
 
97
 
 
98
    if (prod > nproc) {
 
99
        print0 ("ERROR: Product of decomposition numbers %d > number of processes %d\n",
 
100
                prod, nproc);
 
101
        printUsage(argv[0]);
 
102
        return 1;
 
103
    }
 
104
 
 
105
    return 0;
 
106
}
 
107
 
 
108
int main (int argc, char ** argv)
 
109
{
 
110
    char ints[256];
 
111
    uint64_t count[10], start[10], totalsize;
 
112
    int i, nd;
 
113
 
 
114
    if (processArgs(argc, argv)) 
 
115
        return 1;
 
116
 
 
117
    print("# of proc: %d\n", nproc);
 
118
    ints_to_str(ndim, np, ints);
 
119
    print("decomposition: %s\n", ints);
 
120
 
 
121
    for (nd = ndim; nd > 0; nd--)
 
122
    {
 
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);
 
128
        }
 
129
    }
 
130
 
 
131
    return 0;
 
132
}
 
133
 
 
134