~ubuntu-branches/ubuntu/vivid/adios/vivid-proposed

« back to all changes in this revision

Viewing changes to examples/C/flexpath_arrays/global_range_select/arrays_read.c

  • Committer: Package Import Robot
  • Author(s): Alastair McKinstry
  • Date: 2014-06-16 23:06:38 UTC
  • mfrom: (15.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20140616230638-cxryhot6b8ge32l6
Tags: 1.7.0-1
* New upstream release.
* Add adios.pc pkgconfig file. adios_config now uses this.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include "adios.h"
20
20
#include "public/adios_read.h"
21
21
 
 
22
 
 
23
void
 
24
slice(uint64_t length, uint64_t *s, uint64_t *e, int rank, int mpisize)
 
25
{
 
26
    uint64_t start = 0;
 
27
    uint64_t end = 0;
 
28
    uint64_t rem = length % mpisize;
 
29
 
 
30
    start = length/mpisize * rank;
 
31
    end = length/mpisize * (rank+1);
 
32
    *s = start;
 
33
    *e = end;
 
34
    
 
35
    /* If our MPI size is greater
 
36
       than the number of y dimensions,
 
37
       then read the whole thing. */
 
38
    if (mpisize > length) {
 
39
        *e = length;
 
40
        *s = 0;
 
41
        return;\
 
42
    }
 
43
    if (end > length) {
 
44
        end = length;
 
45
        *e = end;
 
46
        return;
 
47
    }
 
48
    if (rank == mpisize-1) {
 
49
        end += rem;
 
50
        *e = end;
 
51
    }
 
52
}
 
53
 
 
54
 
22
55
int main (int argc, char ** argv) 
23
56
{
24
 
    char        filename [256];
25
 
    int         rank, size, i, j;
26
 
    int         NX, NY; 
 
57
    int         rank, size, j;
 
58
    int         NX, NY, NZ; 
27
59
    double      *t;
28
60
    MPI_Comm    comm = MPI_COMM_WORLD;
29
61
 
30
 
    int         adios_err;
31
 
    int64_t     adios_handle, adios_buf_size;
32
 
 
33
62
    MPI_Init (&argc, &argv);
34
63
    MPI_Comm_rank (comm, &rank);
 
64
    MPI_Comm_size (comm, &size);
35
65
 
36
66
    adios_read_init_method(ADIOS_READ_METHOD_FLEXPATH, comm, "");
37
67
 
39
69
 
40
70
    ADIOS_SELECTION scalar_block_select;
41
71
    scalar_block_select.type = ADIOS_SELECTION_WRITEBLOCK;
42
 
    scalar_block_select.u.block.index = rank;
 
72
    scalar_block_select.u.block.index = 0;
43
73
 
44
74
    /* schedule_read of a scalar. */    
45
75
    int test_scalar = -1;
48
78
                                        comm,
49
79
                                        ADIOS_LOCKMODE_NONE, 0.0);
50
80
 
 
81
    int i;
51
82
    /* for(i=0; i<afile->nvars; i++){ */
52
83
    /*  printf("var: %s\n", afile->var_namelist[i]); */
53
84
    /* } */
55
86
    int ii = 0;
56
87
    while(adios_errno != err_end_of_stream){       
57
88
        /* get a bounding box - rank 0 for now*/
58
 
        ADIOS_VARINFO *nx_info = adios_inq_var( afile, "scalar/dim/NX");
59
 
        ADIOS_VARINFO *ny_info = adios_inq_var( afile, "scalar/dim/NY");
 
89
        ADIOS_VARINFO *nx_info = adios_inq_var(afile, "/scalar/dim/NX");
 
90
        ADIOS_VARINFO *ny_info = adios_inq_var(afile, "/scalar/dim/NY");
 
91
        ADIOS_VARINFO *nz_info = adios_inq_var(afile, "/scalar/dim/NZ");
 
92
 
60
93
        ADIOS_VARINFO *size_info = adios_inq_var( afile, "size");
61
94
        ADIOS_VARINFO *arry = adios_inq_var( afile, "var_2d_array");
62
95
 
64
97
        int ny_val = *((int*)ny_info->value);
65
98
        int size_val = *((int*)size_info->value);
66
99
 
67
 
        printf("nx: %d, ny: %d, size: %d\n", nx_val, ny_val, size);
 
100
        //printf("nx: %d, ny: %d, size: %d\n", nx_val, ny_val, size_val);
68
101
        
 
102
        // slice array along y dimension
 
103
        uint64_t my_ystart, my_yend, my_ycount;
 
104
        slice(arry->dims[1], &my_ystart, &my_yend, rank, size);
 
105
 
 
106
        /* printf("rank: %d my_ystart: %d, my_yend: %d\n", */
 
107
        /*        rank, (int)my_ystart, (int)my_yend); */
 
108
 
69
109
        uint64_t xcount = arry->dims[0];
70
 
        uint64_t ycount = arry->dims[1];
71
 
 
72
 
        uint64_t starts[] = {0,0};
73
 
        uint64_t counts[] = {xcount, ycount};
74
 
 
75
 
        global_range_select = adios_selection_boundingbox(2, starts, counts);
76
 
 
77
 
        int nelem = xcount*ycount;
 
110
        uint64_t ycount = my_yend - my_ystart;
 
111
        uint64_t zcount = arry->dims[2];
 
112
 
 
113
        uint64_t starts[] = {0, my_ystart, 0};
 
114
        uint64_t counts[] = {xcount, ycount, zcount};
 
115
 
 
116
        /* printf("rank: %d starts: %d %d %d. counts: %d %d %d\n", */
 
117
        /*        rank, */
 
118
        /*        (int)starts[0], (int)starts[1], (int)starts[2], */
 
119
        /*        (int)counts[0], (int)counts[1], (int)counts[2]); */
 
120
 
 
121
        global_range_select = adios_selection_boundingbox(arry->ndim, starts, counts);
 
122
 
 
123
        int nelem = xcount*ycount*zcount;
78
124
 
79
125
        if(nx_info->value) {
80
126
            NX = *((int *)nx_info->value);
82
128
        if(ny_info->value){
83
129
            NY= *((int*)ny_info->value);
84
130
        }
 
131
        if(nz_info->value){
 
132
            NZ= *((int*)nz_info->value);
 
133
        }
85
134
    
86
135
        if(rank == 0){
87
136
            int n;