def setUp(self): self.temp = TempFile() ad.init_noxml() ad.allocate_buffer(ad.BUFFER_ALLOC_WHEN.NOW, 10) g = ad.declare_group("temperature", "", ad.FLAG.YES) ad.define_var(g, "NX", "", ad.DATATYPE.integer, "", "", "") ad.define_var(g, "size", "", ad.DATATYPE.integer, "", "", "") ad.define_var(g, "temperature", "", ad.DATATYPE.double, "size,NX", "size,NX", "0,0") self.msg = "this is a test" ad.define_attribute(g, "desc", "", ad.DATATYPE.string, self.msg, "") ad.select_method(g, "POSIX1", "verbose=3", "") for i in range(5): mode = "a" if i == 0: mode = "w" fd = ad.open("temperature", self.temp.path, mode) self.NX = 10 self.size = 2 groupsize = 4 + 4 + 8 * self.size * self.NX t = np.array(range(self.NX * self.size), dtype=np.float64) + 100 * i self.tt = t.reshape((self.size, self.NX)) ad.set_group_size(fd, groupsize) ad.write_int(fd, "NX", self.NX) ad.write_int(fd, "size", self.size) ad.write(fd, "temperature", self.tt) ad.close(fd) ad.finalize() self.f = ad.file(self.temp.path)
def setUp(self): NX = 10 size = 2 t = np.array(range(NX*size), dtype=np.float64) tt = t.reshape((size, NX)) self.temp = TempFile() ad.init_noxml() ad.allocate_buffer (ad.BUFFER_ALLOC_WHEN.NOW, 10); fw = ad.writer(self.temp.path) fw.declare_group('group', method='POSIX1') fw['NX'] = NX fw['size'] = size fw['temperature'] = tt fw.attrs['/temperature/description'] = "Global array written from 'size' processes" fw.attrs["/someSubGroup/anOtherGroup/anOtherAttribute"] = 99 fw["/someSubGroup/anOtherGroup/anOtherVariable"] = 77 fw.close() ad.finalize() self.f = ad.file(self.temp.path)
def setUp(self): self.temp = TempFile() ad.init_noxml() ad.allocate_buffer(ad.BUFFER_ALLOC_WHEN.NOW, 10) g = ad.declare_group("temperature", "", ad.FLAG.YES) ad.define_var(g, "NX", "", ad.DATATYPE.integer, "", "", "") ad.define_var(g, "size", "", ad.DATATYPE.integer, "", "", "") ad.define_var(g, "temperature", "", ad.DATATYPE.double, "size,NX", "size,NX", "0,0") self.msg = "this is a test" self.unit = "C" ## attr must be <varpath> + / + something without / (line 857, common_read.c) ad.define_attribute(g, "temperature/desc", "", ad.DATATYPE.string, self.msg, "") ad.define_attribute(g, "temperature/unit", "", ad.DATATYPE.string, self.unit, "") ad.select_method(g, "POSIX1", "verbose=3", "") fd = ad.open("temperature", self.temp.path, "w") self.NX = 10 self.size = 2 groupsize = 4 + 4 + 8 * self.size * self.NX t = np.array(range(self.NX * self.size), dtype=np.float64) self.tt = t.reshape((self.size, self.NX)) ad.set_group_size(fd, groupsize) ad.write_int(fd, "NX", self.NX) ad.write_int(fd, "size", self.size) ad.write(fd, "temperature", self.tt) ad.close(fd) ad.finalize() self.f = ad.file(self.temp.path)
def setUp(self): self.temp = TempFile() ad.init_noxml() ad.allocate_buffer (ad.BUFFER_ALLOC_WHEN.NOW, 10); g = ad.declare_group("temperature", "", ad.FLAG.YES) ad.define_var(g, "NX", "", ad.DATATYPE.integer, "", "", "") ad.define_var(g, "size", "", ad.DATATYPE.integer, "", "", "") ad.define_var(g, "temperature", "", ad.DATATYPE.double, "size,NX", "size,NX", "0,0") ad.define_var(g, "temperature", "", ad.DATATYPE.double, "size,NX", "size,NX", "0,0") self.msg = "this is a test" ad.define_attribute(g, "desc", "", ad.DATATYPE.string, self.msg, "") ad.define_attribute(g, "temperature/unit", "", ad.DATATYPE.string, "C", "") ad.define_attribute(g, "temperature/desc", "", ad.DATATYPE.string, "description", "") ad.define_attribute(g, "/subgroup/subsubgroup/otherattr", "", ad.DATATYPE.string, "another", "") ad.define_var(g, "/subgroup/subsubgroup/othervar", "", ad.DATATYPE.integer, "", "", "") ad.select_method(g, "POSIX1", "verbose=3", "") fd = ad.open("temperature", self.temp.path, "w") self.NX = 10 self.size = 2 groupsize = 4 + 4 + 8 * self.size * self.NX + 4 t = np.array(range(self.NX * self.size), dtype=np.float64) self.tt = t.reshape((self.size, self.NX)) ad.set_group_size(fd, groupsize) ad.write_int(fd, "NX", self.NX) ad.write_int(fd, "size", self.size) ad.write(fd, "temperature", self.tt) ad.write_int(fd, "/subgroup/subsubgroup/othervar", 99) ad.close(fd) ad.finalize() self.f = ad.file(self.temp.path)
def setUp(self): self.temp = TempFile() ad.init_noxml() ad.allocate_buffer (ad.BUFFER_ALLOC_WHEN.NOW, 10); g = ad.declare_group("temperature", "", ad.FLAG.YES) ad.define_var(g, "NX", "", ad.DATATYPE.integer, "", "", "") ad.define_var(g, "size", "", ad.DATATYPE.integer, "", "", "") ad.define_var(g, "temperature", "", ad.DATATYPE.double, "size,NX", "size,NX", "0,0") self.msg = "this is a test" self.unit = "C" ## attr must be <varpath> + / + something without / (line 857, common_read.c) ad.define_attribute(g, "temperature/desc", "", ad.DATATYPE.string, self.msg, "") ad.define_attribute(g, "temperature/unit", "", ad.DATATYPE.string, self.unit, "") ad.select_method(g, "POSIX1", "verbose=3", "") fd = ad.open("temperature", self.temp.path, "w") self.NX = 10 self.size = 2 groupsize = 4 + 4 + 8 * self.size * self.NX t = np.array(range(self.NX * self.size), dtype=np.float64) self.tt = t.reshape((self.size, self.NX)) ad.set_group_size(fd, groupsize) ad.write_int(fd, "NX", self.NX) ad.write_int(fd, "size", self.size) ad.write(fd, "temperature", self.tt) ad.close(fd) ad.finalize() self.f = ad.file(self.temp.path)
def write(self, msg): doid = msg['doid'] column = msg['column'] rows = msg['rows'] shape = msg['shape'] rowid = msg['row'] datatype = msg['datatype'] data = msg['data'] filename = self.filepath + '/' + doid dimension = [rows] + copy.copy(shape) global_dimension = copy.copy(dimension) global_dimension[0] = self.maxrows offset = [0] * len(dimension) offset[0] = rowid ad.init_noxml() ad.allocate_buffer(ad.BUFFER_ALLOC_WHEN.NOW, self.buffersize) adios_group = ad.declare_group("shore", "", ad.FLAG.YES) local_dimension = str(dimension)[1:-1] global_dimension = str(global_dimension)[1:-1] offset = str(offset)[1:-1] ad.select_method(adios_group, "POSIX", "", "") ad.define_var(adios_group, column, "", self.dtype_numpy2adios[datatype], local_dimension, global_dimension, offset) adios_file = ad.open("shore", filename, 'u') group_size = 1000000 if data.nbytes > group_size: group_size = data.nbytes ad.set_group_size(adios_file, group_size) ad.write(adios_file, column, data, datatype) ad.close(adios_file) ad.finalize() return True
def write_scalar(self, adtype, val, varname='val'): ad.init_noxml() ad.allocate_buffer(ad.BUFFER_ALLOC_WHEN.NOW, 10) g = ad.declare_group("group", "", ad.FLAG.YES) ad.define_var(g, varname, "", adtype, "", "", "") ad.select_method(g, "POSIX1", "", "") if adtype == ad.DATATYPE.string: dtype = ad.adios2npdtype(adtype, len(str(val))) npval = np.array(val, dtype=dtype) else: dtype = ad.adios2npdtype(adtype) npval = np.array(val, dtype=dtype) fd = ad.open("group", self.temp.path, "w") ad.set_group_size(fd, npval.nbytes) ad.write(fd, varname, val, dtype) ad.close(fd) ad.finalize() f = ad.file(self.temp.path) v = f.vars['val'] self.assertEqual(v.read(), npval)
def write_scalar(self, adtype, val, varname='val'): ad.init_noxml() ad.allocate_buffer (ad.BUFFER_ALLOC_WHEN.NOW, 10); g = ad.declare_group("group", "", ad.FLAG.YES) ad.define_var(g, varname, "", adtype, "", "", "") ad.select_method(g, "POSIX1", "", "") if adtype == ad.DATATYPE.string: dtype = ad.adios2npdtype(adtype, len(str(val))) npval = np.array(val, dtype=dtype) else: dtype = ad.adios2npdtype(adtype) npval = np.array(val, dtype=dtype) fd = ad.open("group", self.temp.path, "w") ad.set_group_size(fd, npval.nbytes) ad.write(fd, varname, val, dtype) ad.close(fd) ad.finalize() f = ad.file(self.temp.path) v = f.vars['val'] self.assertEqual(v.read(), npval)
import numpy as np import getopt, sys import os method = "POSIX" init = "verbose=3;" if len(sys.argv) > 1: method = sys.argv[1] if len(sys.argv) > 2: init = sys.argv[2] ## Init ad.init_noxml() ad.allocate_buffer (ad.BUFFER_ALLOC_WHEN.NOW, 10); g = ad.declare_group("temperature", "", 1) ad.define_var(g, "NX", "", ad.DATATYPE.integer, "", "", "") ad.define_var(g, "size", "", ad.DATATYPE.integer, "", "", "") ad.define_var(g, "temperature", "", ad.DATATYPE.double, "size,NX", "size,NX", "0,0") ad.select_method(g, method, init, "") print ">>> Method:", method ## Writing for i in range(5): fd = ad.open("temperature", "temp.bp", "a") NX = 10 size = 2 groupsize = 4 + 4 + 8 * size * NX t = np.array(range(NX*size), dtype=np.float64) + 100*i
$ python ./test_adios_write.py """ import adios as ad import numpy as np print("\n>>> Prepare ...\n") fname = 'adios_test_writer.bp' NX = 10 size = 2 t = np.array(list(range(NX * size)), dtype=np.float64) tt = t.reshape((size, NX)) print("\n>>> Writing ...\n") ad.init_noxml() ad.allocate_buffer(ad.BUFFER_ALLOC_WHEN.NOW, 10) fw = ad.writer(fname) fw.declare_group('group', method='POSIX1') fw['NX'] = NX fw['size'] = size fw['temperature'] = tt fw.attrs[ '/temperature/description'] = "Global array written from 'size' processes" fw.close() ## Reading print("\n>>> Reading ...\n") f = ad.file(fname)
def setUp(self): ad.init_noxml() ad.allocate_buffer(ad.BUFFER_ALLOC_WHEN.NOW, 10)