1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
/*
* ADIOS is freely available under the terms of the BSD license described
* in the COPYING file in the top level directory of this source distribution.
*
* Copyright (c) 2008 - 2009. UT-BATTELLE, LLC. All rights reserved.
*/
/* ADIOS C Query Example write part:
* write a few global array from a single processor
* to be queried using query_table.c
*
* How to run: write_table
* Output: table.bp
* ADIOS config file: None
*
*/
/* This example will write out a 2D table like particle data,
where each row is data of one particle, and
each column is a property of the particles.
It's completely fake data with integer values for demonstration.
*/
#ifndef _NOMPI
#define _NOMPI
#endif
#include <stdio.h>
#include <string.h>
#include "adios.h"
#include "adios_types.h"
#include "adios_query.h" // to ask about availability of ALACRITY
#ifdef DMALLOC
#include "dmalloc.h"
#endif
/* table for Atoms, named A.
unique ID
element type (C, O, N etc)
potential
kinetic energy
position X,Y and Z
Note: This is not some data with any physical meaning...
*/
const int NX = 10;
const int NY = 7;
float A[10][7] = {
/* id, Elem, P, KE, x, y, z */
{0, 0, 97, 15, 8, 0, 7},
{1, 0, 96, 16, 5, -1, 7},
{2, 1, 32, 1, 7, 1, 7},
{3, 2, 200, 8, 6, 0, 7},
{4, 0, 94, 14, 1, 3, 5},
{5, 0, 96, 13, 2, 4, 5},
{6, 2, 201, 2, 3, 3, 5},
{7, 1, 37, 9, 4, 2, 5},
{8, 0, 98, 15, 5, 1, 5},
{9, 0, 99, 14, 6, 2, 5},
};
const int Columns_length = 11; /* length of string + 1 for the terminating 0 */
char Columns[7][11] = {
"ID ",
"Element ",
"Potential ",
"Kinetic E ",
"Position X",
"Position Y",
"Position Z",
};
const int n_of_elements = 3;
const int Elements_length = 9; /* length of string + 1 for the terminating 0 */
char Elements[3][9] = {
"Carbon ",
"Nitrogen",
"Oxygen "
};
int main (int argc, char ** argv)
{
MPI_Comm comm = 0; // dummy mpi
/* ADIOS variables declarations for matching gwrite_temperature.ch */
uint64_t adios_groupsize, adios_totalsize;
int64_t g;
int64_t f;
char dimstr[32];
adios_init_noxml (comm);
adios_set_max_buffer_size (1);
adios_declare_group (&g, "table", "", adios_stat_default);
adios_select_method (g, "POSIX", "", "");
sprintf (dimstr, "%d,%d", NX, NY);
int64_t varA = adios_define_var (g, "A" ,"", adios_real, dimstr, dimstr, "0,0");
adios_read_init_method(ADIOS_READ_METHOD_BP,0,"");
if (adios_query_is_method_available (ADIOS_QUERY_METHOD_ALACRITY)) {
adios_set_transform (varA, "alacrity");
printf ("Turned on ALACRITY transformation for table A\n");
}
sprintf (dimstr, "%d,%d", n_of_elements, Elements_length);
adios_define_var (g, "Elements" ,"", adios_byte, dimstr, dimstr, "0,0");
sprintf (dimstr, "%d,%d", NY, Columns_length);
adios_define_var (g, "Columns" ,"", adios_byte, dimstr, dimstr, "0,0");
adios_open (&f, "table", "table.bp", "w", comm);
adios_groupsize = NX*NY*sizeof(int32_t) /* size of A */
+ n_of_elements * Elements_length /* size of Elements */
+ NY * Columns_length; /* size of Columns */
adios_group_size (f, adios_groupsize, &adios_totalsize);
adios_write (f, "A", A);
adios_write (f, "Elements", Elements);
adios_write (f, "Columns", Columns);
adios_close (f);
adios_finalize (0);
return 0;
}
|