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

« back to all changes in this revision

Viewing changes to examples/C/global-array/read_no_xml_write_byid.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
/* ADIOS C Example: read global arrays from a BP file
 
9
 *
 
10
 * This code is using the generic read API, which can read in
 
11
 * arbitrary slices of an array and thus we can read in an array
 
12
 * on arbitrary number of processes (provided our code is smart 
 
13
 * enough to do the domain decomposition).
 
14
 *
 
15
 * Run this example after adios_global, which generates 
 
16
 * adios_global.bp. Run this example on equal or less 
 
17
 * number of processes since we decompose only on one 
 
18
 * dimension of the global array here. 
 
19
*/
 
20
#include <stdio.h>
 
21
#include <stdlib.h>
 
22
#include <string.h>
 
23
#include <unistd.h>
 
24
#include "mpi.h"
 
25
#include "adios_read.h"
 
26
 
 
27
int main (int argc, char ** argv) 
 
28
{
 
29
    char        filename [256];
 
30
    int         rank, size, i, j, npl, token;
 
31
    MPI_Comm    comm = MPI_COMM_WORLD;
 
32
    MPI_Status  status;
 
33
    enum ADIOS_READ_METHOD method = ADIOS_READ_METHOD_BP;
 
34
    ADIOS_SELECTION * sel;
 
35
    void * data = NULL;
 
36
    uint64_t start[1], count[1], bytes_read = 0;
 
37
 
 
38
    MPI_Init (&argc, &argv);
 
39
    MPI_Comm_rank (comm, &rank);
 
40
    MPI_Comm_size (comm, &size);
 
41
 
 
42
    adios_read_init_method (method, comm, "verbose=3");
 
43
 
 
44
    ADIOS_FILE * f = adios_read_open ("no_xml_write_byid.bp", method, 
 
45
                                      comm, ADIOS_LOCKMODE_NONE, 0);
 
46
    if (f == NULL)
 
47
    {
 
48
        printf ("%s\n", adios_errmsg());
 
49
        return -1;
 
50
    }
 
51
 
 
52
    ADIOS_VARINFO * v = adios_inq_var (f, "temperature");
 
53
 
 
54
    /* Using less readers to read the global array back, i.e., non-uniform */
 
55
    uint64_t slice_size = v->dims[0]/size;
 
56
    start[0] = slice_size * rank;
 
57
    if (rank == size-1) /* last rank may read more lines */
 
58
        slice_size = slice_size + v->dims[0]%size;
 
59
    count[0] = slice_size;
 
60
 
 
61
    data = malloc (slice_size * sizeof (double));
 
62
    if (data == NULL)
 
63
    {
 
64
        fprintf (stderr, "malloc failed.\n");
 
65
        return -1;
 
66
    }
 
67
 
 
68
    /* Read a subset of the temperature array */
 
69
    sel = adios_selection_boundingbox (v->ndim, start, count);
 
70
    adios_schedule_read (f, sel, "temperature", 0, 1, data);
 
71
    adios_perform_reads (f, 1);
 
72
 
 
73
    if (rank > 0) {
 
74
        MPI_Recv (&token, 1, MPI_INT, rank-1, 0, comm, &status);
 
75
    }
 
76
 
 
77
    printf (" ======== Rank %d ========== \n", rank);
 
78
    npl = 10;
 
79
    for (i = 0; i < slice_size; i+=npl) {
 
80
        printf ("[%4.4d]  ", rank*slice_size+i);
 
81
        for (j= 0; j < npl; j++) {
 
82
            printf (" %6.6g", * ((double *)data + i + j));
 
83
        }
 
84
        printf ("\n");
 
85
    }
 
86
    fflush(stdout);
 
87
    sleep(1);
 
88
 
 
89
    if (rank < size-1) {
 
90
        MPI_Send (&token, 1, MPI_INT, rank+1, 0, comm);
 
91
    }
 
92
 
 
93
 
 
94
    free (data);
 
95
 
 
96
    adios_read_close (f);
 
97
    MPI_Barrier (comm);
 
98
    adios_read_finalize_method (method);
 
99
    MPI_Finalize ();
 
100
    return 0;
 
101
}