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

« back to all changes in this revision

Viewing changes to examples/C/schema/structured.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: write a variable along with a structured mesh. 
 
9
 * Note that the mesh dimensions depend on the rank.
 
10
*/
 
11
#include <stdio.h>
 
12
#include <string.h>
 
13
#include "mpi.h"
 
14
#include "adios.h"
 
15
int main (int argc, char * argv[] ) 
 
16
{
 
17
    char        filename[]="structured.bp";
 
18
    int         rank, size, i, j;
 
19
    int         NX = 10;  
 
20
    double      t[NX], mean = 0;
 
21
    MPI_Comm    comm = MPI_COMM_WORLD;
 
22
    char      * str = "Jul, 2012";
 
23
    int         nspace=2;
 
24
 
 
25
    int         adios_err;
 
26
    uint64_t    adios_groupsize, adios_totalsize;
 
27
    int64_t     adios_handle;
 
28
 
 
29
    MPI_Init (&argc, &argv);
 
30
    MPI_Comm_rank (comm, &rank);
 
31
    MPI_Comm_size (comm, &size);
 
32
 
 
33
    float       X[size*NX];
 
34
    float       Y[size][NX];
 
35
    float       XY[2*size*NX];
 
36
    int         size2 = 2*size*NX;
 
37
    int idx = 0;
 
38
    for (i = 0; i< size; i++)
 
39
    {
 
40
        for (j=0; j<NX; j++)
 
41
        {
 
42
            X[idx] = i + j;
 
43
            Y[i][j] = i - j;
 
44
            XY[2*idx] = X[idx];
 
45
            XY[2*idx+1]=Y[i][j];
 
46
            idx++;
 
47
        }
 
48
    }
 
49
   
 
50
    for (i = 0; i< NX; i++) {
 
51
        t[i] = i+rank;
 
52
    }
 
53
    mean /= NX;
 
54
 
 
55
    adios_init ("structured.xml", comm);
 
56
 
 
57
    adios_open (&adios_handle, "schema", filename, "w", comm);
 
58
 
 
59
    adios_groupsize = 4 \
 
60
                      + 4 \
 
61
                + 4 \
 
62
                + 4 \
 
63
                + strlen(str) \
 
64
                + sizeof(float) * (size) * (NX) \
 
65
                + sizeof(float) * (size) * (NX) \
 
66
                + sizeof(double) * (NX);
 
67
    adios_group_size (adios_handle, adios_groupsize, &adios_totalsize);
 
68
    adios_write (adios_handle, "NX", &NX);
 
69
    adios_write (adios_handle, "size", &size);
 
70
    //adios_write (adios_handle, "size2", &size2);
 
71
    adios_write (adios_handle, "rank", &rank);
 
72
    //adios_write (adios_handle, "mean", &mean);
 
73
    //adios_write (adios_handle, "nspace", &nspace);
 
74
    adios_write (adios_handle, "X", X);
 
75
    adios_write (adios_handle, "Y", Y);
 
76
    //adios_write (adios_handle, "XY",  XY);
 
77
    //adios_write (adios_handle, "date", str);
 
78
    adios_write (adios_handle, "temperature", t);
 
79
 
 
80
    adios_close (adios_handle);
 
81
 
 
82
    MPI_Barrier (comm);
 
83
 
 
84
    adios_finalize (rank);
 
85
 
 
86
    MPI_Finalize ();
 
87
 
 
88
    return 0;
 
89
}