예제 #1
0
void onBox(int rank, ADIOS_FILE* f, ADIOS_VARINFO* v, int timestep, uint64_t* start, uint64_t* count,  FastBitDataType ft)
{
  int i=0;
  
  char selName[100];
  sprintf(selName, "box-%lu", start[0]);


  uint64_t totalCount = 1;
  for (i = 0; i<v->ndim; i++) {
      totalCount *= count[i];
  }

  double* data = (double *) calloc (totalCount, sizeof (double));

  uint64_t currStart = 0;

  ADIOS_SELECTION* boxSel = adios_selection_boundingbox(v->ndim, start, count);
  
  int err = adios_schedule_read_byid(f, boxSel, v->varid, timestep, 1, data);

  if (!err) {	
    err = adios_perform_reads(f, 1);
  }    
  
  processData(data, totalCount, rank, timestep, selName, ft, v);

} // on box
예제 #2
0
void adios_checkpoint_verify_variables(ADIOS_FILE* fp, const char* name, unsigned long origin)
{
  ADIOS_VARINFO *vi;
  int count = 1;
  int size;
  vi = adios_inq_var(fp, name);
  if (vi->ndim > 0)
  {
    cout<<name<<" verification not passed, not a scalar"<<endl;
    return;
  }
  size = count*adios_type_size(vi->type, vi->value);
  unsigned long* mem= (unsigned long* )malloc(size);
  adios_schedule_read(fp, NULL, name, 0, 1, mem);
  adios_perform_reads(fp, 1);
  if(mem[0] == origin)
  {
    cout<<name<<" verification passed"<<mem[0]<<endl;
  }
  else
  {
    cout<<name<<" verification not passed, readin: "<<mem[0]<<" writeout: "<<origin<<endl;
  }
  adios_free_varinfo (vi);
  free(mem);
}
예제 #3
0
int read_file (char *fname)
{
    ADIOS_SELECTION *sel;
    ADIOS_FILE * f;
    ADIOS_VARINFO * vi;
    int err=0,i,n;

    uint64_t start[1] = {0};
    uint64_t count[2] = {NX};
    uint64_t ndim;

    reset_rarrays();

    log ("Read and check data in %s\n", fname);
    f = adios_read_open_file (fname, ADIOS_READ_METHOD_BP, comm);
    if (f == NULL) {
        printE ("Error at opening file: %s\n", adios_errmsg());
        return 1;
    }

    sel = adios_selection_boundingbox (1, start, count);
    adios_schedule_read (f, sel, "t1", 0, 1, r1);
    adios_schedule_read (f, sel, "t2", 0, 1, r2);
    adios_perform_reads (f, 1);
    adios_selection_delete (sel);

    CHECK_ARRAY (t, r1, NX);
    CHECK_ARRAY (t, r2, NX);

endread:
    adios_read_close(f);
    MPI_Barrier (comm);
    return err;
}
예제 #4
0
void adios_checkpoint_verify_variables(ADIOS_FILE* fp, const char* name, RealType* origin)
{
  ADIOS_VARINFO *vi;
  int count = 1;
  int size;
  vi = adios_inq_var(fp, name);
  adios_inq_var_blockinfo (fp, vi);
  if (vi->ndim > 0)
  {
    count*=vi->dims[0];
    for (int j = 1; j < vi->ndim; j++)
    {
      count *= vi->dims[j];
    }
  }
  size = count*adios_type_size(vi->type, vi->value);
  RealType *mem= (RealType *)malloc(size);
  adios_schedule_read(fp, NULL, name, 0, 1, mem);
  adios_perform_reads(fp, 1);
  for(int i=0; i<count; i++)
  {
    if(mem[i] == origin[i])
    {
      cout<<name<<"["<<i<<"]verification passed "<<mem[i]<<endl;
    }
    else
    {
      cout<<name<<"["<<i<<"]verification not passed, readin: "<<mem[i]<<" writeout: "<<origin[i]<<endl;
    }
  }
  adios_free_varinfo (vi);
  free(mem);
}
예제 #5
0
int read_write(int step)
{
    int retval = 0;
    int i;
    uint64_t total_size;

    // open output file
    adios_open (&fh, group_namelist[0], outfilename, (step==1 ? "w" : "a"), comm);
    adios_group_size (fh, write_total, &total_size);
    
    for (i=0; i<f->nvars; i++) 
    {
        if (varinfo[i].writesize != 0) {
            // read variable subset
            print ("rank %d: Read variable %d: %s\n", rank, i, f->var_namelist[i]); 
            ADIOS_SELECTION *sel = adios_selection_boundingbox (varinfo[i].v->ndim,
                    varinfo[i].start, 
                    varinfo[i].count);
            adios_schedule_read_byid (f, sel, i, 1, 1, readbuf);
            adios_perform_reads (f, 1);   


            // write (buffer) variable
            print ("rank %d: Write variable %d: %s\n", rank, i, f->var_namelist[i]); 
            adios_write(fh, f->var_namelist[i], readbuf);
        }
    }

    adios_release_step (f); // this step is no longer needed to be locked in staging area
    adios_close (fh); // write out output buffer to file
    return retval;
}
예제 #6
0
eavlField *
eavlXGCImporter::GetField(const string &name, const string &mesh, int chunk)
{
    map<string, ADIOS_VARINFO*>::const_iterator it = variables.find(name);
    if (it == variables.end())
	THROW(eavlException, string("Variable not found: ")+name);

    uint64_t s[3], c[3];
    ADIOS_SELECTION *sel = MakeSelection(it->second, s, c);
    int nt = 1;
    for (int i = 0; i < it->second->ndim; i++)
	nt *= c[i];
    double *buff = new double[nt];
    adios_schedule_read_byid(fp, sel, it->second->varid, 0, 1, buff);
    int retval = adios_perform_reads(fp, 1);
    adios_selection_delete(sel);

    eavlFloatArray *arr = new eavlFloatArray(name, 1);
    arr->SetNumberOfTuples(nt);
    for (int i = 0; i < nt; i++)
	arr->SetComponentFromDouble(i, 0, buff[i]);
    delete [] buff;

    eavlField *field = new eavlField(1, arr, eavlField::ASSOC_POINTS);
    //field->PrintSummary(cout);
    return field;
}
예제 #7
0
// k is numbered from 1 to sum_nblocks
void verifyData(ADIOS_FILE* f, ADIOS_VARINFO* v, int k, int timestep) 
{
  uint64_t blockBytes = adios_type_size (v->type, v->value);
  int j=0;

  if (v->ndim <= 0) {
    return;
  }

  //printf("verify block[%d]: ", k);
  
      for (j=0; j<v->ndim; j++) 
      {  
	  blockBytes *= v->blockinfo[k].count[j];
	  //printf("%" PRIu64 ":%" PRIu64 " ", v->blockinfo[k].start[j], v->blockinfo[k].count[j]);
      }

      void* data = NULL;
      data = malloc(blockBytes);  
      ADIOS_SELECTION* sel =  adios_selection_boundingbox (v->ndim, v->blockinfo[k].start, v->blockinfo[k].count);
      int err = adios_schedule_read_byid(f, sel, v->varid, timestep, 1, data);      
      if (!err) {	
	   err = adios_perform_reads(f, 1);
      }
      //fastbit_adios_util_printData(data, v->type, blockBytes/adios_type_size(v->type, v->value));
      adios_selection_delete(sel);
      free(data);	 
      data = NULL;
}
예제 #8
0
void adios_checkpoint_verify_variables(ADIOS_FILE* fp, const char* name, int* origin)
{
  ADIOS_VARINFO *vi;
  int count = 1;
  int size;
  vi = adios_inq_var(fp, name);
  if (vi->ndim > 0)
  {
    cout<<name<<" verification not passed, not a scalar"<<endl;
    return;
  }
  size = count*adios_type_size(vi->type, vi->value);
  int * mem= (int * )malloc(size);
  ADIOS_SELECTION *sel = adios_selection_writeblock(OHMMS::Controller->rank());
  adios_schedule_read(fp, sel, name, 0, 1, mem);
  //adios_schedule_read(fp, NULL, name, 0, 1, mem);
  adios_perform_reads(fp, 1);
  if(mem[0] == *origin)
  {
    cout<<name<<" verification passed "<<mem[0]<<endl;
  }
  else
  {
    cout<<name<<" verification not passed, readin: "<<mem[0]<<" writeout: "<<*origin<<endl;
  }
  adios_free_varinfo (vi);
  adios_selection_delete(sel);
  free(mem);
}
예제 #9
0
/// Read a sub-array.
///
/// @Note The length of the buffer is assumed to be sufficiently large
/// if the argument bufLen is less or equal to 0.  The caller is
/// responsible for allocating the buffer (@c buf) of the currect size.
int64_t
ADIOS_Var::readData(void* buf, int64_t bufLen,
                    const uint64_t* start,
                    const uint64_t* count)
{
    uint64_t total_elm = 1;
    for (int i=0; i<getNumDimension(); i++) {
        total_elm *= count[i];
#ifdef DEBUG
        LOGGER(ibis::gVerbose > 5)
            << "ADIOS_Var::readData: [" << i << "] start=" << start[i]
            << ", count=" << count[i];
#endif
    }
    {
        uint64_t total_bytes = total_elm *
            adios_type_size(getType(), readValue());
        if (bufLen > 0 && (uint64_t)bufLen < total_bytes) {
            LOGGER(ibis::gVerbose > 0)
                << "Warning -- ADIOS_Var::readData: bufLen (" << bufLen
                << ") < total_bytes (" << total_bytes << ")";
            return -1;
        }
    }
    ADIOS_SELECTION *sel = adios_selection_boundingbox
        (m_handle->ndim, start, count);
    if (sel == 0) {
        LOGGER(ibis::gVerbose > 1)
            << "Warning -- ADIOS_Var::readData failed to create a selection";
        return -2;
    }

    IBIS_BLOCK_GUARD(adios_selection_delete, sel);
    int ierr = adios_schedule_read_byid
        (getFile(), sel, index(), getFile()->current_step, 1, buf);
    if (ierr != 0) {
        LOGGER(ibis::gVerbose > 0)
            << "Warning -- ADIOS_Var::readData call to "
            "adios_schedule_read_byid failed due to " << adios_errmsg();
        return -3;
    }

    ierr = adios_perform_reads(getFile(), 1); // 1 == blocking
    if (ierr != 0) {
        LOGGER(ibis::gVerbose > 0)
            << "Warning -- ADIOS_Var::readData call to adios_perform_reads on "
            << getFileName() << " failed due to " << adios_errmsg();
        return -4;
    }
    LOGGER(ibis::gVerbose > 5)
        << "ADIOS_Var::readData: competeled reading " << total_elm
        << " element" << (total_elm>1?"s":"") << " for " << getName()
        << " from " << getFileName();
    return total_elm;
} // ADIOS_Var::readData
예제 #10
0
void adios_checkpoint_verify_random_variables(ADIOS_FILE* fp, const char* name, uint_type* origin)
{
  ADIOS_VARINFO *vi;
  int count_int = 1;
  int size;
  uint64_t *start;
  uint64_t *count;
  vi = adios_inq_var(fp, name);
  adios_inq_var_blockinfo (fp, vi);
  if (vi->ndim > 0)
  {
    start = (uint64_t *)malloc(vi->ndim * sizeof(uint64_t));
    count = (uint64_t *)malloc(vi->ndim * sizeof(uint64_t));
  }
  for (int j=0; j<vi->nblocks[0]; j++)
  {
    if(j == OHMMS::Controller->rank())
    {
      for (int k=0; k<vi->ndim; k++)
      {
        start[k] = vi->blockinfo[j].start[k];
        count[k] = vi->blockinfo[j].count[k];
        count_int *= count[k];
        //cout<<OHMMS::Controller->rank()<<" count "<<start[k]<<" "<<count[k]<<endl;
      }
    }
  }
  size = count_int*adios_type_size(vi->type, vi->value);
  uint_type *mem= (uint_type*)malloc(size);
  ADIOS_SELECTION *sel = adios_selection_boundingbox(vi->ndim, start, count);
  adios_schedule_read(fp, sel, name, 0, 1, mem);
  adios_perform_reads(fp, 1);
  int flag = 0;
  for(int i=0; i<count_int; i++)
  {
    if(mem[i] == origin[i])
    {
      //cout<<name<<"["<<i<<"]verification passed "<<mem[i]<<endl;
    }
    else
    {
      flag = 1;
      cout<<name<<"["<<i<<"]verification not passed, readin: "<<mem[i]<<" writeout: "<<origin[i]<<endl;
    }
  }
  if (flag == 0) cout<<name<<" verification passed "<<endl;
  else cout<<name<<" verification not passed "<<endl;
  adios_free_varinfo (vi);
  adios_selection_delete(sel);
  free(start);
  free(count);
  free(mem);
}
예제 #11
0
void onBlock(int rank, ADIOS_FILE* f, ADIOS_VARINFO* v, int i, int j, int blockCounter, FastBitDataType ft)
{
      char bmsVarName[100];
      char keyVarName[100];
      char offsetName[100];

      int64_t       var_ids_bms[v->nblocks[i]];
      int64_t       var_ids_key[v->nblocks[i]];
      int64_t       var_ids_offset[v->nblocks[i]];
             
      sprintf(bmsVarName, "bms-%d-%d-%d", v->varid, i, j);
      sprintf(keyVarName, "key-%d-%d-%d", v->varid, i, j);
      sprintf(offsetName, "offset-%d-%d-%d", v->varid, i, j);
      

      uint64_t blockSize = fastbit_adios_util_getBlockSize(v, i, j); 
      uint64_t blockDataByteSize = adios_type_size (v->type, v->value) * blockSize; 
      
      char notes[100];
      logTime(NULL); logTimeMillis(NULL);
      
      sprintf(notes, "  reading data from adios  on varid=%d, time=%d, block: %d, size=%ld bytes=%ld", v->varid, i, j, blockSize, blockDataByteSize);
      
      logTime(notes); logTimeMillis(notes);
      localtime(&indexRefresh);
      
      //printf("   %d th block / (%d), size= %" PRIu64 " bytes=%" PRIu64, j, blockSize, blockCounter, blockDataByteSize);
      
      void* data = malloc (blockDataByteSize);
      ADIOS_SELECTION* blockSel = adios_selection_writeblock(j);
      
      //adios_selcton_writeblock(num),  0 <= num <  nblocks[timestep]
      //ADIOS_SELECTION* blockSel = adios_selection_writeblock(blockCounter);
      int err = adios_schedule_read_byid(f, blockSel, v->varid, i, 1, data);
      if (!err) {	
	err = adios_perform_reads(f, 1);
      } else {
	printf("Unable to read block %d at timestep: %d \n", j, i);
	return;
	//break;
      }
      //fastbit_adios_util_printData(data, v->type, blockSize);

      char selName[20];
      sprintf(selName, "block-%d", j);
      processData(data, blockSize, rank, i, selName, ft, v);

      //processData(void* data, uint64_t dataCount, int rank, int timestep, char* selName, FastBitDataType ft, ADIOS_VARINFO* v)


      adios_selection_delete(blockSel);
      verifyData(f, v, blockCounter, i);
} // onblock
예제 #12
0
void ToolsAdiosParallel::convertToText()
{
    if(m_options.data.size() == 0)
        throw std::runtime_error("No datasets requested");

    for (size_t i = 0; i < m_options.data.size(); ++i)
    {
        ADIOS_VARINFO *pVarInfo;

        //get name of dataset to print
        std::string nodeName = m_options.data[i];

        uint8_t *P;
        int varElement = 1;
        int varTypeSize = 0;

        adios_read_init_method(ADIOS_READ_METHOD_BP, comm, nodeName.c_str());

        pVarInfo = adios_inq_var(pFile, nodeName.c_str());

        varTypeSize = adios_type_size(pVarInfo->type, NULL);

        // get number of elements combined in a dataset
        for(int j = 0; j < pVarInfo->ndim; j++)
        {
            varElement = varElement * pVarInfo->dims[j];
        }
        // allocate memory
        P = (uint8_t*) malloc (sizeof(uint8_t) * varTypeSize * varElement);

        adios_schedule_read(pFile, NULL, nodeName.c_str(), 0, 1, P);

        adios_perform_reads(pFile, 1);

        if(pVarInfo->ndim > 0)
        {        
            for(int k = 0; k < varElement; k++)
            {
                printValue(pVarInfo->type, &P[k*varTypeSize]);
            }
        }
        else
        {
            printValue(pVarInfo->type, pVarInfo->value);
        }
        adios_free_varinfo(pVarInfo);
    }
}
예제 #13
0
    /** Read the skalar field and optionally the attribute into the values referenced by the pointers */
    void operator()(ThreadParams& params,
                const std::string& name, T_Scalar* value,
                const std::string& attrName = "", T_Attribute* attribute = nullptr)
    {
        log<picLog::INPUT_OUTPUT> ("ADIOS: read %1%D scalars: %2%") % simDim % name;
        std::string datasetName = params.adiosBasePath + name;

        ADIOS_VARINFO* varInfo;
        ADIOS_CMD_EXPECT_NONNULL( varInfo = adios_inq_var(params.fp, datasetName.c_str()) );
        if(varInfo->ndim != simDim)
            throw std::runtime_error(std::string("Invalid dimensionality for ") + name);
        if(varInfo->type != traits::PICToAdios<T_Scalar>().type)
            throw std::runtime_error(std::string("Invalid type for ") + name);

        DataSpace<simDim> gridPos = Environment<simDim>::get().GridController().getPosition();
        uint64_t start[varInfo->ndim];
        uint64_t count[varInfo->ndim];
        for(int d = 0; d < varInfo->ndim; ++d)
        {
            /* \see adios_define_var: z,y,x in C-order */
            start[d] = gridPos.revert()[d];
            count[d] = 1;
        }

        ADIOS_SELECTION* fSel = adios_selection_boundingbox(varInfo->ndim, start, count);

        // avoid deadlock between not finished pmacc tasks and mpi calls in adios
        __getTransactionEvent().waitForFinished();

        /* specify what we want to read, but start reading at below at `adios_perform_reads` */
        /* magic parameters (0, 1): `from_step` (not used in streams), `nsteps` to read (must be 1 for stream) */
        log<picLog::INPUT_OUTPUT > ("ADIOS: Schedule read skalar %1%)") % datasetName;
        ADIOS_CMD( adios_schedule_read(params.fp, fSel, datasetName.c_str(), 0, 1, (void*)value) );

        /* start a blocking read of all scheduled variables */
        ADIOS_CMD( adios_perform_reads(params.fp, 1) );

        adios_selection_delete(fSel);
        adios_free_varinfo(varInfo);

        if(!attrName.empty())
        {
            log<picLog::INPUT_OUTPUT> ("ADIOS: read attribute %1% for scalars: %2%") % attrName % name;
            *attribute = readAttribute<T_Attribute>(params.fp, datasetName, attrName);
        }
    }
