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

« 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: 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
/* 
 
2
 * ADIOS is freely available under the terms of the BSD license described
 
3
 * in the COPYING file in the top level directory of this source distribution.
 
4
 *
 
5
 * Copyright (c) 2008 - 2009.  UT-BATTELLE, LLC. All rights reserved.
 
6
 */
 
7
 
 
8
/*************************************************************/
 
9
/*          Example of reading arrays in ADIOS               */
 
10
/*    which were written from the same number of processors  */
 
11
/*                                                           */
 
12
/*        Similar example is manual/2_adios_read.c           */
 
13
/*************************************************************/
 
14
#include <stdio.h>
 
15
#include <stdlib.h>
 
16
#include <stdint.h>
 
17
#include <string.h>
 
18
#include "mpi.h"
 
19
#include "adios.h"
 
20
#include "public/adios_read.h"
 
21
 
 
22
int main (int argc, char ** argv) 
 
23
{
 
24
    char        filename [256];
 
25
    int         rank, size, i, j;
 
26
    int         NX, NY; 
 
27
    double      *t;
 
28
    MPI_Comm    comm = MPI_COMM_WORLD;
 
29
 
 
30
    int         adios_err;
 
31
    int64_t     adios_handle, adios_buf_size;
 
32
 
 
33
    MPI_Init (&argc, &argv);
 
34
    MPI_Comm_rank (comm, &rank);
 
35
 
 
36
    adios_read_init_method(ADIOS_READ_METHOD_FLEXPATH, comm, "");
 
37
 
 
38
    ADIOS_SELECTION global_range_select;
 
39
    //if(rank == 0){
 
40
    global_range_select.type=ADIOS_SELECTION_BOUNDINGBOX;
 
41
    global_range_select.u.bb.start = malloc(sizeof(uint64_t)*2);
 
42
    global_range_select.u.bb.count = malloc(sizeof(uint64_t)*2);
 
43
    (global_range_select.u.bb.start)[0] = rank;
 
44
    (global_range_select.u.bb.count)[0] = 1;
 
45
    (global_range_select.u.bb.start)[1] = 0;
 
46
    (global_range_select.u.bb.count)[1] = 40;
 
47
    global_range_select.u.bb.ndim = 2;
 
48
 
 
49
    ADIOS_SELECTION scalar_block_select;
 
50
    scalar_block_select.type = ADIOS_SELECTION_WRITEBLOCK;
 
51
    scalar_block_select.u.block.index = rank;
 
52
    //fprintf(stderr, "app got here\n");
 
53
    /* schedule_read of a scalar. */    
 
54
    int test_scalar = -1;
 
55
    ADIOS_FILE* afile = adios_read_open("arrays", 
 
56
                                         ADIOS_READ_METHOD_FLEXPATH, 
 
57
                                         comm,
 
58
                                         ADIOS_LOCKMODE_NONE, 0.0);
 
59
    
 
60
    int ii = 0;
 
61
    while(adios_errno != err_end_of_stream){
 
62
        
 
63
        /* get a bounding box - rank 0 for now*/
 
64
        ADIOS_VARINFO* nx_info = adios_inq_var( afile, "NX");
 
65
        ADIOS_VARINFO* ny_info = adios_inq_var( afile, "NY");
 
66
 
 
67
        if(nx_info->value) {
 
68
            NX = *((int *)nx_info->value);
 
69
        }
 
70
        if(ny_info->value){
 
71
            NY= *((int*)ny_info->value);
 
72
        }
 
73
    
 
74
        //printf("\trank=%d: NX=%d\n", rank, NX);
 
75
        //printf("\trank=%d: NY=%d\n", rank, NY);
 
76
    
 
77
        /* Allocate space for the arrays */
 
78
        int nelem = 40;
 
79
        int arr_size = sizeof(double) * nelem;
 
80
        t = (double *) malloc (arr_size);
 
81
        memset(t, 0, arr_size);
 
82
        //fprintf(stderr, "t %p\n", t);
 
83
      
 
84
        /* Read the arrays */        
 
85
        adios_schedule_read (afile, 
 
86
                             &global_range_select, 
 
87
                             "var_2d_array", 
 
88
                             0, 1, t);
 
89
        adios_schedule_read (afile,
 
90
                             &scalar_block_select,
 
91
                             "test_scalar",
 
92
                             0, 1, &test_scalar);
 
93
 
 
94
        adios_perform_reads (afile, 1);                
 
95
    
 
96
        //sleep(20);
 
97
    
 
98
        printf("Rank=%d: test_scalar: %d step: %d, t[0,5+x] = [%6.2f", rank, test_scalar, ii, t[0]);
 
99
        for(j=0; j<nelem; j++) {
 
100
            printf(", %6.2f", t[j]);
 
101
        }
 
102
        printf("]\n");
 
103
        adios_release_step(afile);
 
104
        adios_advance_step(afile, 0, 30);
 
105
        ii++;
 
106
        //MPI_Barrier (comm);
 
107
        //sleep(1);
 
108
    }
 
109
    //
 
110
    adios_read_close(afile);
 
111
 
 
112
    adios_read_finalize_method(ADIOS_READ_METHOD_FLEXPATH);
 
113
 
 
114
    //MPI_Finalize ();
 
115
 
 
116
    return 0;
 
117
}