Read data from a file¶
ss_blob_read1 is a function defined in ssblob.c.
Synopsis:
-
void *
ss_blob_read1(ss_blob_t *blob, hsize_t offset, hsize_t nelmts, unsigned flags, ss_prop_t *props)¶
Formal Arguments:
blob: The blob from which data should be read.offset: Offset w.r.t. the blob’s data for the first element to be read.nelmts: Number of elements to be read from the blob’s data.flags: See theflagsargument of ss_blob_read.props: See *Blob Properties*.
Description: This is a convenience function for ss_blob_read when the blob’s data is scalar or one dimensional and
contiguous in the dataset. The offset and SIZE describe the part of the blob’s data to be read and are in
terms of elements with respect to the blob’s data (not necessarily the whole dataset).
Return Value: Same as ss_blob_read.
Parallel Notes: Same as ss_blob_read.
Example: The examples here are similar to those given for ss_blob_read and show that it’s much easier to use the special case functions for single dimension blobs.
Example 1: A single task reads all of the blob’s data into a static buffer. We assume that the dataset
contains 100 elements of an integer datatype. SSlib will convert the data from the file datatype to an int
type in memory.
1 2 3 4 | ss_blob_t b = SS_RELATION(rel)->d_blob;
int data[100];
ss_blob_bind_m1(&b, data, H5T_NATIVE_INT, 100); // bind memory to the blob
ss_blob_read1(&b, 0, 100, SS_BLOB_UNBIND, NULL); // read data into the buffer
|
Example 2: All tasks read all data collectively (they could also do it independently as when the above example is executed by every task, but that could be very inefficient since SSlib and lower layers cannot recognize that collective optimizations are possible).
1 2 3 4 5 | ss_blob_t b = SS_RELATION(rel)->d_blob;
int data[100];
ss_blob_bind_m1(&b, data, H5T_NATIVE_INT, 100); // bind memory to the blob
ss_blob_read1(&b, 0, 100, SS_BLOB_COLLECTIVE, NULL); // read data into the buffer
ss_blob_bind_m1(&b, NULL, 0, 0); // unbind the buffer just to be safe
|
Example 3: Each task reads 50 non-overlapping task-rank-order elements from a blob that was associated with a relation. Each task provides a buffer for the result. We assume that the blob’s data is one dimensional, a floating-point datatype, and of sufficient size to satisfy the read request.
1 2 3 | int self = ...; // task rank in blob's file communicator
float *buffer=NULL; // the result buffer to be allocated by ss_blob_read1()
buffer = ss_blob_read1(blob, 50*self, 50, SS_BLOB_COLLECTIVE, NULL); // read part of the blob data
|
See Also:
- ss_blob_read: 15.14: Read data from a file
- I/O: Introduction for current chapter