#include "definitions.h" #include "Attribute.h" #include "MPIFS.h" #include "string.h" extern MPIFS *MPIFS_global_obj; extern "C" { int IOwriteAttribute(IOFile,char*,int,int,void *); int IOsizeOf(int); int IOreadAttributeInfo(IOFile,char*,int*,int*); int IOreadAttribute(IOFile,int,void*); // IOFile IEEEopen(char *,char *); } Attribute::Attribute() { name_ = NULL; data_status_ = 0; data_ = NULL; } void Attribute::init(char *name) { int i, len = strlen(name); name_ = (char *)malloc(sizeof(char) * (len + 1)); for (i=0; inode_type(); IOFile fp; if (node_type == PART_TIME_COMPUTE || node_type == COMPUTE_NODE) { if (MPIFS_global_obj->am_master_compute_node()) { init(n); MPIFS_global_obj->send_attr_schema(this, fname, READ_TIMESTEP); } MPIFS_global_obj->receive_attr_data(this); } else { // PART_TIME_IO init(n); if (MPIFS_global_obj->am_master_compute_node()) MPIFS_global_obj->send_attr_schema(this, fname, READ_TIMESTEP); MPIFS_global_obj->receive_attr_schema(); int i, len = strlen(fname); char *name = (char *)malloc(sizeof(char) * (len+1)); char *name1 = (char *)malloc(sizeof(char) * (len+16)); for (i=0; iapp_size(IO_NODE) > 1) { sprintf(name1, "%s.file_%d.ieee", name, MPIFS_global_obj->my_rank(IO_NODE)); } else { sprintf(name1, "%s.ieee", name); } fp = MPIFS_global_obj->open_file(name1, READ_TIMESTEP); read_data(fp); if (MPIFS_global_obj->am_master_io_node()) { MPIFS_global_obj->send_attr_data(this); } MPIFS_global_obj->receive_attr_data(this); free(name); } } void Attribute::write(char *fname, char *n, int esize, int count, void *data) { int node_type = MPIFS_global_obj->node_type(); if (node_type == PART_TIME_COMPUTE || node_type == COMPUTE_NODE) { if (MPIFS_global_obj->am_master_compute_node()) { init(n, esize, count, data); MPIFS_global_obj->send_attr_schema(this, fname, TIMESTEP); } } else { // PART_TIME_IO init(n, esize, count, data); if (MPIFS_global_obj->am_master_compute_node()) MPIFS_global_obj->send_attr_schema(this, fname, TIMESTEP); MPIFS_global_obj->receive_attr_schema(); IOFile fp; int i, len = strlen(fname); char *name = (char *)malloc(sizeof(char) * (len+1)); char *name1 = (char *)malloc(sizeof(char) * (len+16)); for (i=0; iapp_size(IO_NODE) > 1) { sprintf(name1, "%s.file_%d.ieee", name, MPIFS_global_obj->my_rank(IO_NODE)); } else { sprintf(name1, "%s.ieee", name); } fp = MPIFS_global_obj->open_file(name1, TIMESTEP); write_data(fp); free(name); } } void Attribute::write_data(IOFile fp) { IOwriteAttribute(fp, name_, esize_, count_, data_); } void Attribute::read_data(IOFile fp) { int index = IOreadAttributeInfo(fp, name_, &esize_, &count_); if (index >= 0) { data_ = (void *)malloc(IOsizeOf(esize_) * count_); IOreadAttribute(fp, index, data_); } else printf("Fail to read attribute %s\n", name_); } void *Attribute::get_data_ptr() { return data_; } void Attribute::set_data_ptr(void *d) { data_ = d; } int Attribute::data_size() { return IOsizeOf(esize_) * count_; } int Attribute::esize() { return esize_; } int Attribute::count() { return count_; } void Attribute::set_count(int c) { count_ = c; } void Attribute::set_esize(int e) { esize_ = e; }