예제 #14
0
void AdiosCheckpointInput::performReads()
{
  for (int i = 0; i < read_queue.size(); i++)
  {
    const char* var_name = read_queue[i].c_str();
    //grab the information from the metadata about this variable
    ADIOS_VARINFO* adios_inq = adios_inq_var(adios_file_handle, var_name);
    //Calculate the total size of the vector based on the metadata
    uint64_t total_size = adios_type_size(adios_inq->type, NULL);
    for (int i = 0; i < adios_inq->ndim; i++)
      total_size *= adios_inq->dims[i];
    //allocate and then store for when retrieve
    void* buff = malloc(total_size);
    buffers.push_back(buff);
    //schedule the read
    adios_schedule_read(adios_file_handle, sel, var_name, 0, 1, buff);
    //Don't need the information about the variable anymore
    adios_free_varinfo(adios_inq);
  }
  //perform the read
  adios_perform_reads(adios_file_handle, 1);
}
예제 #15
0
void AdiosCheckpointInput::getVector(const std::string& var_name, vector<T>& buffer)
{
  ADIOS_VARINFO* adios_inq = adios_inq_var(adios_file_handle, var_name.c_str());
  //Check to make sure the T is the same size as the data type on the disk
  if (adios_type_size(adios_inq->type, NULL) != sizeof(T))
  {
    qmcplusplus::app_error() << "Data type does not match data type found in file: " << std::endl;
    APP_ABORT("qmcapp");
    return ;
  }
  uint64_t total_size = 1;
  for (int i = 0; i < adios_inq->ndim; i++)
    total_size *= adios_inq->dims[i];
  //make sure we have enough space to copy all the data from the file
  buffer.reserve(total_size);
  //schedule the read
  adios_schedule_read(adios_file_handle, sel, var_name.c_str(), 0, 1, &(buffer[0]));
  //perform the read
  adios_perform_reads(adios_file_handle, 1);
  //Don't need the information about the variable anymore
  adios_free_varinfo(adios_inq);
}
예제 #16
0
void adios_trace_verify_local_variables(ADIOS_FILE* fp, const char* name, double* origin)
{
  ADIOS_VARINFO *vi;
  int count = 1;
  unsigned long size = 1;
  vi = adios_inq_var(fp, name);
  adios_inq_var_blockinfo(fp, vi);
  for (int j=0; j<vi->nblocks[0]; j++)
  {
    if(OHMMS::Controller->rank() == j)
    {
      for (int k=0; k<vi->ndim; k++)
      {
        count *= vi->blockinfo[j].count[k];
      }
    }
  }
  size = count * adios_type_size(vi->type, vi->value);
  double* mem = (double*)malloc(size);
  ADIOS_SELECTION *sel = adios_selection_writeblock(OHMMS::Controller->rank());
  adios_schedule_read(fp, sel, name, 0, 1, mem);
  adios_perform_reads(fp, 1);
  int flag = 0;
  for(int i=0; i<count; i++)
  {
    if(mem[i] == origin[i])
    {
    }
    else
    {
      flag = 1;
      cout<<OHMMS::Controller->rank()<<" "<<name<<"["<<i<<"]verification not passed, readin: "<<mem[i]<<" writeout: "<<origin[i]<<endl;
    }
  }
  if(flag == 0) cout<<OHMMS::Controller->rank()<<" "<<name<<" verification passed"<<endl;
  adios_selection_delete(sel);
  adios_free_varinfo (vi);
  free(mem);
}
예제 #17
0
void onMultiBlock(int rank, ADIOS_FILE* f, ADIOS_VARINFO* v, int timestep, int blockStart,  int blockEnd, FastBitDataType ft)
{
  int i=0;
  
  char selName[100];
  sprintf(selName, "block-%d", blockStart, blockEnd);

  uint64_t blockSizeArray[blockEnd-blockStart];

  uint64_t totalCount = 0;
  for (i = blockStart; i< blockEnd; i++) {
      blockSizeArray[i-blockStart] = fastbit_adios_util_getBlockSize(v, timestep, i); 
      //totalBytes += blockSizeArray[i-blockStart] * adios_type_size (v->type, v->value);
      totalCount += blockSizeArray[i-blockStart];
  }

  //void* data = malloc (totalBytes);
  double* data = (double *) calloc (totalCount, sizeof (double));

  uint64_t currStart = 0;
  for (i = blockStart; i < blockEnd; i++) {
      ADIOS_SELECTION* blockSel = adios_selection_writeblock(i);
      
      int err = adios_schedule_read_byid(f, blockSel, v->varid, timestep, 1, &data[currStart]);
      currStart += blockSizeArray[i-blockStart];
      if (!err) {	
	err = adios_perform_reads(f, 1);
      } else {
	printf("Unable to read block %d at timestep: %d \n", i, timestep);
	return;
	//break;
      }
  }
  
  processData(data, totalCount, rank, timestep, selName, ft, v);
      //processData(void* data, uint64_t dataCount, int rank, int timestep, char* selName, FastBitDataType ft, ADIOS_VARINFO* v)

} // on multi block
예제 #18
0
파일: selections.c 프로젝트: acbauer/ADIOS
int read_points ()
{
    ADIOS_SELECTION *sel0,*sel1,*sel2,*sel3;
    ADIOS_FILE * f;
    ADIOS_VARINFO * vi;
    int err=0,n,n1, i,j,k;
    int nsteps_a, nsteps_b, nsteps_c;
    int v; 

    uint64_t *pts1;
    uint64_t *pts2;
    uint64_t *pts3;
    uint64_t start[3] = {offs1,offs2,offs3};
    uint64_t count[3] = {ldim1,ldim2,ldim3};
    
    pts1 = (uint64_t*) malloc (1*sizeof(uint64_t)*ldim1);
    pts2 = (uint64_t*) malloc (2*sizeof(uint64_t)*ldim1*ldim2);
    pts3 = (uint64_t*) malloc (3*sizeof(uint64_t)*ldim1*ldim2*ldim3);

    for (i=0; i<ldim1; i++) 
    {
        pts1[i] = offs1 + i;
        for (j=0; j<ldim2; j++) 
        {
            pts2[i*2*ldim2 + 2*j]   = offs1 + i;
            pts2[i*2*ldim2 + 2*j+1] = j; 
            for (k=0; k<ldim3; k++) 
            {
                pts3[i*3*ldim2*ldim3+j*3*ldim3+3*k]   = offs1 + i;
                pts3[i*3*ldim2*ldim3+j*3*ldim3+3*k+1] = j;
                pts3[i*3*ldim2*ldim3+j*3*ldim3+3*k+2] = k;
            }
        }
    }

    //Force error on very last point: pts3[3*ldim1*ldim2*ldim3-1] = 0;

    reset_readvars();

    log ("Read and check data in %s using point selections\n", FILENAME);
    f = adios_read_open (FILENAME, read_method, comm,
                         ADIOS_LOCKMODE_CURRENT, 0.0);
    if (f == NULL) {
        printE ("Error at opening file: %s\n", rank, adios_errmsg());
        return 1;
    }

    sel1 = adios_selection_points (1, ldim1, pts1); 
    sel2 = adios_selection_points (2, ldim1*ldim2, pts2); 
    sel3 = adios_selection_points (3, ldim1*ldim2*ldim3, pts3); 

#ifdef DEBUG_PRINTS
    fprintf(stderr, "1D selection: {");
    for (i=0; i<ldim1; i++) {
        fprintf (stderr, "%d ", i, i, pts1[i]);
    }
    fprintf(stderr, "}\n");

    fprintf(stderr, "2D selection :\n");
    for (i=0; i<ldim1; i++) {
        fprintf (stderr, "i=%d, idx=%2d- = ", i, i*2*ldim2);
        for (j=0; j<ldim2; j++) {
            n = i*2*ldim2+2*j;
            fprintf (stderr, "{%d,%d} ", pts2[n], pts2[n+1]); 
        }
        fprintf(stderr, "\n");
    }

    fprintf(stderr, "3D selection :\n");
    for (i=0; i<ldim1; i++) {
        for (j=0; j<ldim2; j++) {
            fprintf (stderr, "i=%d, j=%d, idx=%3d- = ", i, j, i*3*ldim2*ldim3+j*3*ldim3); 
            for (k=0; k<ldim3; k++) {
                n = i*3*ldim2*ldim3+j*3*ldim3+3*k;
                fprintf (stderr, "{%d,%d,%d} ", pts3[n], pts3[n+1], pts3[n+2]); 
            }
            fprintf(stderr, "\n");
        }
    }
#endif

    n1=0;
    while (n1 < NSTEPS && adios_errno != err_end_of_stream) {
        n1++;
        log ("  Step %d\n", f->current_step);


        log ("  Check 1D variable a1...\n");
        adios_schedule_read (f, sel1, "a1",  0, 1, r1);
        adios_perform_reads (f, 1);

#ifdef DEBUG_PRINTS
        fprintf(stderr, "1D result: {");
        for (i=0; i<ldim1; i++) {
            fprintf (stderr, "%d ", i, i, r1[i]);
        }
        fprintf(stderr, "}\n");
#endif

        for (i=0; i<ldim1; i++) {
            v = VALUE1D(rank,f->current_step,i);
            if (r1[i] != v) {
                printE ("Error: a1[%d]=%d  !=  read=%d\n", i, v, r1[i]); 
                //goto endread;
            }
        }



        log ("  Check 2D variable a2...\n");
        adios_schedule_read (f, sel2, "a2",  0, 1, r2);
        adios_perform_reads (f, 1);

#ifdef DEBUG_PRINTS
        fprintf(stderr, "2D result :\n");
        n = 0;
        for (i=0; i<ldim1; i++) {
            fprintf (stderr, "row=%2d- = {", i);
            for (j=0; j<ldim2; j++) {
                fprintf (stderr, "%d ", r2[n]); 
                n++;
            }
            fprintf(stderr, "}\n");
        }
#endif

        n = 0;
        for (i=0; i<ldim1; i++) {
            for (j=0; j<ldim2; j++) {
                v = VALUE2D(rank,f->current_step,i,j);
                if (v != r2[n]) {
                    printE ("Error: a2[%d,%d]=%d  !=  read=%d\n", i, j, v, r2[n]); 
                    //goto endread;
                }
                n++;
            }
        }




        log ("  Check 3D variable a3...\n");
        adios_schedule_read (f, sel3, "a3",  0, 1, r3);
        adios_perform_reads (f, 1);

#ifdef DEBUG_PRINTS
        fprintf(stderr, "3D selection :\n");
        n=0;
        for (i=0; i<ldim1; i++) {
            for (j=0; j<ldim2; j++) {
                fprintf (stderr, "[%d,%d] = {", i, j); 
                for (k=0; k<ldim3; k++) {
                    fprintf (stderr, "%d ", r3[n]); 
                    n++;
                }
                fprintf(stderr, "}\n");
            }
        }
#endif
        n = 0;
        for (i=0; i<ldim1; i++) {
            for (j=0; j<ldim2; j++) {
                for (k=0; k<ldim3; k++) {
                    v = VALUE3D(rank,f->current_step,i,j,k);
                    if (v != r3[n]) {
                        printE ("Error: a3[%d,%d,%d]=%d  !=  read=%d\n", i, j, k, v, r3[n]); 
                        //goto endread;
                    }
                    n++;
                }
            }
        }

        if (n1 < NSTEPS)
        {
            adios_advance_step (f, 0, -1.0);
        }
    }


endread:

    adios_selection_delete (sel1);
    adios_selection_delete (sel2);
    adios_selection_delete (sel3);

    free(pts1);
    free(pts2);
    free(pts3);

    adios_read_close(f);
    MPI_Barrier (comm);
    return err;
}
예제 #19
0
static void test_file_mode_reads_on_var(ADIOS_FILE *fp, const char *bp_filename, const char *varname) {
	int i;

	ADIOS_VARINFO *varinfo = adios_inq_var(fp, varname);
	MPI_Assert(COMM, varinfo);

	if (varinfo->value != NULL) {
		//if (rank == 0) fprintf(stderr, "(skipping scalar variable '%s')\n", varname);
		adios_free_varinfo(varinfo);
		return;
	}

	fprintf(stderr, "[rank %d/%d] Starting file-mode writeblock reads on %s:/%s\n", rank, size, bp_filename, varname);

	adios_inq_var_blockinfo(fp, varinfo);
	MPI_Assert(COMM, varinfo->blockinfo);

	const enum ADIOS_DATATYPES datatype = varinfo->type;
	const int datatypesize = adios_get_type_size(datatype, NULL);

	int timestep, timestep_blockidx, blockidx = 0;
	for (timestep = 0; timestep < varinfo->nsteps; ++timestep) {
		for (timestep_blockidx = 0; timestep_blockidx < varinfo->nblocks[timestep]; ++timestep_blockidx, ++blockidx) {
			if (blockidx % size != rank) continue;

			const ADIOS_VARBLOCK *vb = &varinfo->blockinfo[blockidx];

			ADIOS_SELECTION *block_bb = adios_selection_boundingbox(varinfo->ndim, vb->start, vb->count);
			ADIOS_SELECTION *block_wb = adios_selection_writeblock(timestep_blockidx);
			ADIOS_SELECTION *block_abs_wb = adios_selection_writeblock(blockidx);
			block_abs_wb->u.block.is_absolute_index = 1;

			uint64_t blocksize = datatypesize;
			for (i = 0; i < varinfo->ndim; ++i)
				blocksize *= vb->count[i];

			void *buf_bb = malloc(blocksize);
			void *buf_wb = malloc(blocksize);
			void *buf_abs_wb = malloc(blocksize);
			memset(buf_bb,     0, blocksize);
			memset(buf_wb,     1, blocksize);
			memset(buf_abs_wb, 2, blocksize);
			MPI_Assert(COMM, buf_bb && buf_wb && buf_abs_wb);

			adios_schedule_read(fp, block_bb,     varname, timestep, 1, buf_bb    );
			adios_schedule_read(fp, block_wb,     varname, timestep, 1, buf_wb    );
			adios_schedule_read(fp, block_abs_wb, varname, timestep, 1, buf_abs_wb);
			adios_perform_reads(fp, 1);

			fprintf(stderr, "[rank %d/%d] Checking file-mode blockidx %d BB vs. WB...\n", rank, size, blockidx);
			MPI_Assert(COMM, memcmp(buf_bb, buf_wb, blocksize) == 0);
			fprintf(stderr, "[rank %d/%d] Checking file-mode blockidx %d BB vs. abs-WB...\n", rank, size, blockidx);
			MPI_Assert(COMM, memcmp(buf_bb, buf_abs_wb, blocksize) == 0);

			free(buf_bb); free(buf_wb); free(buf_abs_wb);
			adios_selection_delete(block_bb);
			adios_selection_delete(block_wb);
			adios_selection_delete(block_abs_wb);
		}
	}

	adios_free_varinfo(varinfo);

	fprintf(stderr, "[rank %d/%d] Finished file-mode writeblock reads on %s:/%s\n", rank, size, bp_filename, varname);
}
예제 #20
0
eavlField *
eavlXGCParticleImporter::GetField(const string &name, const string &mesh, int chunk)
{
    int idx = 0;
    eavlField *field;
    uint64_t s[3], c[3];
    map<string, ADIOS_VARINFO*>::const_iterator it;
    if(name.compare("ephase") == 0 && ephaseAvail)
    {
        eavlFloatArray *arr = new eavlFloatArray(name, 1);
        arr->SetNumberOfTuples(totalEParticles*9);
        for(it = ephase.begin(); it != ephase.end(); it++)
        {
            int nt = 1;
            ADIOS_SELECTION *sel;
            if(readingRestartFile)
                sel = MakeSelection(it->second, s, c);
            else
                sel = MakeLimitedSelection(it->second, s, c, 0);

            for(int i = 0; i < it->second->ndim; i++)
                nt *= c[i];

            double *buff = new double[nt];
            adios_schedule_read_byid(fp, sel, it->second->varid, 0, 1, buff);
            int retval = adios_perform_reads(fp, 1);
            adios_selection_delete(sel);

            for(int i = 0; i < nt; i++)
            {
                arr->SetComponentFromDouble(idx, 0, buff[i]);
                idx++;
            }
            delete [] buff;
        }
        field = new eavlField(1, arr, eavlField::ASSOC_POINTS);
    }
    else if(name.compare("iphase") == 0 && iphaseAvail)
    {
        eavlFloatArray *arr = new eavlFloatArray(name, 1);
        arr->SetNumberOfTuples(totalIParticles*9);
        for(it = iphase.begin(); it != iphase.end(); it++)
        {
            int nt = 1;
            ADIOS_SELECTION *sel;
            if(readingRestartFile)
                sel = MakeSelection(it->second, s, c);
            else
                sel = MakeLimitedSelection(it->second, s, c, 1);

            for (int i = 0; i < it->second->ndim; i++)
                nt *= c[i];

            double *buff = new double[nt];
            adios_schedule_read_byid(fp, sel, it->second->varid, 0, 1, buff);
            int retval = adios_perform_reads(fp, 1);
            adios_selection_delete(sel);

            for(int i = 0; i < nt; i++)
            {
                arr->SetComponentFromDouble(idx, 0, buff[i]);
                idx++;
            }
            delete [] buff;
        }
        field = new eavlField(1, arr, eavlField::ASSOC_POINTS);
    }
    else if(name.compare("igid") == 0 && iphaseAvail)
    {
        eavlIntArray *arr = new eavlIntArray(name, 1);
        arr->SetNumberOfTuples(totalIParticles);
        for(it = igid.begin(); it != igid.end(); it++)
        {
            int nt = 1;
            ADIOS_SELECTION *sel;
            if(readingRestartFile)
                sel = MakeSelection(it->second, s, c);
            else
                sel = MakeLimitedSelection(it->second, s, c, 1);

            for(int i = 0; i < it->second->ndim; i++)
                nt *= c[i];

            long long *buff = new long long[nt];
            adios_schedule_read_byid(fp, sel, it->second->varid, 0, 1, buff);
            int retval = adios_perform_reads(fp, 1);
            adios_selection_delete(sel);

            for(int i = 0; i < nt; i++)
            {
                arr->SetValue(idx, (int)buff[i]);
                idx++;
            }
            delete [] buff;
        }
        field = new eavlField(1, arr, eavlField::ASSOC_POINTS);
    }
    else if((name.compare("egid") == 0) && ephaseAvail )
    {
        eavlIntArray *arr = new eavlIntArray(name, 1);
        arr->SetNumberOfTuples(totalEParticles);
        for (it = egid.begin(); it != egid.end(); it++)
        {
            int nt = 1;
            ADIOS_SELECTION *sel;
            if(readingRestartFile)
                sel = MakeSelection(it->second, s, c);
            else
                sel = MakeLimitedSelection(it->second, s, c, 0);

            for(int i = 0; i < it->second->ndim; i++)
                nt *= c[i];
            long long *buff = new long long[nt];
            adios_schedule_read_byid(fp, sel, it->second->varid, 0, 1, buff);
            int retval = adios_perform_reads(fp, 1);
            adios_selection_delete(sel);

            for(int i = 0; i < nt; i++)
            {
                arr->SetValue(idx, (int)buff[i]);
                idx++;
            }
            delete [] buff;
        }
        field = new eavlField(1, arr, eavlField::ASSOC_POINTS);
    }
    else
    {
        THROW(eavlException, string("Variable not found: ")+name);
    }
    return field;
}
int main (int argc, char ** argv) 
{
    int         rank, size, i, j;
    MPI_Comm    comm = MPI_COMM_WORLD;
    ADIOS_FILE * f;
    ADIOS_VARINFO * v;
    ADIOS_SELECTION * sel;
    int steps = 0;
    int retval = 0;
    float timeout_sec = 1.0; 

    void * data = NULL;
    uint64_t start[2], count[2];

    MPI_Init (&argc, &argv);

    MPI_Comm_rank (comm, &rank);
    MPI_Comm_size (comm, &size);

    adios_read_init_method (ADIOS_READ_METHOD_BP, comm, "verbose=3");

    f = adios_read_open ("adios_globaltime.bp", ADIOS_READ_METHOD_BP,
                          comm, ADIOS_LOCKMODE_NONE, timeout_sec);
    if (adios_errno == err_file_not_found)
    {
        printf ("rank %d: Stream not found after waiting %f seconds: %s\n",
                rank, timeout_sec, adios_errmsg());
        retval = adios_errno;
    }
    else if (adios_errno == err_end_of_stream)
    {
        printf ("rank %d: Stream terminated before open. %s\n", rank, adios_errmsg());
        retval = adios_errno;
    }
    else if (f == NULL) {
        printf ("rank %d: Error at opening stream: %s\n", rank, adios_errmsg());
        retval = adios_errno;
    }
    else
    {
        /* process file here... */
        v = adios_inq_var (f, "temperature");
        adios_inq_var_blockinfo (f, v);

        printf ("ndim = %d\n",  v->ndim);
        //printf ("nsteps = %d\n",  v->nsteps);
        printf ("dims[%llu][%llu]\n",  v->dims[0], v->dims[1]);

        uint64_t slice_size = v->dims[0]/size;
        if (rank == size-1)
            slice_size = slice_size + v->dims[0]%size;

        start[0] = rank * slice_size;
        count[0] = slice_size;
        start[1] = 0;
        count[1] = v->dims[1];

        data = malloc (slice_size * v->dims[1] * 8);

        /* Processing loop over the steps (we are already in the first one) */
        while (adios_errno != err_end_of_stream) {
            steps++; // steps start counting from 1

            sel = adios_selection_boundingbox (v->ndim, start, count);
            adios_schedule_read (f, sel, "temperature", 0, 1, data);
            adios_perform_reads (f, 1);

            if (rank == 0)
                printf ("--------- Step: %d --------------------------------\n", 
                        f->current_step);

            printf("rank=%d: [0:%lld,0:%lld] = [", rank, v->dims[0], v->dims[1]);
            for (i = 0; i < slice_size; i++) {
                printf (" [");
                for (j = 0; j < v->dims[1]; j++) {
                    printf ("%g ", *((double *)data + i * v->dims[1] + j));
                }
                printf ("]");
            }
            printf (" ]\n\n");

            // advance to 1) next available step with 2) blocking wait
            adios_advance_step (f, 0, timeout_sec);
            if (adios_errno == err_step_notready)
            {
                printf ("rank %d: No new step arrived within the timeout. Quit. %s\n",
                        rank, adios_errmsg());
                break; // quit while loop
            }

        }

        adios_read_close (f);
    }

    if (rank==0) 
        printf ("We have processed %d steps\n", steps);

    adios_read_finalize_method (ADIOS_READ_METHOD_BP);
    free (data);
    MPI_Finalize ();

    return retval;
}
예제 #22
0
int worker(int argc, char* argv[]) {
    TAU_PROFILE_TIMER(timer, __func__, __FILE__, TAU_USER);
    TAU_PROFILE_START(timer);
    my_printf("%d of %d In worker B\n", myrank, commsize);
    static bool announced = false;

    /* validate input */
    validate_input(argc, argv);

    my_printf("Worker B will execute until it sees n iterations.\n", iterations);

    /* ADIOS: These declarations are required to match the generated
     *        gread_/gwrite_ functions.  (And those functions are
     *        generated by calling 'gpp.py adios_config.xml') ...
     *        EXCEPT THAT THE generation of Reader code is broken.
     *        So, we will write the reader code manually.
     */
    uint64_t  adios_groupsize;
    uint64_t  adios_totalsize;
    uint64_t  adios_handle;
    void * data = NULL;
    uint64_t start[2], count[2];
    int i, j, steps = 0;
    int NX = 10;
    int NY = 1;
    double t[NX];
    double p[NX];

    /* ADIOS: Can duplicate, split the world, whatever.
     *        This allows you to have P writers to N files.
     *        With no splits, everyone shares 1 file, but
     *        can write lock-free by using different areas.
     */
    MPI_Comm  adios_comm, adios_comm_b_to_c;
    adios_comm = MPI_COMM_WORLD;
    //MPI_Comm_dup(MPI_COMM_WORLD, &adios_comm);
    adios_comm_b_to_c = MPI_COMM_WORLD;
    //MPI_Comm_dup(MPI_COMM_WORLD, &adios_comm_b_to_c);

    enum ADIOS_READ_METHOD method = ADIOS_READ_METHOD_FLEXPATH;
    adios_read_init_method(method, adios_comm, "verbose=3");
    if (adios_errno != err_no_error) {
        fprintf (stderr, "rank %d: Error %d at init: %s\n", myrank, adios_errno, adios_errmsg());
        exit(4);
    }
    if (send_to_c) {
        adios_init("adios_config.xml", adios_comm);
    }

    /* ADIOS: Set up the adios communications and buffers, open the file.
    */
    ADIOS_FILE *fp; // file handler
    ADIOS_VARINFO *vi; // information about one variable 
    ADIOS_SELECTION * sel;
    char      adios_filename_a_to_b[256];
    char      adios_filename_b_to_c[256];
    enum ADIOS_LOCKMODE lock_mode = ADIOS_LOCKMODE_NONE;
    double timeout_sec = 1.0;
    sprintf(adios_filename_a_to_b, "adios_a_to_b.bp");
    sprintf(adios_filename_b_to_c, "adios_b_to_c.bp");
    my_printf ("rank %d: Worker B opening file: %s\n", myrank, adios_filename_a_to_b);
    fp = adios_read_open(adios_filename_a_to_b, method, adios_comm, lock_mode, timeout_sec);
    if (adios_errno == err_file_not_found) {
        fprintf (stderr, "rank %d: Stream not found after waiting %d seconds: %s\n",
        myrank, timeout_sec, adios_errmsg());
        exit(1);
    } else if (adios_errno == err_end_of_stream) {
        // stream has been gone before we tried to open
        fprintf (stderr, "rank %d: Stream terminated before open. %s\n", myrank, adios_errmsg());
        exit(2);
    } else if (fp == NULL) {
        // some other error happened
        fprintf (stderr, "rank %d: Error %d at opening: %s\n", myrank, adios_errno, adios_errmsg());
        exit(3);
    } else {
        my_printf("Found file %s\n", adios_filename_a_to_b);
        my_printf ("File info:\n");
        my_printf ("  current step:   %d\n", fp->current_step);
        my_printf ("  last step:      %d\n", fp->last_step);
        my_printf ("  # of variables: %d:\n", fp->nvars);

        vi = adios_inq_var(fp, "temperature");
        adios_inq_var_blockinfo(fp, vi);

        printf ("ndim = %d\n",  vi->ndim);
        printf ("nsteps = %d\n",  vi->nsteps);
        printf ("dims[%llu][%llu]\n",  vi->dims[0], vi->dims[1]);

        uint64_t slice_size = vi->dims[0]/commsize;
        if (myrank == commsize-1) {
            slice_size = slice_size + vi->dims[0]%commsize;
        }

        start[0] = myrank * slice_size;
        count[0] = slice_size;
        start[1] = 0;
        count[1] = vi->dims[1];

        data = malloc (slice_size * vi->dims[1] * 8);

        /* Processing loop over the steps (we are already in the first one) */
        while (adios_errno != err_end_of_stream && steps < iterations) {
            steps++; // steps start counting from 1

            TAU_PROFILE_TIMER(adios_recv_timer, "ADIOS recv", __FILE__, TAU_USER);
            TAU_PROFILE_START(adios_recv_timer);
            sel = adios_selection_boundingbox (vi->ndim, start, count);
            adios_schedule_read (fp, sel, "temperature", 0, 1, data);
            adios_perform_reads (fp, 1);

            if (myrank == 0)
                printf ("--------- B Step: %d --------------------------------\n",
                        fp->current_step);

#if 0
            printf("B rank=%d: [0:%lld,0:%lld] = [", myrank, vi->dims[0], vi->dims[1]);
            for (i = 0; i < slice_size; i++) {
                printf (" [");
                for (j = 0; j < vi->dims[1]; j++) {
                    printf ("%g ", *((double *)data + i * vi->dims[1] + j));
                }
                printf ("]");
            }
            printf (" ]\n\n");
#endif

            // advance to 1) next available step with 2) blocking wait
            adios_advance_step (fp, 0, timeout_sec);
            if (adios_errno == err_step_notready)
            {
                printf ("B rank %d: No new step arrived within the timeout. Quit. %s\n",
                        myrank, adios_errmsg());
                break; // quit while loop
            }
            TAU_PROFILE_STOP(adios_recv_timer);

            /* Do some exchanges with neighbors */
            //do_neighbor_exchange();
            /* "Compute" */
            compute(steps);

            for (i = 0; i < NX; i++) {
                t[i] = steps*100.0 + myrank*NX + i;
            }

            for (i = 0; i < NY; i++) {
                p[i] = steps*1000.0 + myrank*NY + i;
            }

            if (send_to_c) {
                TAU_PROFILE_TIMER(adios_send_timer, "ADIOS send", __FILE__, TAU_USER);
                TAU_PROFILE_START(adios_send_timer);
                /* ADIOS: write to the next application in the workflow */
                if (steps == 0) {
                    adios_open(&adios_handle, "b_to_c", adios_filename_b_to_c, "w", adios_comm_b_to_c);
                } else {
                    adios_open(&adios_handle, "b_to_c", adios_filename_b_to_c, "a", adios_comm_b_to_c);
                }
                /* ADIOS: Actually write the data out.
                *        Yes, this is the recommended method, and this way, changes in
                *        configuration with the .XML file will, even in the worst-case
                *        scenario, merely require running 'gpp.py adios_config.xml'
                *        and typing 'make'.
                */
                #include "gwrite_b_to_c.ch"
                /* ADIOS: Close out the file completely and finalize.
                *        If MPI is being used, this must happen before MPI_Finalize().
                */
                adios_close(adios_handle);
                TAU_PROFILE_STOP(adios_send_timer);
            #if 1
            if (!announced) {
                SOS_val foo;
                foo.i_val = NX;
                SOS_pack(example_pub, "NX", SOS_VAL_TYPE_INT, foo);
                SOS_announce(example_pub);
                SOS_publish(example_pub);
                announced = true;
            }
            #endif
            }
            MPI_Barrier(adios_comm_b_to_c);
        }
        MPI_Barrier(MPI_COMM_WORLD);
        adios_read_close(fp);
        /* ADIOS: Close out the file completely and finalize.
        *        If MPI is being used, this must happen before MPI_Finalize().
        */
        adios_read_finalize_method(method);
    }
    if (send_to_c) {
        adios_finalize(myrank);
    }

    free(data);
    //MPI_Comm_free(&adios_comm);
    //MPI_Comm_free(&adios_comm_b_to_c);

    TAU_PROFILE_STOP(timer);
    /* exit */
    return 0;
}
예제 #23
0
eavlDataSet *
eavlXGCParticleImporter::GetMesh(const string &name, int chunk)
{
    eavlDataSet *ds = new eavlDataSet;

    if(name == "iMesh" && iphaseAvail)
    {
        ds->SetNumPoints(totalIParticles);
        eavlCoordinatesCartesian *coords = new eavlCoordinatesCartesian(NULL,
                eavlCoordinatesCartesian::X,
                eavlCoordinatesCartesian::Y,
                eavlCoordinatesCartesian::Z);
        ds->AddCoordinateSystem(coords);
        coords->SetAxis(0, new eavlCoordinateAxisField("xcoords", 0));
        coords->SetAxis(1, new eavlCoordinateAxisField("ycoords", 0));
        coords->SetAxis(2, new eavlCoordinateAxisField("zcoords", 0));

        eavlArray *axisValues[3] = {
            new eavlFloatArray("xcoords", 1),
            new eavlFloatArray("ycoords", 1),
            new eavlFloatArray("zcoords", 1)
        };
        axisValues[0]->SetNumberOfTuples(totalIParticles);
        axisValues[1]->SetNumberOfTuples(totalIParticles);
        axisValues[2]->SetNumberOfTuples(totalIParticles);

        //Set all of the axis values to the x, y, z coordinates of the
        //iphase particles; set computational node origin
        eavlIntArray *originNode;
        if(getOriginNode && readingRestartFile)
            originNode = new eavlIntArray("originNode", 1, totalIParticles);
        eavlFloatArray *r;
        if(getR)
            r = new eavlFloatArray("R", 1, totalIParticles);
        eavlFloatArray *z;
        if(getZ)
            z = new eavlFloatArray("Z", 1, totalIParticles);
        eavlFloatArray *phi;
        if(getPhi)
            phi = new eavlFloatArray("phi", 1, totalIParticles);
        eavlFloatArray *rho;
        if(getRho)
            rho = new eavlFloatArray("rho", 1, totalIParticles);
        eavlFloatArray *w1;
        if(getW1)
            w1 = new eavlFloatArray("w1", 1, totalIParticles);
        eavlFloatArray *w2;
        if(getW2)
            w2 = new eavlFloatArray("w2", 1, totalIParticles);
        eavlFloatArray *mu;
        if(getMu)
            mu = new eavlFloatArray("mu", 1, totalIParticles);
        eavlFloatArray *w0;
        if(getW0)
            w0 = new eavlFloatArray("w0", 1, totalIParticles);
        eavlFloatArray *f0;
        if(getF0)
            f0 = new eavlFloatArray("f0", 1, totalIParticles);

        uint64_t s[3], c[3];
        double *buff;
        int nt = 1, idx = 0;
        map<string, ADIOS_VARINFO*>::const_iterator it;
        for(it = iphase.begin(); it != iphase.end(); it++)
        {
            ADIOS_SELECTION *sel;
            if(readingRestartFile)
                sel = MakeSelection(it->second, s, c);
            else
                sel = MakeLimitedSelection(it->second, s, c, 1);

            nt = 1;
            for (int i = 0; i < it->second->ndim; i++)
                nt *= c[i];

            buff = new double[nt];
            adios_schedule_read_byid(fp, sel, it->second->varid, 0, 1, buff);
            adios_perform_reads(fp, 1);
            adios_selection_delete(sel);

            string nodeNum;
            if(getOriginNode && readingRestartFile) nodeNum = it->first.substr(it->first.find("_",1,1)+1, 5);

            for(int i = 0; i < nt; i+=9)
            {
                if(getR)   r->SetValue(idx, buff[i]);
                if(getZ)   z->SetValue(idx, buff[i+1]);
                if(getPhi) phi->SetValue(idx, buff[i+2]);
                if(getRho) rho->SetValue(idx, buff[i+3]);
                if(getW1)  w1->SetValue(idx, buff[i+4]);
                if(getW2)  w2->SetValue(idx, buff[i+5]);
                if(getMu)  mu->SetValue(idx, buff[i+6]);
                if(getW0)  w0->SetValue(idx, buff[i+7]);
                if(getF0)  f0->SetValue(idx, buff[i+8]);
                axisValues[0]->SetComponentFromDouble(idx, 0, r->GetValue(idx)*cos(phi->GetValue(idx)));
                axisValues[1]->SetComponentFromDouble(idx, 0, r->GetValue(idx)*sin(phi->GetValue(idx)));
                axisValues[2]->SetComponentFromDouble(idx, 0, z->GetValue(idx));
                if(getOriginNode && readingRestartFile) originNode->SetValue(idx, atoi(nodeNum.c_str()));
                idx++;
            }
            delete [] buff;
        }

        ds->AddField(new eavlField(1, axisValues[0], eavlField::ASSOC_POINTS));
        ds->AddField(new eavlField(1, axisValues[1], eavlField::ASSOC_POINTS));
        ds->AddField(new eavlField(1, axisValues[2], eavlField::ASSOC_POINTS));
        if(getOriginNode && readingRestartFile)
            ds->AddField(new eavlField(1, originNode, eavlField::ASSOC_POINTS));
        if(getR)   ds->AddField(new eavlField(1, r,   eavlField::ASSOC_POINTS));
        if(getZ)   ds->AddField(new eavlField(1, z,   eavlField::ASSOC_POINTS));
        if(getPhi) ds->AddField(new eavlField(1, phi, eavlField::ASSOC_POINTS));
        if(getRho) ds->AddField(new eavlField(1, rho, eavlField::ASSOC_POINTS));
        if(getW1)  ds->AddField(new eavlField(1, w1,  eavlField::ASSOC_POINTS));
        if(getW2)  ds->AddField(new eavlField(1, w2,  eavlField::ASSOC_POINTS));
        if(getMu)  ds->AddField(new eavlField(1, mu,  eavlField::ASSOC_POINTS));
        if(getW0)  ds->AddField(new eavlField(1, w0,  eavlField::ASSOC_POINTS));
        if(getF0)  ds->AddField(new eavlField(1, f0,  eavlField::ASSOC_POINTS));

        eavlCellSet *cellSet = new eavlCellSetAllPoints(name + "_cells", totalIParticles);
        ds->AddCellSet(cellSet);
        //-- END set axis values

        //----Set the ids of all axis values
        idx = 0;
        long long *idBuff;
        eavlIntArray *axisIds = new eavlIntArray("id", 1, totalIParticles);
        for(it = igid.begin(); it != igid.end(); it++)
        {
            ADIOS_SELECTION *sel;
            if(readingRestartFile)
                sel = MakeSelection(it->second, s, c);
            else
                sel = MakeLimitedSelection(it->second, s, c, 1);

            nt = 1;
            for (int i = 0; i < it->second->ndim; i++)
                nt *= c[i];

            idBuff = new long long[nt];
            adios_schedule_read_byid(fp, sel, it->second->varid, 0, 1, idBuff);
            adios_perform_reads(fp, 1);
            adios_selection_delete(sel);

            for(int i = 0; i < nt; i++)
            {
                axisIds->SetValue(idx, (int)idBuff[i]);
                idx++;
            }
            delete [] idBuff;
        }
        ds->AddField(new eavlField(1, axisIds, eavlField::ASSOC_POINTS));
        //-- END set ids

    }
    else if(name == "eMesh" && ephaseAvail)
    {
        ds->SetNumPoints(totalEParticles);
        eavlCoordinatesCartesian *coords = new eavlCoordinatesCartesian(NULL,
                eavlCoordinatesCartesian::X,
                eavlCoordinatesCartesian::Y,
                eavlCoordinatesCartesian::Z);
        ds->AddCoordinateSystem(coords);
        coords->SetAxis(0, new eavlCoordinateAxisField("xcoords", 0));
        coords->SetAxis(1, new eavlCoordinateAxisField("ycoords", 0));
        coords->SetAxis(2, new eavlCoordinateAxisField("zcoords", 0));

        eavlArray *axisValues[3] = {
            new eavlFloatArray("xcoords", 1),
            new eavlFloatArray("ycoords", 1),
            new eavlFloatArray("zcoords", 1)
        };
        axisValues[0]->SetNumberOfTuples(totalEParticles);
        axisValues[1]->SetNumberOfTuples(totalEParticles);
        axisValues[2]->SetNumberOfTuples(totalEParticles);

        //Set all of the axis values to the x, y, z coordinates of the
        //ephase particles; set computational node origin
        eavlIntArray *originNode;
        if(getOriginNode && readingRestartFile)
            originNode = new eavlIntArray("originNode", 1, totalIParticles);
        eavlFloatArray *r;
        if(getR)
            r = new eavlFloatArray("R", 1, totalIParticles);
        eavlFloatArray *z;
        if(getZ)
            z = new eavlFloatArray("Z", 1, totalIParticles);
        eavlFloatArray *phi;
        if(getPhi)
            phi = new eavlFloatArray("phi", 1, totalIParticles);
        eavlFloatArray *rho;
        if(getRho)
            rho = new eavlFloatArray("rho", 1, totalIParticles);
        eavlFloatArray *w1;
        if(getW1)
            w1 = new eavlFloatArray("w1", 1, totalIParticles);
        eavlFloatArray *w2;
        if(getW2)
            w2 = new eavlFloatArray("w2", 1, totalIParticles);
        eavlFloatArray *mu;
        if(getMu)
            mu = new eavlFloatArray("mu", 1, totalIParticles);
        eavlFloatArray *w0;
        if(getW0)
            w0 = new eavlFloatArray("w0", 1, totalIParticles);
        eavlFloatArray *f0;
        if(getF0)
            f0 = new eavlFloatArray("f0", 1, totalIParticles);

        uint64_t s[3], c[3];
        int nt = 1, idx = 0;
        double *buff;
        map<string, ADIOS_VARINFO*>::const_iterator it;
        for(it = ephase.begin(); it != ephase.end(); it++)
        {
            ADIOS_SELECTION *sel;
            if(readingRestartFile)
                sel = MakeSelection(it->second, s, c);
            else
                sel = MakeLimitedSelection(it->second, s, c, 0);

            nt = 1;
            for(int i = 0; i < it->second->ndim; i++)
                nt *= c[i];

            buff = new double[nt];
            adios_schedule_read_byid(fp, sel, it->second->varid, 0, 1, buff);
            adios_perform_reads(fp, 1);
            adios_selection_delete(sel);

            string nodeNum;
            if(getOriginNode && readingRestartFile) nodeNum = it->first.substr(it->first.find("_",1,1)+1, 5);

            for(int i = 0; i < nt; i+=9)
            {
                if(getR)   r->SetValue(idx, buff[i]);
                if(getZ)   z->SetValue(idx, buff[i+1]);
                if(getPhi) phi->SetValue(idx, buff[i+2]);
                if(getRho) rho->SetValue(idx, buff[i+3]);
                if(getW1)  w1->SetValue(idx, buff[i+4]);
                if(getW2)  w2->SetValue(idx, buff[i+5]);
                if(getMu)  mu->SetValue(idx, buff[i+6]);
                if(getW0)  w0->SetValue(idx, buff[i+7]);
                if(getF0)  f0->SetValue(idx, buff[i+8]);
                axisValues[0]->SetComponentFromDouble(idx, 0, r->GetValue(idx)*cos(phi->GetValue(idx)));
                axisValues[1]->SetComponentFromDouble(idx, 0, r->GetValue(idx)*sin(phi->GetValue(idx)));
                axisValues[2]->SetComponentFromDouble(idx, 0, z->GetValue(idx));
                if(getOriginNode && readingRestartFile) originNode->SetValue(idx, atoi(nodeNum.c_str()));
                idx++;
            }
            delete [] buff;
        }

        ds->AddField(new eavlField(1, axisValues[0], eavlField::ASSOC_POINTS));
        ds->AddField(new eavlField(1, axisValues[1], eavlField::ASSOC_POINTS));
        ds->AddField(new eavlField(1, axisValues[2], eavlField::ASSOC_POINTS));
        if(getOriginNode && readingRestartFile)
            ds->AddField(new eavlField(1, originNode, eavlField::ASSOC_POINTS));
        if(getR)   ds->AddField(new eavlField(1, r,   eavlField::ASSOC_POINTS));
        if(getZ)   ds->AddField(new eavlField(1, z,   eavlField::ASSOC_POINTS));
        if(getPhi) ds->AddField(new eavlField(1, phi, eavlField::ASSOC_POINTS));
        if(getRho) ds->AddField(new eavlField(1, rho, eavlField::ASSOC_POINTS));
        if(getW1)  ds->AddField(new eavlField(1, w1,  eavlField::ASSOC_POINTS));
        if(getW2)  ds->AddField(new eavlField(1, w2,  eavlField::ASSOC_POINTS));
        if(getMu)  ds->AddField(new eavlField(1, mu,  eavlField::ASSOC_POINTS));
        if(getW0)  ds->AddField(new eavlField(1, w0,  eavlField::ASSOC_POINTS));
        if(getF0)  ds->AddField(new eavlField(1, f0,  eavlField::ASSOC_POINTS));

        eavlCellSet *cellSet = new eavlCellSetAllPoints(name + "_cells", totalEParticles);
        ds->AddCellSet(cellSet);
        //-- END set axis values


        //----Set the ids of all axis values
        idx = 0;
        long long *idBuff;
        eavlIntArray *axisIds = new eavlIntArray("id", 1, totalEParticles);

        for(it = egid.begin(); it != egid.end(); it++)
        {
            ADIOS_SELECTION *sel;
            if(readingRestartFile)
                sel = MakeSelection(it->second, s, c);
            else
                sel = MakeLimitedSelection(it->second, s, c, 0);

            nt = 1;
            for (int i = 0; i < it->second->ndim; i++)
                nt *= c[i];

            idBuff = new long long[nt];
            adios_schedule_read_byid(fp, sel, it->second->varid, 0, 1, idBuff);
            adios_perform_reads(fp, 1);
            adios_selection_delete(sel);

            for(int i = 0; i < nt; i++)
            {
                axisIds->SetValue(idx, (int)idBuff[i]);
                idx++;
            }
            delete [] idBuff;
        }
        ds->AddField(new eavlField(1, axisIds, eavlField::ASSOC_POINTS));
    }
    return ds;
}
예제 #24
0
int main (int argc, char ** argv)
{
    int         i, j, datasize;
    MPI_Comm    comm = MPI_COMM_WORLD;
    enum ADIOS_READ_METHOD method = ADIOS_READ_METHOD_BP;
    ADIOS_SELECTION * sel1;
    double * data = NULL;
    uint64_t start[2], count[2];

    MPI_Init (&argc, &argv);
#ifdef WITH_NCSU_TIMER
    timer_init();
#endif

    adios_read_init_method (method, comm, NULL);

    ADIOS_FILE * f = adios_read_open_file ("adios_global.bp", method, comm);
    ADIOS_VARINFO * varinfo = adios_inq_var (f, "temperature");
    if (varinfo)
    {
        int nranks;

        assert(varinfo->ndim == 2);

        nranks = varinfo->dims[0];
        assert(nranks % 4 == 0);
        assert(varinfo->dims[1] == 10);

        datasize = (nranks / 2) * varinfo->dims[1] * sizeof(double);
        data = malloc (datasize);

        start[0] = nranks / 4;
        start[1] = 2;
        count[0] = nranks / 2;
        count[1] = 6;

        sel1 = adios_selection_boundingbox (varinfo->ndim, start, count);

        adios_schedule_read (f, sel1, "temperature", 0, 1, data);
        adios_perform_reads (f, 1);

        printf("Subvolume at (%" PRIu64 ",%" PRIu64 ") of size (%" PRIu64 ",%" PRIu64 "):\n", start[0], start[1], count[0], count[1]);
        for (i = 0; i < count[0]; i++) {
            printf("[ ");
            for (j = 0; j < count[1]; j++) {
                printf("%.0lf ", data[i * count[1] + j]);
            }
            printf("]\n");
        }

        adios_selection_delete (sel1);
    }

    adios_free_varinfo (varinfo);
    adios_read_close (f);

    adios_read_finalize_method (ADIOS_READ_METHOD_BP);


#ifdef WITH_NCSU_TIMER
    printf("[TIMERS] ");
    timer_result_t *results = timer_get_results_sorted();
    for (i = 0; i < timer_get_num_timers(); i++) {
        printf("%s: %0.4lf ", results[i].name, results[i].time);
    }
    printf("\n");
    free(results);
#endif

#ifdef WITH_NCSU_TIMER
    timer_finalize();
#endif
    MPI_Finalize ();
    return 0;
}
예제 #25
0
파일: blocks.c 프로젝트: wjlei1990/ADIOS
int print_scalar (ADIOS_FILE *f, char * name) 
{
    ADIOS_VARINFO * v;
    int i,j,k;

    v = adios_inq_var (f, name);
    adios_inq_var_blockinfo (f, v);

    printf ("Scalar '%s':\n",  name);
    printf ("nsteps = %d\n",  v->nsteps);
    printf ("nblocks per step = %d\n",  v->nblocks[0]);

    int err;

    /* Read one writeblock across all timesteps */
    int *data = (int*) calloc (v->nsteps, sizeof(int));
    ADIOS_SELECTION *s;
    printf ("Read same instance across all timesteps:\n");
    for (i=0; i < v->nblocks[0]; i++) {
        s = adios_selection_writeblock(i);
        err = adios_schedule_read_byid(f, s, v->varid, 0, v->nsteps, data);
        if (!err) 
        { 
            err = adios_perform_reads(f, 1);
            if (!err) 
            { 
                err = 0;
                printf ("  block %d = [",  i);
                for (j=0; j < v->nsteps; j++) {
                    printf ("%d", data[j]);
                    if (data[j] != 
                        block_offset [j*nblocks_per_step*size + i]) 
                    {
                        err = 1;
                    }
                    if (j < v->nsteps-1) printf(",");
                }
                printf("]");

                if (err) 
                {
                    nerrors++;
                    printf ("\tERROR expected = [");
                    for (j=0; j < v->nsteps; j++) {
                        printf ("%llu", block_offset [j*nblocks_per_step*size + i]);
                        if (j < v->nsteps-1) printf(",");
                    }
                    printf("]");
                }
                printf("\n");

            } else {
                printf ("ERROR at reading scalar '%s': %s\n", name, adios_errmsg());
            } 
        } else {
                printf ("ERROR at scheduling read for scalar '%s': %s\n", name, adios_errmsg());
        }
        adios_selection_delete(s);
    }

    /* Now read piecewise, one writeblock at a time */
    printf ("Read each instance individually:\n");
    for (j=0; j < v->nsteps; j++) {
        printf ("  step %d: \n",  j);
        for (i=0; i < v->nblocks[j]; i++) {
            s = adios_selection_writeblock(i);
            err = adios_schedule_read_byid(f, s, v->varid, j, 1, data);
            if (!err) 
            { 
                err = adios_perform_reads(f, 1);
                if (!err) 
                { 
                    printf ("    block %d = %d", i, data[0]);
                    if (data[0] != 
                        block_offset [j*nblocks_per_step*size + i]) 
                    {
                        printf ("\tERROR expected = %llu", 
                                block_offset [j*nblocks_per_step*size + i]);
                        nerrors++;
                    }
                    printf ("\n");
                } else {
                    printf ("ERROR at reading scalar '%s': %s\n", name, adios_errmsg());
                } 
            } else {
                printf ("ERROR at scheduling read for scalar '%s': %s\n", name, adios_errmsg());
            }
            adios_selection_delete(s);
        }
    }

    /* Now get them piecewise, but not with reading but through statistics */
    printf ("Get each instance individually from available statistics:\n");
    adios_inq_var_stat (f, v, 0, 1);
    if (v->statistics && v->statistics->blocks) {
        ADIOS_VARSTAT *stat = v->statistics;
        int blockid = 0;
        for (j=0; j < v->nsteps; j++) {
            printf ("  step %d: \n",  j);
            for (i=0; i < v->nblocks[j]; i++) {
                printf ("    block %d = %d", i, *(int*)stat->blocks->mins[blockid]);
                if (*(int*)stat->blocks->mins[blockid] != 
                        block_offset [j*nblocks_per_step*size + i]) 
                {
                    printf ("\tERROR expected = %llu", 
                            block_offset [j*nblocks_per_step*size + i]);
                    nerrors++;
                }
                printf ("\n");
                blockid++;
            }
        }
    }

    adios_free_varinfo (v);
    free(data);
}
예제 #26
0
int main (int argc, char ** argv) 
{
    char        filename [256] = "stream.bp";
    int         rank, size;
    int         NX, NY; 
    int         len, off;
    double      *t = NULL;
    MPI_Comm    comm = MPI_COMM_WORLD;

    int64_t     adios_handle;
	uint64_t    adios_groupsize, adios_totalsize;

    uint64_t    start[2], count[2];

    ADIOS_SELECTION *sel;
    int         steps = 0;

    MPI_Init (&argc, &argv);
    MPI_Comm_rank (comm, &rank);
    MPI_Comm_size (comm, &size);
    
    // ADIOS read init
    adios_read_init_method (ADIOS_READ_METHOD_BP, comm, "verbose=3");
    
    ADIOS_FILE* fp = adios_read_open_file ("kstar.bp", 
                                           ADIOS_READ_METHOD_BP,
                                           comm);
    assert(fp != NULL);

    ADIOS_VARINFO* nx_info = adios_inq_var( fp, "N");
    ADIOS_VARINFO* ny_info = adios_inq_var( fp, "L");

    NX = *((int *)nx_info->value);
    NY= *((int*)ny_info->value);

    len = NX / size;
    off = len * rank;

    if (rank == size-1)
        len = len + NX % size;

    printf("\trank=%d: NX,NY,len,off = %d\t%d\t%d\t%d\n", rank, NX, NY, len, off);
    assert(len > 0);

    t = (double *) malloc(sizeof(double) * len * NY);
    memset(t, '\0', sizeof(double) * len * NY);
    assert(t != NULL);

    start[0] = off;
    start[1] = 0;
    count[0] = len;
    count[1] = NY;
    sel = adios_selection_boundingbox (2, start, count);

    // ADIOS write init
    adios_init ("adios.xml", comm);
    
    remove (filename);
    //int ii;
    //for(ii = 0; ii<10; ii++){
    //    for (i = 0; i < len * NY; i++)
    //        t[i] = ii*1000 + rank;

    while(adios_errno != err_end_of_stream && adios_errno != err_step_notready)
    {
        steps++;
        // Reading
        adios_schedule_read (fp, sel, "var", 0, 1, t);
        adios_perform_reads (fp, 1);

        // Debugging
        //for (i = 0; i < len*NY; i++)  t[i] = off * NY + i;

        printf("step=%d\trank=%d\t[%d,%d]\n", steps, rank, len, NY);

        // Writing
        adios_open (&adios_handle, "writer", filename, "a", comm);
        adios_groupsize = 4*4 + 8*len*NY;
        adios_group_size (adios_handle, adios_groupsize, &adios_totalsize);
        adios_write (adios_handle, "NX", &NX);
        adios_write (adios_handle, "NY", &NY);
        adios_write (adios_handle, "len", &len);
        adios_write (adios_handle, "off", &off);
        adios_write (adios_handle, "var_2d_array", t);
        adios_close (adios_handle);


        // Advance
        MPI_Barrier (comm);
        adios_advance_step(fp, 0, TIMEOUT_SEC);
    }
    free(t);

    MPI_Barrier (comm);
    adios_read_close(fp);

    if (rank==0) 
        printf ("We have processed %d steps\n", steps);

    MPI_Barrier (comm);
    adios_read_finalize_method(ADIOS_READ_METHOD_BP);

    adios_finalize (rank);

    MPI_Finalize ();

    return 0;
}
예제 #27
0
int main (int argc, char ** argv) 
{
    int         rank, size;
    int         NX, NY; 
    int         len, off;
    double      *t = NULL;
    MPI_Comm    comm = MPI_COMM_WORLD;

    uint64_t    start[2], count[2];

    ADIOS_SELECTION *sel;
    int         steps = 0;

#ifdef _USE_GNUPLOT
    int         i, j;
    double      *tmp;
    FILE        *pipe;
#else
    // Variables for ADIOS write
    int64_t     adios_handle;
    uint64_t    adios_groupsize, adios_totalsize;
    char        outfn[256];
#endif

    MPI_Init (&argc, &argv);
    MPI_Comm_rank (comm, &rank);
    MPI_Comm_size (comm, &size);

    adios_read_init_method(ADIOS_READ_METHOD_FLEXPATH, comm, "");

    ADIOS_FILE* fp = adios_read_open("stream.bp", 
                                     ADIOS_READ_METHOD_FLEXPATH, 
                                     comm, ADIOS_LOCKMODE_NONE, 0.0);
    assert(fp != NULL);
    
    ADIOS_VARINFO* nx_info = adios_inq_var( fp, "NX");
    ADIOS_VARINFO* ny_info = adios_inq_var( fp, "NY");

    NX = *((int *)nx_info->value);
    NY= *((int*)ny_info->value);
    
    len = NX / size;
    off = len * rank;

    if (rank == size-1)
        len = len + NX % size;
    
    printf("\trank=%d: NX,NY,len,off = %d\t%d\t%d\t%d\n", rank, NX, NY, len, off);
    assert(len > 0);

    t = (double *) malloc(sizeof(double) * len * NY);
    memset(t, '\0', sizeof(double) * len * NY);
    assert(t != NULL);

    start[0] = off;
    start[1] = 0;
    count[0] = len;
    count[1] = NY;
    // Not working ... 
    //sel = adios_selection_boundingbox (2, start, count);

    sel = malloc(sizeof(ADIOS_SELECTION));
    sel->type=ADIOS_SELECTION_WRITEBLOCK;
    sel->u.block.index = rank;

#ifdef _USE_GNUPLOT
    if ((NX % size) > 0)
    {
        fprintf(stderr, "Equal distribution is required\n");
        return -1;
    }

    if (rank == 0) {
        pipe = popen("gnuplot", "w");
        fprintf(pipe, "set view map\n");
        fprintf(pipe, "set xrange [0:%d]\n", NX-1);

        tmp = (double *) malloc(sizeof(double) * NX * NY);
        assert(tmp != NULL);
    }

#else
    // ADIOS write init
    adios_init ("adios.xml", comm);
#endif

    //while(adios_errno != err_end_of_stream && adios_errno != err_step_notready)
    while(1)
    {
        steps++;
        // Reading
        adios_schedule_read (fp, sel, "var_2d_array", 0, 1, t);
        adios_perform_reads (fp, 1);
        
        printf("step=%d\trank=%d\tfp->current_step=%d\t[%d,%d]\n", 
                steps, rank, fp->current_step, len, NY);
        /*
        // Debugging
        for (i=0; i<len; i++) {
            printf("%d: rank=%d: t[%d,0:4] = ", steps, rank, off+i);
            for (j=0; j<5; j++) {
                printf(", %g", t[i*NY + j]);
            }
            printf(" ...\n");
        }
        */

        // Do something 
#ifdef _USE_GNUPLOT         // Option 1: plotting

        MPI_Gather(t, len * NY, MPI_DOUBLE, tmp, len * NY, MPI_DOUBLE, 0, comm);
        
        if (rank == 0)
        {
            fprintf(pipe, "set title 'Soft X-Rray Signal (shot #%d)'\n", steps);
            fprintf(pipe, "set xlabel 'Channel#'\n");
            fprintf(pipe, "set ylabel 'Timesteps'\n");
            fprintf(pipe, "set cblabel 'Voltage (eV)'\n");

#  ifndef _GNUPLOT_INTERACTIVE
            fprintf(pipe, "set terminal png\n");
            fprintf(pipe, "set output 'fig%03d.png'\n", steps);
#  endif

            fprintf(pipe, "splot '-' matrix with image\n");
            //fprintf(pipe, "plot '-' with lines, '-' with lines, '-' with lines\n");

            double *sum = calloc(NX, sizeof(double));

            for (j = 0; j < NY; j++) {
                for (i = 0; i < NX; i++) {
                    sum[i] += tmp[i * NY + j];
                }
            }

            for (j = 0; j < NY; j++) {
                for (i = 0; i < NX; i++) {
                    fprintf (pipe, "%g ", (-tmp[i * NY + j] + sum[i]/NY)/3276.8);
                }
                fprintf(pipe, "\n");
            }
            fprintf(pipe, "e\n");
            fprintf(pipe, "e\n");
            fflush (pipe);

#  ifdef _GNUPLOT_INTERACTIVE
            printf ("Press [Enter] to continue . . .");
            fflush (stdout);
            getchar ();
#  endif

            free(sum);
        }


#else        // Option 2: BP writing

        snprintf (outfn, sizeof(outfn), "reader_%3.3d.bp", steps);
        adios_open (&adios_handle, "reader", outfn, "w", comm);
        adios_groupsize = 4 * sizeof(int) + sizeof(double) * len * NY; 
        adios_group_size (adios_handle, adios_groupsize, &adios_totalsize);
        adios_write (adios_handle, "NX", &NX);
        adios_write (adios_handle, "NY", &NY);
        adios_write (adios_handle, "len", &len);
        adios_write (adios_handle, "off", &off);
        adios_write (adios_handle, "var", t);
        adios_close (adios_handle);

#endif        

        // Advance
        MPI_Barrier (comm);
        adios_advance_step(fp, 0, TIMEOUT_SEC);
        if (adios_errno == err_end_of_stream)
        {
            printf("rank %d, Stream terminated. Quit\n", rank);
            break; // quit while loop
        }
        else if (adios_errno == err_step_notready)
        {
            printf ("rank %d: No new step arrived within the timeout. Quit.\n", rank);
            break; // quit while loop
        }
        else if (adios_errno != err_no_error) {
            printf("ADIOS returned code=%d, msg:%s\n", 
                    adios_errno, adios_get_last_errmsg()); 
            break; // quit while loop
        }
    }
    //
    free(t);

    adios_read_close(fp);
    //printf("rank %d, Successfully closed stream\n", rank);

    adios_read_finalize_method(ADIOS_READ_METHOD_FLEXPATH);
    //printf("rank %d, Successfully finalized read method\n", rank);

#ifndef _USE_GNUPLOT
    adios_finalize (rank);
    //printf("rank %d, Successfully finalized adios\n", rank);
#else
    if (rank==0) {
        free(tmp);
        pclose(pipe);
    }
#endif

    MPI_Finalize ();

    return 0;
}
int main(int argc, char ** argv)
{
    int rank, size, varid, numvars;
    int bins, step, mod;
    char *filename, *in_stream, *data_var_name;
    MPI_Comm comm = MPI_COMM_WORLD;
    enum ADIOS_READ_METHOD method = ADIOS_READ_METHOD_FLEXPATH;
    //enum ADIOS_READ_METHOD method = ADIOS_READ_METHOD_BP;
    ADIOS_SELECTION * global_range_select;
    double *data;
    uint64_t tstep, global_size, mysize, mystart, sz;

    MPI_Init (&argc, &argv);
    MPI_Comm_rank(comm, &rank);
    MPI_Comm_size(comm, &size);

    /* Command line parsing */
    if (rank == 0 && argc < 4) {
      fprintf(stderr, "\nHistogram usage: <exec> input-stream-name num-bins" 
         " arr1 [arr2] [arr3] [...]\n"
         "\t where arr1, arr2, arr3 ... are the names of the arrays to be analyzed.\n");
      MPI_Abort(comm, -1);
    }
    MPI_Barrier(comm); 
    in_stream = argv[1];

    //Parse cmd line
    bins = atoi(argv[2]);
    numvars = argc - 3;
    const char *vars[numvars];
    for (varid=0; varid < numvars; varid++)
    {
      vars[varid] = argv[varid + 3];
    }

    /* Adios open and init */
    adios_read_init_method (method, comm, "verbose=1");
    ADIOS_FILE * f = adios_read_open (in_stream, method, comm, ADIOS_LOCKMODE_ALL, -1);
    step = 0; //not used now
    while (adios_errno != err_end_of_stream){
      //resource monitor

      /*loop over different arrays inside stream*/
      for (varid = 0; varid < numvars; varid++){         
#ifdef ENABLE_MONITOR
        //double t1 = wfgettimeofday();
        lib_mem_init();
        ind_timer_start(0, "whole timestep");
#endif
        //Init variables....
        global_size = 0; tstep = 0;
        mod = 0; mysize = 0; mystart = 0;
        adios_schedule_read (f, NULL, "ntimestep", 0, 1, &tstep);
        adios_perform_reads (f, 1);
        ADIOS_VARINFO * glob_info = adios_inq_var (f, vars[varid]);
        global_size = glob_info->dims[0];
        //printf("[DEBUG] global_size = %" PRIu64 " ntimestep = %" PRIu64 "\n", 
        //  global_size, tstep);

        //printf("[HIST%d] received data for timestep %" PRIu64 " with ndim: %d and globalsize:%"
        //    PRIu64 " \n", rank, tstep, ndim, global_size); 
        //sleep(800);
        //debug
        //Array slice computation
        mod = global_size % size;//size = MPI size
        if (mod == 0){
          mysize = global_size / size;
          mystart = mysize * rank;
        }
        else {
          mysize = global_size / (size);
          if (rank < mod){
            mysize++;
            mystart = mysize * rank;
          }
          else {
            mystart = (mod * (mysize + 1)) +
                      ((rank - mod) * mysize);
          }
        }

#ifdef ENABLE_MONITOR
        nohandler_mem(rank);
#endif

        //printf("[HISTO%d]: mysize = %" PRIu64" mystart = %" PRIu64 "\n", rank, mysize, mystart);
        //debug
        //if (step == 0) sleep(800);
        uint64_t starts[] = {mystart};
        uint64_t counts[] = {mysize};
        global_range_select = adios_selection_boundingbox (1, starts, counts);
        
        //Allocate space for arrays
        uint64_t msize = ((uint64_t) sizeof(double) * mysize);
        //printf("[DEBUG] mysize = %" PRIu64 " msize= %" PRIu64" \n", mysize, msize);
        //data = (double *) malloc(sizeof(double) * mysize);
        data = new double[mysize];
        if (data == NULL){
          //printf("DEBUG: malloc returned NULL, size was %d\n", msize);
        }
        else {
          if (rank == 0)
            printf("[HIST0] DEBUG: malloc successful, size was %d\n", mysize);
        }
        //memset (data, 0, sizeof(double) * mysize);

        //Read data
        adios_schedule_read (f,
                             global_range_select,
                             vars[varid],
                             0, 1, data);
        adios_perform_reads 

        (f, 1);
        
#ifdef ENABLE_MONITOR
        nohandler_mem(rank);
#endif

        //printf("PERFORM_READS success of variable: %s\n", vars[varid]); 
        /*
           Data check


        if (step == 4) {
          FILE *fp;
          char *log;
          asprintf(&log, "histo-input%d-%d.log", step, rank);
          fp = fopen(log, "w");
          fprintf(fp, "timestep: %" PRIu64 " mysize: %"PRIu64 "\n", 
              tstep, mysize);
          for (i=0; i<(int)mysize; i++){
            fprintf(fp, "%lf\n", data[i]);
          }
          fclose(fp);
          sleep(800);
        }
        */

         
        // find max and min
        sz = 0;
        sz = mysize; 
        double min = data[0];
        double max = data[0];
        for (uint64_t i = 1; i < sz; ++i)
        {
            if (data[i] > max) max = data[i];
            if (data[i] < min) min = data[i];
        }//local max, min found.
        //local data should just use shared mem.


        double g_min, g_max;

        // Find the global max/min
        MPI_Allreduce (&min, &g_min, 1, MPI_DOUBLE, MPI_MIN, comm);
        MPI_Allreduce (&max, &g_max, 1, MPI_DOUBLE, MPI_MAX, comm);

        //printf("[HIST%d] glob-min: %f, glob-max: %f\n", rank, g_min, g_max);
        
        nohandler_mem(rank);

        double width = (g_max - g_min)/bins;
        std::vector<uint64_t>   hist(bins);
        for (uint64_t i = 0; i < sz; ++i)//fill local bins
        {
            //printf("[HISTO%d] local filling adding index %" PRIu64 "\n", rank, i);
            int idx = int((data[i] - g_min)/width);//discover index
            if (idx == bins)        // we hit the max
                --idx;
            //printf("[%d]: %f -> %d\n", rank, data[i], idx);
            ++hist[idx];
        }

        delete[] data;
        // Global reduce histograms
        std::vector<uint64_t> g_hist(bins);
        MPI_Reduce(&hist[0], &g_hist[0], bins, MPI_UINT64_T, MPI_SUM, 0, comm);
        
        //debug
        //printf("[Completed histogram routine]\n");

        if (rank == 0) //print histogram to file
        {
          FILE *fp;
          const char *log = "histograms.log";
          fp = fopen(log, "a");
          fprintf(fp, "Histogram for %s, timestep %" PRIu64"\n", vars[varid], tstep);
          for (int i = 0; i < bins; ++i)
            fprintf(fp, "  %f-%f: %" PRIu64 "\n", g_min + i*width, g_min + (i+1)*width, g_hist[i]);
          fclose (fp);
        }

#ifdef ENABLE_MONITOR
        nohandler_mem(rank);
#endif

        if (rank == 0) //print histogram to terminal
        {
          printf("Histogram for %s, timestep %" PRIu64"\n", vars[varid], tstep);
          for (int i = 0; i < bins; ++i)
            printf("  %f-%f: %" PRIu64 "\n", 
              g_min + i*width, g_min + (i+1)*width, g_hist[i]);
        }
        
        //resource monitor
#ifdef ENABLE_MONITOR
        //double t2 = wfgettimeofday();
        ind_timer_end(0);
        char monitor_title[40];
        sprintf(monitor_title, "histogram-%s", vars[varid]);
        monitor_out (rank, size, tstep, msize, t1, t2, comm, monitor_title);
#endif
      }
      //end of read + analysis for 3 variables


      
      adios_release_step(f);
      //delete[] data;
      if (rank == 0) printf("[HIST%d] read and wrote data for timestep %" PRIu64 "\n", rank, tstep);

      step++;
      adios_advance_step(f, 0, -1);
      /*
      if (step == 6){ 
        double t1 = wfgettimeofday();
        FILE *tfp;
        tfp = fopen("time.log", "a");
        fprintf(tfp, "rank %d histogram end time: %f\n", rank, t1);
        fclose(tfp);
      }
      */ 
    }//end of adios stream while loop
    if (rank == 0) printf("[HIST%d] out of read loop\n", rank);
    /* performance measurement */
    /*
    if (rank == 0){ 
      double t3 = wfgettimeofday();
      FILE *tfp;
      tfp = fopen("time.log", "a");
      fprintf(tfp, "master histogram end time: %f\n", t3);
      fclose(tfp);
    }
    */
#ifdef ENABLE_MONITOR
    outer_timer_end(rank, "histogram");
#endif
    adios_read_close(f);
    adios_read_finalize_method(method);
    MPI_Finalize();
    return 0;
}
예제 #29
0
파일: testxgc.cpp 프로젝트: applekey/EAVL
eavlDataSet *ReadPsiMesh(const string &filename)
{
    MPI_Comm comm_dummy = 0;
    ADIOS_FILE *fp = adios_read_open_file(filename.c_str(), ADIOS_READ_METHOD_BP, comm_dummy);

    int nNodes = 0, nElems = 0, ptID = -1, elemID = -1;
    ADIOS_VARINFO *points = NULL, *cells = NULL, *psi;
    for (int i = 0; i < fp->nvars; i++)
    {
	ADIOS_VARINFO *avi = adios_inq_var_byid(fp, i);
	string varNm(&fp->var_namelist[i][1]);
	if (varNm == "n_t")
	{
	    nElems = (int)(*(int *)avi->value);
	    adios_free_varinfo(avi);
	}
	else if (varNm == "n_n")
	{
	    nNodes = (int)(*(int *)avi->value);
	    adios_free_varinfo(avi);
	}
	else if (varNm == "coordinates/values")
	    points = avi;
	else if (varNm == "cell_set[0]/node_connect_list")
	    cells = avi;
	else if (varNm == "psi")
	    psi = avi;
	else
	    adios_free_varinfo(avi);
    }
    cout<<"nNodes= "<<nNodes<<" nTri= "<<nElems<<endl;

    eavlDataSet *out = new eavlDataSet;
    out->SetNumPoints(nNodes);
    eavlCoordinatesCartesian *coords = new eavlCoordinatesCartesian(NULL,
								    eavlCoordinatesCartesian::X,
								    eavlCoordinatesCartesian::Y);
    out->AddCoordinateSystem(coords);
    coords->SetAxis(0, new eavlCoordinateAxisField("xcoords", 0));
    coords->SetAxis(1, new eavlCoordinateAxisField("ycoords", 0));
	
    eavlArray *axisValues[2] = {new eavlFloatArray("xcoords", 1),
				new eavlFloatArray("ycoords", 1)};
    axisValues[0]->SetNumberOfTuples(nNodes);
    axisValues[1]->SetNumberOfTuples(nNodes);
    //read points.
    double *buff = new double[2*nNodes];
    uint64_t s[3], c[3];
    ADIOS_SELECTION *sel = MakeSelection(points, s, c);
    adios_schedule_read_byid(fp, sel, points->varid, 0, 1, buff);
    int retval = adios_perform_reads(fp, 1);
    adios_selection_delete(sel);
    adios_free_varinfo(points);

    for (int i = 0; i < nNodes; i++)
    {
	axisValues[0]->SetComponentFromDouble(i, 0, buff[i*2 +0]);
	axisValues[1]->SetComponentFromDouble(i, 0, buff[i*2 +1]);
    }
    out->AddField(new eavlField(1, axisValues[0], eavlField::ASSOC_POINTS));
    out->AddField(new eavlField(1, axisValues[1], eavlField::ASSOC_POINTS));
    delete [] buff;

    eavlCellSetExplicit *cellSet = new eavlCellSetExplicit("2D_cells", 2);
    eavlExplicitConnectivity conn;

    //read cells
    int *nodeList = new int[nElems*3];
    sel = MakeSelection(cells, s, c);
    adios_schedule_read_byid(fp, sel, cells->varid, 0, 1, nodeList);
    retval = adios_perform_reads(fp, 1);
    adios_selection_delete(sel);

    int nodes[3];
    for (int i = 0; i < nElems; i++)
    {
	nodes[0] = nodeList[i*3+0];
	nodes[1] = nodeList[i*3+1];
	nodes[2] = nodeList[i*3+2];
	conn.AddElement(EAVL_TRI, 3, nodes);
    }
    delete [] nodeList;
    cellSet->SetCellNodeConnectivity(conn);
    out->AddCellSet(cellSet);

    //read psi.
    buff = new double[nNodes];
    sel = MakeSelection(psi, s, c);
    adios_schedule_read_byid(fp, sel, psi->varid, 0, 1, buff);
    retval = adios_perform_reads(fp, 1);
    adios_selection_delete(sel);
    adios_free_varinfo(psi);

    eavlArray *psiValues = new eavlFloatArray("psi", 1);
    psiValues->SetNumberOfTuples(nNodes);
    for (int i = 0; i < nNodes; i++)
	psiValues->SetComponentFromDouble(i, 0, buff[i]);
    out->AddField(new eavlField(1, psiValues, eavlField::ASSOC_POINTS));
    delete [] buff;
	
    return out;
}
예제 #30
0
int main (int argc, char ** argv) 
{
    int         rank, size, i, j;
    MPI_Comm    comm = MPI_COMM_WORLD;
    enum ADIOS_READ_METHOD method = ADIOS_READ_METHOD_BP;
    ADIOS_SELECTION * sel;
    void * data = NULL;
    uint64_t start[2], count[2];

    MPI_Init (&argc, &argv);
    MPI_Comm_rank (comm, &rank);
    MPI_Comm_size (comm, &size);

    adios_read_init_method (method, comm, "verbose=4");
    adios_logger_open ("log_read_C", rank);

    ADIOS_FILE * f = adios_read_open ("global_array_C.bp", method, comm, ADIOS_LOCKMODE_NONE, 0);
    if (f == NULL)
    {
        log_error ("%s\n", adios_errmsg());
        return -1;
    }

    ADIOS_VARINFO * v = adios_inq_var (f, "temperature");

    /* Using less readers to read the global array back, i.e., non-uniform */
    uint64_t slice_size = v->dims[0]/size;
    start[0] = slice_size * rank;
    if (rank == size-1) /* last rank may read more lines */
        slice_size = slice_size + v->dims[0]%size;
    count[0] = slice_size;

    start[1] = 0;
    count[1] = v->dims[1];
       

    data = malloc (slice_size * v->dims[1] * sizeof (double));
    if (data == NULL)
    {
        log_error (stderr, "malloc failed.\n");
        return -1;
    }

    /* Read a subset of the temperature array */
    sel = adios_selection_boundingbox (v->ndim, start, count);
    adios_schedule_read (f, sel, "temperature", 0, 1, data);
    adios_perform_reads (f, 1);

    for (i = 0; i < slice_size; i++) {
        log_test ("rank %d: [%lld,%d:%lld]", rank, start[0]+i, 0, slice_size);
        for (j = 0; j < v->dims[1]; j++)
            log_test (" %6.6g", * ((double *)data + i * v->dims[1] + j));
        log_test ("\n");
    }

    free (data);

    adios_read_close (f);
    MPI_Barrier (comm);
    adios_read_finalize_method (method);
    adios_logger_close();
    MPI_Finalize ();
    return 0;
}