108
114
char * parameters,
109
115
char * base_path)
117
cdef extern from "adios_selection.h":
118
ctypedef enum ADIOS_SELECTION_TYPE:
119
ADIOS_SELECTION_BOUNDINGBOX
120
ADIOS_SELECTION_POINTS
121
ADIOS_SELECTION_WRITEBLOCK
124
ctypedef struct ADIOS_SELECTION_BOUNDINGBOX_STRUCT:
129
ctypedef struct ADIOS_SELECTION_POINTS_STRUCT:
132
ctypedef struct ADIOS_SELECTION_WRITEBLOCK_STRUCT:
135
ctypedef struct ADIOS_SELECTION_AUTO_STRUCT:
138
cdef union ADIOS_SELECTION_UNION:
139
ADIOS_SELECTION_BOUNDINGBOX_STRUCT bb
140
ADIOS_SELECTION_POINTS_STRUCT points
141
ADIOS_SELECTION_WRITEBLOCK_STRUCT block
142
ADIOS_SELECTION_AUTO_STRUCT autosel
144
ctypedef struct ADIOS_SELECTION:
145
ADIOS_SELECTION_TYPE type
146
ADIOS_SELECTION_UNION u
148
cdef ADIOS_SELECTION * adios_selection_boundingbox (int ndim,
149
const uint64_t *start,
150
const uint64_t *count)
111
152
cdef extern from "adios_read.h":
112
ctypedef struct MPI_Comm:
153
ctypedef enum ADIOS_READ_METHOD:
155
ADIOS_READ_METHOD_BP_AGGREGATE
158
ctypedef enum ADIOS_LOCKMODE:
160
ADIOS_LOCKMODE_CURRENT
115
163
ctypedef struct ADIOS_FILE:
168
char ** attr_namelist
170
char ** mesh_namelist
123
176
uint64_t file_size
125
char ** group_namelist
128
ctypedef struct ADIOS_GROUP:
134
char ** attr_namelist
139
178
ctypedef struct ADIOS_VARINFO:
146
int characteristics_count
158
cdef ADIOS_FILE * adios_fopen (char *, MPI_Comm)
159
cdef int adios_fclose (ADIOS_FILE *)
161
cdef ADIOS_GROUP * adios_gopen (ADIOS_FILE *, char *)
162
cdef ADIOS_GROUP * adios_gopen_byid (ADIOS_FILE *, int)
163
cdef int adios_gclose (ADIOS_GROUP *)
165
cdef ADIOS_VARINFO * adios_inq_var (ADIOS_GROUP *, char *)
166
cdef ADIOS_VARINFO * adios_inq_var_byid (ADIOS_GROUP *, int)
167
cdef void adios_free_varinfo(ADIOS_VARINFO *)
168
cdef int64_t adios_read_var_byid (ADIOS_GROUP *, int,
169
uint64_t *, uint64_t *,
172
cdef char * adios_errmsg()
180
class DATATYPE(object):
188
cdef int adios_read_init_method (ADIOS_READ_METHOD method,
191
cdef int adios_read_finalize_method(ADIOS_READ_METHOD method)
192
cdef ADIOS_FILE * adios_read_open (const char * fname,
193
ADIOS_READ_METHOD method,
195
ADIOS_LOCKMODE lock_mode,
197
cdef ADIOS_FILE * adios_read_open_file (const char * fname,
198
ADIOS_READ_METHOD method,
200
cdef int adios_read_close (ADIOS_FILE *fp)
201
cdef int adios_advance_step (ADIOS_FILE *fp, int last, float timeout_sec)
202
cdef void adios_release_step (ADIOS_FILE *fp)
203
cdef ADIOS_VARINFO * adios_inq_var (ADIOS_FILE *fp, const char * varname)
204
cdef ADIOS_VARINFO * adios_inq_var_byid (ADIOS_FILE *fp, int varid)
205
cdef void adios_free_varinfo (ADIOS_VARINFO *cp)
206
cdef int adios_schedule_read (const ADIOS_FILE * fp,
207
const ADIOS_SELECTION * sel,
208
const char * varname,
212
cdef int adios_schedule_read_byid (const ADIOS_FILE * fp,
213
const ADIOS_SELECTION * sel,
218
cdef int adios_perform_reads (const ADIOS_FILE *fp, int blocking)
221
## ====================
222
## ADIOS Enum (public)
223
## ====================
354
cpdef int np2adiostype(np.dtype t):
356
if t.type == np.float64:
357
atype = DATATYPE.double
364
cdef printAdiosFile(ADIOS_FILE * f):
398
cdef printfile(ADIOS_FILE * f):
365
399
print '%15s : %lu' % ('fh', f.fh)
366
print '%15s : %d' % ('groups_count', f.groups_count)
367
print '%15s : %d' % ('vars_count', f.vars_count)
368
print '%15s : %d' % ('attrs_count', f.attrs_count)
369
print '%15s : %d' % ('tidx_start', f.tidx_start)
370
print '%15s : %d' % ('ntimesteps', f.ntimesteps)
371
print '%15s : %d' % ('version', f.version)
400
print '%15s : %d' % ('nvars', f.nvars)
401
print '%15s : %s' % ('var_namelist', [f.var_namelist[i] for i in range(f.nvars)])
402
print '%15s : %d' % ('nattrs', f.nattrs)
403
print '%15s : %s' % ('attr_namelist', [f.attr_namelist[i] for i in range(f.nattrs)])
404
print '%15s : %d' % ('current_step', f.current_step)
405
print '%15s : %d' % ('last_step', f.last_step)
406
print '%15s : %s' % ('path', f.path)
407
print '%15s : %d' % ('endianness', f.endianness)
408
print '%15s : %d' % ('version', f.version)
372
409
print '%15s : %lu' % ('file_size', f.file_size)
373
print '%15s : %d' % ('endianness', f.endianness)
374
print '%15s : %s' % ('group_namelist', [f.group_namelist[i] for i in range(f.groups_count)])
376
cdef printAdiosGroup(ADIOS_GROUP * g):
377
print '%15s : %lu' % ('gh', g.gh)
378
print '%15s : %d' % ('grpid', g.grpid)
379
print '%15s : %d' % ('vars_count', g.vars_count)
380
print '%15s : %s' % ('var_namelist', [g.var_namelist[i] for i in range(g.vars_count)])
381
print '%15s : %d' % ('attrs_count', g.attrs_count)
382
print '%15s : %s' % ('attr_namelist', [g.attr_namelist[i] for i in range(g.attrs_count)])
383
print '%15s : %lu' % ('fp', <unsigned long> g.fp)
385
cdef printAdiosVariable(ADIOS_VARINFO * v):
386
print '%15s : %d' % ('grpid', v.grpid)
411
cdef printvar(ADIOS_VARINFO * v):
387
412
print '%15s : %d' % ('varid', v.varid)
388
413
print '%15s : %s' % ('type', adios2nptype(v.type))
389
414
print '%15s : %d' % ('ndim', v.ndim)
390
415
print '%15s : %s' % ('dims', [v.dims[i] for i in range(v.ndim)])
391
print '%15s : %d' % ('timedim', v.timedim)
393
cdef adios2scalar(ADIOS_DATATYPES t, void * val):
395
return (<char *> val)[0]
396
elif t == adios_short:
397
return (<short *> val)[0]
398
elif t == adios_integer:
399
return (<int *> val)[0]
400
elif t == adios_long:
401
return (<long *> val)[0]
402
elif t == adios_unsigned_byte:
403
return (<unsigned char *> val)[0]
404
elif t == adios_unsigned_short:
405
return (<unsigned short *> val)[0]
406
elif t == adios_unsigned_integer:
407
return (<unsigned int *> val)[0]
408
elif t == adios_unsigned_long:
409
return (<unsigned long *> val)[0]
410
elif t == adios_real:
411
return (<float *> val)[0]
412
elif t == adios_double:
413
return (<double *> val)[0]
414
elif t == adios_long_double:
415
return (<long double *> val)[0]
420
## ADIOS Class Definition
423
cdef class AdiosFile:
416
print '%15s : %d' % ('nsteps', v.nsteps)
418
## ====================
419
## ADIOS Class Definitions for Read
420
## ====================
422
cpdef read_init(ADIOS_READ_METHOD method = ADIOS_READ_METHOD_BP,
423
MPI_Comm comm = MPI_COMM_WORLD,
424
char * parameters = ""):
425
return adios_read_init_method (method, comm, parameters)
428
cpdef read_finalize(ADIOS_READ_METHOD method = ADIOS_READ_METHOD_BP):
429
return adios_read_finalize_method (method)
424
432
""" Private Memeber """
425
433
cpdef ADIOS_FILE * fp
427
435
""" Public Memeber """
428
436
cpdef public bytes name
429
cpdef public int groups_count
430
cpdef public int vars_count
431
cpdef public int attrs_count
432
cpdef public int tidx_start
433
cpdef public int ntimesteps
437
cpdef public int nvars
438
cpdef public int nattrs
439
cpdef public int current_step
440
cpdef public int last_step
441
cpdef public int endianness
434
442
cpdef public int version
435
443
cpdef public int file_size
436
cpdef public int endianness
438
cpdef public dict group
440
def __init__(self, char * fname, MPI.Comm comm = MPI.COMM_WORLD):
445
cpdef public dict var
446
cpdef public dict attr
448
def __init__(self, char * fname,
449
ADIOS_READ_METHOD method = ADIOS_READ_METHOD_BP,
450
MPI_Comm comm = MPI_COMM_WORLD):
444
self.fp = adios_fopen(fname, comm.ob_mpi)
455
self.fp = adios_read_open_file(fname, method, comm)
445
456
assert self.fp != NULL, 'Not an open file'
447
self.name = fname.split('/')[-1] ## basename
448
self.groups_count = self.fp.groups_count
449
self.vars_count = self.fp.vars_count
450
self.attrs_count = self.fp.attrs_count
451
self.tidx_start = self.fp.tidx_start
452
self.ntimesteps = self.fp.ntimesteps
453
self.version = self.fp.version
454
self.file_size = self.fp.file_size
455
self.endianness = self.fp.endianness
458
self.name = fname.split('/')[-1] ## basename
459
self.nvars = self.fp.nvars
460
self.nattrs = self.fp.nattrs
461
self.current_step = self.fp.current_step
462
self.last_step = self.fp.last_step
463
self.endianness = self.fp.endianness
464
self.version = self.fp.version
465
self.file_size = self.fp.file_size
458
for grpname in [self.fp.group_namelist[i] for i in range(self.groups_count)]:
459
g = AdiosGroup(self, grpname)
460
self.group[grpname] = g
467
for varname in [self.fp.var_namelist[i] for i in range(self.nvars)]:
468
self.var[varname] = var(self, varname)
462
470
def __del__(self):
465
473
cpdef close(self):
466
474
assert self.fp != NULL, 'Not an open file'
467
for g in self.group.values():
469
adios_fclose(self.fp)
475
adios_read_close(self.fp)
472
478
cpdef printself(self):
473
479
assert self.fp != NULL, 'Not an open file'
474
480
print '=== AdiosFile ==='
475
481
print '%15s : %lu' % ('fp', <unsigned long> self.fp)
476
printAdiosFile(self.fp)
479
cdef class AdiosGroup:
480
""" Private Memeber """
482
cdef ADIOS_GROUP * gp
484
""" Public Memeber """
485
cpdef public bytes name
486
cpdef public int grpid
487
cpdef public int vars_count
488
cpdef public int attrs_count
489
cpdef public int timestep
490
cpdef public int lasttimestep
492
cpdef public dict var
494
def __init__(self, AdiosFile file, char * name):
498
self.gp = adios_gopen(self.file.fp, name)
499
assert self.gp != NULL, 'Not an open group'
502
self.grpid = self.gp.grpid
503
self.vars_count = self.gp.vars_count
504
self.attrs_count = self.gp.attrs_count
505
self.timestep = self.gp.timestep
506
self.lasttimestep = self.gp.lasttimestep
509
for varname in [self.gp.var_namelist[i] for i in range(self.vars_count)]:
510
v = AdiosVariable(self, varname)
511
self.var[varname] = v
517
assert self.gp != NULL, 'Not an open file'
518
for v in self.var.values():
520
adios_gclose(self.gp)
523
cpdef printself(self):
524
assert self.gp != NULL, 'Not an open file'
525
print '=== AdiosGroup ==='
526
print '%15s : %lu' % ('gp', <unsigned long> self.gp)
527
printAdiosGroup(self.gp)
529
cdef class AdiosVariable:
530
""" Private Memeber """
531
cdef AdiosGroup group
485
""" Private Memeber """
532
487
cdef ADIOS_VARINFO * vp
534
489
""" Public Memeber """
537
492
cpdef public type type
538
493
cpdef public int ndim
539
494
cpdef public tuple dims
540
cpdef public int timedim
541
cpdef public int characteristics_count
543
def __init__(self, AdiosGroup group, char * name):
495
cpdef public int nsteps
497
def __init__(self, file file, char * name):
547
self.vp = adios_inq_var(self.group.gp, name)
548
assert self.group.gp != NULL, 'Not an open group'
501
assert self.file.fp != NULL, 'Not an open file'
502
self.vp = adios_inq_var(self.file.fp, name)
503
assert self.vp != NULL, 'Not a valid var'
551
self.varid = self.vp.varid
552
self.type = adios2nptype(self.vp.type)
553
self.ndim = self.vp.ndim
554
self.timedim = self.vp.timedim
555
self.characteristics_count = self.vp.characteristics_count
506
self.varid = self.vp.varid
507
self.type = adios2nptype(self.vp.type)
508
self.ndim = self.vp.ndim
557
509
self.dims = tuple([self.vp.dims[i] for i in range(self.vp.ndim)])
510
self.nsteps = self.vp.nsteps
559
512
def __del__(self):
562
515
cpdef close(self):
563
assert self.vp != NULL, 'Not an open file'
516
assert self.vp != NULL, 'Not an open var'
564
517
adios_free_varinfo(self.vp)
567
cpdef read(self, tuple offset = (), tuple count = ()):
568
cdef type ntype = adios2nptype(self.vp.type)
569
assert ntype is not None, 'Data type is not supported yet'
520
cpdef read(self, tuple offset = (), tuple count = (), from_steps = 0, nsteps = 1):
521
assert self.type is not None, 'Data type is not supported yet'
522
assert from_steps + nsteps <= self.nsteps, 'Step index is out of range'
571
524
cdef list lshape = [self.vp.dims[i] for i in range(self.vp.ndim)]
572
525
cdef np.ndarray npshape = np.array(lshape, dtype=np.int64)
587
540
assert npshape.ndim == npoffset.ndim, 'Offset dimension mismatch'
588
541
assert npshape.ndim == npcount.ndim, 'Count dimension mismatch.'
589
assert (npshape - npoffset > npcount).all(), 'Count is larger than shape.'
591
cdef np.ndarray var = np.zeros(npcount, dtype=ntype)
592
cdef int64_t nbytes = adios_read_var_byid(
595
<uint64_t *> npoffset.data,
596
<uint64_t *> npcount.data,
601
print "[WARNING] bytes read :", nbytes
542
assert (npshape - npoffset >= npcount).all(), 'Count is larger than shape.'
544
shape = list(npcount)
546
shape.insert(0, nsteps)
547
cdef np.ndarray var = np.zeros(shape, dtype=self.type)
549
cdef ADIOS_SELECTION * sel
550
sel = adios_selection_boundingbox (self.vp.ndim, <uint64_t *> npoffset.data, <uint64_t *> npcount.data)
552
adios_schedule_read_byid (self.file.fp, sel, self.vp.varid, from_steps, nsteps, <void *> var.data)
553
adios_perform_reads(self.file.fp, 1)
605
557
""" Print self """
606
558
cpdef printself(self):
607
assert self.vp != NULL, 'Not an open file'
559
assert self.vp != NULL, 'Not an open variable'
608
560
print '=== AdiosVariable ==='
609
561
print '%15s : %lu' % ('vp', <unsigned long> self.vp)
610
printAdiosVariable(self.vp)
562
print '%15s : %lu' % ('fp', <unsigned long> self.file.fp)
565
## ====================
566
## ADIOS Global functions
567
## ====================
569
def readvar(fname, varname):
571
if not f.var.has_key(varname):
572
print "No valid variable"
576
return v.read(from_steps=0, nsteps=v.nsteps)
580
return {'nvars': f.nvars,
582
'vars': tuple([ k for k in f.var.iterkeys() ]),
583
'attrs': tuple([ k for k in f.attr.iterkeys() ]),
584
'time_steps': (f.current_step, f.last_step),
585
'file_size': f.file_size}