Beispiel #1
0
eavlXGCImporter::eavlXGCImporter(const string &filename)
{
    nNodes = 0;
    nPlanes = 0;
    nElems = 0;
    fp = NULL;
    mesh_fp = NULL;
    points = NULL;
    cells = NULL;
    
    string::size_type i0 = filename.rfind("xgc.");
    string::size_type i1 = filename.rfind(".bp");
    string meshname = filename.substr(0,i0+4) + "mesh.bp";
    
    MPI_Comm comm_dummy = 0;
    fp = adios_read_open_file(filename.c_str(), ADIOS_READ_METHOD_BP, comm_dummy);
    mesh_fp = adios_read_open_file(meshname.c_str(), ADIOS_READ_METHOD_BP, comm_dummy);
    
    if (fp == NULL)
	THROW(eavlException, "XGC variable file not found.");
    if (mesh_fp == NULL)
	THROW(eavlException, "XGC mesh file not found.");

    Initialize();
}
Beispiel #2
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;
}
Beispiel #3
0
ToolsAdiosParallel::ToolsAdiosParallel(ProgramOptions &options, Dims &mpiTopology, std::ostream &outStream) :
ITools(options, mpiTopology, outStream), errorStream(std::cerr)
{
    if (m_options.verbose)
        errorStream << m_options.inputFile << std::endl;

    comm = MPI_COMM_WORLD;
    pFile = adios_read_open_file(m_options.inputFile.c_str(), ADIOS_READ_METHOD_BP, comm);
}
Beispiel #4
0
/// Test if the file is present.  This function accomplishes its task by
/// actually attempting to open it.  It returns true if the open attempt
/// was successful, returns false otherwise.
bool ADIOS_File::exists(const std::string& fileName)
{
    ADIOS_FILE* f = adios_read_open_file
        (fileName.c_str(), ADIOS_READ_METHOD_BP, MPI_COMM_WORLD);
    if (f != 0) {
        adios_read_close(f);
        return true;
    }
    return false;
}
AdiosCheckpointInput::AdiosCheckpointInput(std::string& checkpoint_file)
{
  adios_read_init(method, OHMMS::Controller->getMPI(), "verbose=3;abort_on_error");
  adios_file_handle = adios_read_open_file(checkpoint_file.c_str(), method,
                      comm);
  if (adios_file_handle == NULL)
  {
    qmcplusplus::app_error() << adios_errmsg() << std::endl;
  }
  //Select for local values
  sel = adios_selection_writeblock (OHMMS::Controller->rank());
}
eavlXGCParticleImporter::eavlXGCParticleImporter(const string &filename)
{
    timestep = 0;
    maxnum = 0;
    enphase = 0;
    inphase = 0;
    emaxgid = 0;
    imaxgid = 0;
    nvars = 0;
    time = 0;
    retVal = 0;
    totalIParticles = 0;
    totalEParticles = 0;
    iphaseAvail = 0;
    ephaseAvail = 0;
    fp = NULL;
    getR = true;
    getZ = true;
    getPhi = true;
    getRho = true;
    getW1 = true;
    getW2 = true;
    getMu = true;
    getW0 = true;
    getF0 = true;
    getOriginNode = true;


    std::string key (".restart");
    std::size_t found = filename.find(key);
    if(found != std::string::npos)
        readingRestartFile = 1;
    else
        readingRestartFile = 0;


    MPI_Comm comm_dummy = comm = 0;
    char    hostname[MPI_MAX_PROCESSOR_NAME];
    char    str [256];
    int     len = 0;

    //Set local mpi vars so we know how many minions there are, and wich we are
    MPI_Comm_size(comm,&numMPITasks);
    MPI_Comm_rank(comm,&mpiRank);
    MPI_Get_processor_name(hostname, &len);

    fp = adios_read_open_file(filename.c_str(), ADIOS_READ_METHOD_BP, comm_dummy);

    if(fp == NULL)
        THROW(eavlException, "XGC variable file not found.");

    Initialize();
}
Beispiel #7
0
bool ADIOS1CommonRead::Open()
{
    if (m_OpenAsFile)
    {
        m_fh =
            adios_read_open_file(m_FileName.c_str(), m_ReadMethod, m_MPIComm);
    }
    else
    {
        m_fh = adios_read_open(m_FileName.c_str(), m_ReadMethod, m_MPIComm,
                               ADIOS_LOCKMODE_CURRENT, 0.0);
    }
    return (m_fh != NULL);
}
static void test_file_mode_reads(const char *bp_filename) {
	int i;
	ADIOS_FILE *fp = adios_read_open_file(bp_filename, ADIOS_READ_METHOD_BP, COMM);
	MPI_Assert(COMM, fp);

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

	for (i = 0; i < fp->nvars; ++i) {
		const char *varname = fp->var_namelist[i];
		test_file_mode_reads_on_var(fp, bp_filename, varname);

		MPI_Barrier(COMM);
	}

	adios_read_close(fp);

	fprintf(stderr, "[rank %d/%d] Finished file-mode writeblock reads on %s\n", rank, size, bp_filename);
}
Beispiel #9
0
/// Open the named file in read-only mode.  If a write operation is
/// desired, the caller is expected to close this file and call adios_open
/// explicitly.  This object is used to carry the file name when any write
/// operations are to be performed.  Furthermore, the file is always open
/// in streaming mode.
void ADIOS_File::open(const std::string &fn, ADIOS_READ_METHOD rm,
                      float to, bool strm)
{
    const char *cptr = (fn.empty() ? m_fname.c_str() : fn.c_str());
    if (*cptr == 0) // can not proceed with a valid file name
        return;

    if (m_handle)
        (void) adios_read_close(m_handle);

    if (strm) { // variables are visible one step at a time
        m_handle = adios_read_open_stream
            (cptr, rm, m_comm, ADIOS_LOCKMODE_CURRENT, to);
        if (m_handle != 0) { // successfully opened the stream for reading
            if (m_fname.compare(cptr) != 0)
                m_fname = cptr;
            LOGGER(ibis::gVerbose > 4)
                << "ADIOS_File::open(" << m_fname
                << ") successfully opened the name file in streaming mode";
        }
        else {
            LOGGER(ibis::gVerbose >= 0)
                << "Warning -- ADIOS_File::open(" << cptr
                << ") failed to locate an active stream";
        }
    }
    else { // open_file makes all variables visible at once
        if (m_fname.compare(cptr) != 0)
            m_fname = cptr;
        m_handle = adios_read_open_file(cptr, rm, m_comm);
        if (m_handle != 0) {
            LOGGER(ibis::gVerbose > 4)
                << "ADIOS_File::open(" << m_fname
                << ") opened the named file for reading";
        }
        else {
            LOGGER(ibis::gVerbose >= 0)
                << "Warning -- ADIOS_File::open(" << cptr
                << ") failed to open the named file in read-only mode";
        }
    }
} // ADIOS_File::open
Beispiel #10
0
int main (int argc, char ** argv) 
{
	char        filename [256];
	int         rank, size, i;
	int         NX = 4096; 
	double      t[NX];
	MPI_Comm    comm = MPI_COMM_WORLD;

	/* ADIOS variables declarations for matching gwrite_temperature.ch */
	ADIOS_FILE *fp;
	ADIOS_SELECTION *s;

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

	strcpy (filename, "adios_global.bp");

    //adios_read_init_method (ADIOS_READ_METHOD_BP, comm, "");

    fp = adios_read_open_file ("adios_global.bp", ADIOS_READ_METHOD_BP, comm);

    #include "gread_temperature.ch"

    adios_read_close (fp);

    // Verify data
	for (i = 0; i < NX; i++)
		if (t[i] != rank*NX + i)
        {
            fprintf (stderr, "Error detected\n");
        }

    
    adios_read_finalize_method (ADIOS_READ_METHOD_BP);

	MPI_Finalize ();
	return 0;
}
Beispiel #11
0
int read_scalar ()
{
    ADIOS_FILE * f;
    float timeout_sec = 0.0; 
    int steps = 0;
    int retval = 0;
    MPI_Comm    comm = MPI_COMM_SELF;

    adios_read_init_method (ADIOS_READ_METHOD_BP, comm, "verbose=3");
    printf ("\n--------- Read all instances of the scalar 'O'  ------------\n");
    f = adios_read_open_file (fname, ADIOS_READ_METHOD_BP, comm);
    if (f == NULL) {
        printf ("Error at opening file: %s\n", adios_errmsg());
        retval = adios_errno;
    }
    else
    {
        /* Read the scalar O with writeblock selection */
        print_scalar (f, "O");
        adios_read_close (f);
    }
    adios_read_finalize_method (ADIOS_READ_METHOD_BP);
    return retval;
}
Beispiel #12
0
int read_all ()
{
        ADIOS_FILE * f;
        float timeout_sec = 0.0; 
        int steps = 0;
    int retval = 0;
    MPI_Comm    comm = MPI_COMM_SELF;

    adios_read_init_method (ADIOS_READ_METHOD_BP, comm, "verbose=3");
    printf ("\n--------- Read as file  ------------\n");
    f = adios_read_open_file (fname, ADIOS_READ_METHOD_BP, comm);
    if (f == NULL) {
        printf ("Error at opening file: %s\n", adios_errmsg());
        retval = adios_errno;
    }
    else
    {
        /* Processing all the steps at once */
        print_varinfo (f, 0);
        adios_read_close (f);
    }
    adios_read_finalize_method (ADIOS_READ_METHOD_BP);
    return retval;
}
//Reads an adios restart file :: can only be instantiated if EAVL was built
//with MPI enabled!
eavlXGCParticleImporter::eavlXGCParticleImporter(   const string &filename,
        ADIOS_READ_METHOD method,
        MPI_Comm communicator,
        ADIOS_LOCKMODE mode,
        int timeout_sec
                                                )
{
    timestep = 0;
    maxnum = 0;
    enphase = 0;
    inphase = 0;
    emaxgid = 0;
    imaxgid = 0;
    nvars = 0;
    time = 0;
    retVal = 0;
    totalIParticles = 0;
    totalEParticles = 0;
    fp = NULL;
    fp = NULL;
    getR = true;
    getZ = true;
    getPhi = true;
    getRho = true;
    getW1 = true;
    getW2 = true;
    getMu = true;
    getW0 = true;
    getF0 = true;
    getOriginNode = true;
    comm = communicator;


    std::string key (".restart");
    std::size_t found = filename.find(key);
    if(found != std::string::npos)
        readingRestartFile = 1;
    else
        readingRestartFile = 0;

    char    hostname[MPI_MAX_PROCESSOR_NAME];
    char    str [256];
    int     len = 0;

    //Set local mpi vars so we know how many minions there are, and wich we are
    MPI_Comm_size(comm,&numMPITasks);
    MPI_Comm_rank(comm,&mpiRank);
    MPI_Get_processor_name(hostname, &len);

    if(method == ADIOS_READ_METHOD_BP) //do not open stream if not staging
        fp = adios_read_open_file(filename.c_str(), method, comm);
    else
        fp = adios_read_open(filename.c_str(), method, comm, mode, timeout_sec);

    if (fp == NULL)
    {
        cerr << __LINE__ << endl;
        if(adios_errno == err_end_of_stream)
        {
            printf ("End of stream, no more steps expected. Quit. %s\n",
                    adios_errmsg()
                   );
        }
        else
        {
            printf ("No new step arrived within the timeout. Quit. %s\n",
                    adios_errmsg()
                   );
            THROW(eavlException, "XGC variable file not found.");
        }
    }
    Initialize();
}
Beispiel #14
0
int main (int argc, char** argv) 
{
  fastbit_init(0);
  fastbit_set_verbose_level(0);

  ADIOS_FILE * f;
  //MPI_Comm    comm_dummy = 0;  // MPI_Comm is defined through adios_read.h 
  MPI_Comm comm_dummy = MPI_COMM_WORLD;

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

  adios_init_noxml (comm_dummy);
  
  if (argc < 2) {
    printf("Usage: index_fastbit fileName (attrName)");
    return 0;
  }

  f = adios_read_open_file (argv[1], ADIOS_READ_METHOD_BP, comm_dummy);
  if (f == NULL) {
    printf ("::%s\n", adios_errmsg());
    return -1;
  }
  
  /*
  adios_allocate_buffer (ADIOS_BUFFER_ALLOC_NOW, (f->file_size)*2/1048576 + 5); // +5MB for extra room in buffer
  adios_declare_group (&gAdios_group, gGroupNameFastbitIdx, "", adios_flag_yes);
  adios_select_method (gAdios_group, "MPI", "", "");
  */
  gIdxFileName = fastbit_adios_util_getFastbitIndexFileName(argv[1]);
  unlink(gIdxFileName);

      adios_allocate_buffer (ADIOS_BUFFER_ALLOC_NOW, 500); // +5MB for extra room in buffer
      adios_declare_group (&gAdios_group, gGroupNameFastbitIdx, "", adios_flag_yes);
      adios_select_method (gAdios_group, "MPI", "", "");

      adios_open (&gAdios_write_file, gGroupNameFastbitIdx, gIdxFileName, "w", MPI_COMM_WORLD);

#ifdef MULTI_BLOCK
      int testid = adios_define_var (gAdios_group, "pack", "", adios_integer , 0, 0, 0);
#endif
#ifdef BOX
      int testid = adios_define_var (gAdios_group, "elements", "", adios_integer , 0, 0, 0);
#endif
      //uint64_t estimatedbytes = (nb+nk+no)*adios_type_size(adios_double, NULL);
      int jobCounter = getJobCounter(f);
      uint64_t estimatedbytes =  getByteEstimationOnFile(f, rank);
      if (size > 1) {
	int maxJobsPP = jobCounter/size + 1;
        estimatedbytes = estimatedbytes * maxJobsPP /jobCounter +1048576;
      }

      estimatedbytes += 1048576;

      uint64_t adios_totalsize;      // adios_group_size needs to be call before any write_byid, Otherwise write_byid does nothing 
      adios_group_size (gAdios_write_file, estimatedbytes , &adios_totalsize);     

      printf("=> .. adios open output file: %s, rank %d allocated %" PRIu64 " bytes... \n", gIdxFileName, rank, adios_totalsize);
      // IMPORTANT: 
      // can only call open/close once in a process
      // otherwise data is tangled or only the data in the last open/close call is recorded

#ifdef MULTI_BLOCK
      adios_write_byid(gAdios_write_file, testid, &pack);
#endif
#ifdef BOX
      adios_write_byid(gAdios_write_file, testid, &recommended_index_ele);
#endif


  sumLogTime(-1);
  sumLogTimeMillis(-1);

  
  if (argc >= 3) {
     int i=2;
     while (i<argc) {
        const char* varName = argv[i];
	if(strstr(varName, "<binning prec") != NULL) {
	  if (gBinningOption == NULL) {
	    gBinningOption = argv[i];
	  }
	  if (argc == 3) {
	    buildIndexOnAllVar(f, rank, size);
	    break;
	  }
	  i++;
	  continue;
	} else {
	  ADIOS_VARINFO * v = adios_inq_var(f, varName);
	  if (v == NULL) {
	     printf("No such variable: %s\n", varName);
	     return 0;
	   }	
	  printf("building fastbit index on  variable: %s\n", varName);
	  buildIndex_mpi(f, v, rank, size);
	  adios_free_varinfo(v);
	  i++;
	}
     }
  } else {
    buildIndexOnAllVar(f, rank, size);
  }


  sumLogTime(0);
  sumLogTimeMillis(0);

  adios_close(gAdios_write_file);
  adios_read_close(f);

  //
  // writing file clean up
  //


  // read back:
  f = adios_read_open_file (gIdxFileName, ADIOS_READ_METHOD_BP, comm_dummy);
  if (f == NULL) {
    printf("No such file: %s \n", gIdxFileName);
    return 0;
  }

  int numVars = f->nvars;
  
  int i=0;
  int k=0;
  int j=0;
  for (i=0; i<numVars; i++) {
      char* varName = f->var_namelist[i];
      ADIOS_VARINFO* v = adios_inq_var(f, varName);

       adios_inq_var_blockinfo(f,v);      
      int timestep = 0;
      for (k=0; k<v->sum_nblocks; k++) {
	  verifyData(f, v, k, timestep);
      }

      adios_free_varinfo(v);
  }

  adios_read_close(f);

  if (rank == 0) {
    printf(" ==>  index file is at: %s\n", gIdxFileName);
  }

  // clean up
  MPI_Barrier (comm_dummy);
  adios_finalize (rank);
  MPI_Finalize ();
  free (gIdxFileName);

  fastbit_cleanup();
  return 0;
}
Beispiel #15
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;
}
Beispiel #16
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;
}
Beispiel #17
0
int main (int argc, char ** argv) 
{
    int         i, j, k,l;
    MPI_Comm    comm_dummy = 0;  /* MPI_Comm is defined through adios_read.h */

    if (argc < 2) {
        printf("Usage: %s <BP-file>\n", argv[0]);
        return 1;
    }

    adios_read_init_method (ADIOS_READ_METHOD_BP, comm_dummy, "show_hidden_attrs");
    ADIOS_FILE * f;
    f = adios_read_open_file (argv[1], ADIOS_READ_METHOD_BP, comm_dummy);
    if (f == NULL) {
        printf ("%s\n", adios_errmsg());
        return -1;
    }

    /* For all variables */
    printf("  Variables=%d:\n", f->nvars);
    for (i = 0; i < f->nvars; i++) {
        ADIOS_VARINFO * v = adios_inq_var_byid (f, i);
        adios_inq_var_stat (f, v, 0, 1);
        adios_inq_var_blockinfo (f, v);

        uint64_t total_size = adios_type_size (v->type, v->value);
        for (j = 0; j < v->ndim; j++)
            total_size *= v->dims[j];

        printf("    %-9s  %s", adios_type_to_string(v->type), f->var_namelist[i]);
        if (v->ndim == 0) {
            /* Scalars do not need to be read in, we get it from the metadata
               when using adios_inq_var */
            printf(" = %s\n", value_to_string(v->type, v->value, 0));
        } else {
            /* Arrays, print min/max statistics*/
            printf("[%lld",v->dims[0]);
            for (j = 1; j < v->ndim; j++)
                printf(", %lld",v->dims[j]);
            //printf("] = \n");

            if (v->type == adios_integer)
                printf("] : min=%d  max=%d\n", 
                        (*(int*)v->statistics->min), (*(int*)v->statistics->max));
            else if (v->type == adios_double)
                printf("] : min=%lg  max=%lg\n", 
                        (*(double*)v->statistics->min), (*(double*)v->statistics->max));

            /* Print block info */
            for (l=0; l<v->nsteps; l++) {
                printf("        step %3d: \n", l);
                for (j=0; j<v->nblocks[l]; j++) {
                    printf("          block %3d: [", j);
                    for (k=0; k<v->ndim; k++) {
                        printf("%3lld:%3lld", v->blockinfo[j].start[k],
                                v->blockinfo[j].start[k]+v->blockinfo[j].count[k]-1);
                        if (k<v->ndim-1)
                            printf(", ");
                    }
                    printf("]\n");
                }
            }

        }

        adios_free_varinfo (v);
    } /* variables */

    /* For all attributes */
    printf("  Attributes=%d:\n", f->nattrs);
    for (i = 0; i < f->nattrs; i++) {
        enum ADIOS_DATATYPES atype;
        int  asize;
        void *adata;
        adios_get_attr_byid (f, i, &atype, &asize, &adata);
        printf("    %-9s  %s = %s\n", adios_type_to_string(atype), 
                f->attr_namelist[i], value_to_string(atype, adata, 0));
        free(adata);
    } /* attributes */

    adios_read_close (f);

    return 0;
}
Beispiel #18
0
int main(int argc, char ** argv) {

    char xmlFileName[256];
    enum ADIOS_READ_METHOD method = ADIOS_READ_METHOD_BP;

    MPI_Comm comm = MPI_COMM_WORLD;

    ADIOS_QUERY_TEST_INFO *queryInfo;
    ADIOS_FILE *f;


    MPI_Init(&argc, &argv);

    if (argc < 4 || argc > 7) {
        fprintf(stderr," usage: %s {input bp file} {xml file} {query engine (ALACRITY/FASTBIT)} [mode (FILE/stream)] [print points? (TRUE/false)] [read results? (true/FALSE)]\n", argv[0]);
        MPI_Abort(comm, 1);
    }
    else {
        strcpy(xmlFileName,  argv[2]);
    }

    enum ADIOS_QUERY_METHOD query_method = ADIOS_QUERY_METHOD_UNKNOWN;
    if (strcasecmp(argv[3], "ALACRITY") == 0) {
        // init with ALACRITY
        //adios_query_init(ADIOS_QUERY_TOOL_ALACRITY);
    	query_method = ADIOS_QUERY_METHOD_ALACRITY;
    }
    else if (strcasecmp(argv[3], "FASTBIT") == 0) {
        // init with FastBit
    	query_method = ADIOS_QUERY_METHOD_FASTBIT;
    	//fprintf(stderr,"FastBit not supported in this test yet, exiting...\n");
    	//MPI_Abort(comm, 1);
    }
    else {
    	fprintf(stderr,"Unsupported query engine %s, exiting...\n", argv[3]);
        MPI_Abort(comm, 1);
    }

    const int use_streaming = (argc >= 5) && (strcasecmp(argv[4], "stream") == 0);
    const int read_results = (argc >= 6) && (strcasecmp(argv[5], "true") == 0);
    const int print_points = !(argc >= 7) || (strcasecmp(argv[6], "true") == 0);

    fprintf(stderr, "NOTE: Running the query in %s mode\n", use_streaming ? "STREAM" : "FILE");
    fprintf(stderr, "NOTE: %s print query result points\n", print_points ? "WILL" : "WILL NOT");
    fprintf(stderr, "NOTE: %s read data using query result point selection\n", read_results ? "WILL" : "WILL NOT");

    // ADIOS init
    adios_read_init_method(method, comm, NULL);

    f = use_streaming ?
    		adios_read_open(argv[1], method, comm, ADIOS_LOCKMODE_ALL, -1) :
    		adios_read_open_file(argv[1], method, comm);
    if (f == NULL) {
        fprintf(stderr," can not open file %s \n", argv[1]);
        MPI_Abort(comm, 1);
    }

    // Parse the xml file to generate query info
    queryInfo = parseXml(xmlFileName, f);

    // perform query
    adios_query_set_method(queryInfo->query, query_method);
    performQuery(queryInfo, f, use_streaming, print_points, read_results);


    adios_read_close(f);
    adios_read_finalize_method(ADIOS_READ_METHOD_BP);

    MPI_Finalize();
    return 0;
}
Beispiel #19
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;

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

    adios_read_init_method (method, comm, "verbose=3");
    ADIOS_FILE * f = adios_read_open_file("adios_stat.bp", method, comm);
    if (f == NULL)
    {
        fprintf (stderr, "%s\n", adios_errmsg());
        return -1;
    }

    ADIOS_VARINFO * v = adios_inq_var (f, "temperature");
    if (v) {
        /* get statistics, for each individual time-step */ 
        adios_inq_var_stat (f, v, 1, 0);


        printf("Global MIN of temperature: %lf\n", * (double *) v->statistics->min);
        printf("Global MAX of temperature: %lf\n", * (double *) v->statistics->max);
        printf("Global AVG of temperature: %lf\n", * (double *) v->statistics->avg);
        printf("Global STD DEV of temperature: %lf\n", * (double *) v->statistics->std_dev);

        printf("\n");
        printf("---------------------------------------------------------------------------\n");
        if (v->statistics->steps) {
            printf("MIN\t\tMAX\t\tAVG\t\tSTD_DEV\t\tHISTOGRAM\n");
            for(i = 0; i < v->nsteps; i++)
            {
                if (v->statistics->steps->mins[i]) 
                    printf("%lf\t", * (double *) v->statistics->steps->mins[i]);
                else
                    printf("--\t\t");
                if (v->statistics->steps->maxs[i]) 
                    printf("%lf\t", * (double *) v->statistics->steps->maxs[i]);
                else
                    printf("--\t\t");
                if (v->statistics->steps->avgs[i]) 
                    printf("%lf\t", * (double *) v->statistics->steps->avgs[i]);
                else
                    printf("--\t\t");
                if (v->statistics->steps->std_devs[i]) 
                    printf("%lf\t", * (double *) v->statistics->steps->std_devs[i]);
                else
                    printf("--\t\t");
                if (v->statistics->histogram) {
                    for(j = 0; j <= v->statistics->histogram->num_breaks; j++) {
                        printf("%d ", v->statistics->histogram->frequencies[i][j]);
                    }
                    printf("\n");
                } else {
                    printf("--\t\t");
                }
                printf("\n");
            }	
        } else {
            printf ("Per step statistics is missing\n"); 
        }
        printf("---------------------------------------------------------------------------\n");
        printf("\n");

        if (v->statistics->histogram) {
            printf("Break points:\t\t\t");
            for(j = 0; j < v->statistics->histogram->num_breaks; j++)
                printf("%6.2lf\t", v->statistics->histogram->breaks[j]);

            printf("\n");

            printf("Frequencies:\t\t\t");
            for(j = 0; j <= v->statistics->histogram->num_breaks; j++)
                printf("%6d\t", v->statistics->histogram->gfrequencies[j]);
        }

        printf("\n\n");

#if 0 
        printf ("Auto covariance of MIN values of temperature over time: %lf\n", adios_stat_cov (v, v, "min", 0, 12, 0));
        printf ("Auto correlation of MAX values of temperature over time, with lag 2 units: %lf\n", adios_stat_cor (v, v, "max", 0, 8, 2));
        printf("\n\n");
#endif 

        adios_free_varinfo (v);

    } else {
        fprintf (stderr, "ERROR: Cannot inquire statistics of variable 'temperature': %s\n", adios_errmsg());
    }

    v = adios_inq_var (f, "complex");
    if (v) {
        adios_inq_var_stat (f, v, 1, 0);
        double *C = v->statistics->min;
        printf("Global Minimum of variable complex - Magnitude: %lf\n", C[0]);
        printf("Global Minimum of variable complex - Real part: %lf\n", C[1]);
        printf("Global Minimum of variable complex - Imaginary part: %lfi\n", C[2]);

        double ** Cmin;
        Cmin = (double **) v->statistics->steps->mins;

        printf("\nMagnitude\t\tReal\t\t\tImaginary\n");
        for (j = 0; j < v->nsteps; j++)
        {
            printf ("%lf\t\t%lf\t\t%lf\n", Cmin[j][0], Cmin[j][1], Cmin[j][2]);
        }
        printf("\n");
        adios_free_varinfo (v);

    } else {
        fprintf (stderr, "ERROR: Cannot inquire statistics of variable 'complex': %s\n", adios_errmsg());
    }

    adios_read_close (f);
    MPI_Barrier (comm);
    adios_read_finalize_method (method);
    MPI_Finalize ();
    return 0;
}
Beispiel #20
0
int main (int argc, char ** argv) 
{
    char        filename [256];
    int         rank, size, i, j, k, token;
    MPI_Comm    comm = MPI_COMM_WORLD;
    MPI_Status  status;
    enum ADIOS_READ_METHOD method = ADIOS_READ_METHOD_BP;
    ADIOS_SELECTION * sel;
    void * data = NULL;
    uint64_t start[3], count[3], step = 0;

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

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

    /* adios_read_open_file() allows for seeing all timesteps in the file */
    ADIOS_FILE * f = adios_read_open_file ("adios_globaltime.bp", method, comm);
    if (f == NULL)
    {
        printf ("%s\n", adios_errmsg());
        return -1;
    }

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

    // read in two timesteps
    data = malloc (2 * v->dims[0] * v->dims[1] * sizeof (double));
    if (data == NULL)
    {
        fprintf (stderr, "malloc failed.\n");
        return -1;
    }

    // read in timestep 'rank' (up to 12)
    step = rank % 13;

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

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

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

    if (rank == 0) 
        printf ("Array size of temperature [0:%lld,0:%lld]\n", v->dims[0], v->dims[1]);   

    if (rank > 0) {
        MPI_Recv (&token, 1, MPI_INT, rank-1, 0, comm, &status);
    }

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

    if (rank < size-1) {
        MPI_Send (&token, 1, MPI_INT, rank+1, 0, comm);
    }

    free (data);
    adios_free_varinfo (v);

    adios_read_close (f);
    MPI_Barrier (comm);
    adios_read_finalize_method (method);
    MPI_Finalize ();
    return 0;
}
Beispiel #21
0
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;
}
Beispiel #22
0
int main (int argc, char ** argv) 
{
    int         i, j, k, l, t;
    MPI_Comm    comm_dummy = 0;  /* MPI_Comm is defined through adios_read.h */
    void      * data = NULL;
    uint64_t    start[] = {0,0,0,0,0,0,0,0,0,0};
    uint64_t    count[10];
    ADIOS_SELECTION *sel;

    if (argc < 2) {
        printf("Usage: %s <BP-file>\n", argv[0]);
        return 1;
    }

    ADIOS_FILE * f;
    //int step;
    //for (step=0; step < 2; step++) {
        f = adios_read_open_file (argv[1], ADIOS_READ_METHOD_BP, comm_dummy);
        if (f == NULL) {
            printf ("%s\n", adios_errmsg());
            return -1;
        }

        /* For all variables */
        printf("  Variables=%d:\n", f->nvars);
        for (i = 0; i < f->nvars; i++) {
            ADIOS_VARINFO * v = adios_inq_var_byid (f, i);
            adios_inq_var_stat (f, v, 0, 0);

            uint64_t total_size = adios_type_size (v->type, v->value);
            for (j = 0; j < v->ndim; j++)
                total_size *= v->dims[j];

            printf("    %-9s  %s", adios_type_to_string(v->type), f->var_namelist[i]);
            if (v->ndim == 0) {
                /* Scalars do not need to be read in, we get it from the metadata
                   when using adios_inq_var */
                printf(" = %s\n", value_to_string(v->type, v->value, 0));
            } else {
                /* Arrays have to be read in from the file */
                if (v->nsteps > 1) {
                    printf(" %d*",v->nsteps);
                }
                printf("[%" PRIu64,v->dims[0]);
                for (j = 1; j < v->ndim; j++)
                    printf(", %" PRIu64,v->dims[j]);
                //printf("] = \n");
                
                if (v->type == adios_integer)
                    printf("] = min=%d  max=%d\n", (*(int*)v->statistics->min), (*(int*)v->statistics->max));
                else if (v->type == adios_double)
                    printf("] = min=%lg  max=%lg\n", (*(double*)v->statistics->min), (*(double*)v->statistics->max));
                
                if (total_size > 1024*1024*1024) {
                    printf("        // too big, do not read in\n");
                } else {
                    data = malloc (total_size);
                    if (data == NULL) {
                        fprintf (stderr, "malloc failed.\n");
                        return -1;
                    }

                    for (j = 0; j < v->ndim; j++) 
                        count[j] = v->dims[j];   

                    for (t=0; t<v->nsteps; t++) {
                        sel = adios_selection_boundingbox (v->ndim, start, count);
                        adios_schedule_read_byid (f, sel, i, t, 1, data);
                        adios_perform_reads (f, 1);

                        printf("      Step %d:\n", t);
                        if (adios_errno) {
                            printf ("%s\n", adios_errmsg());
                        } else if (total_size > 1024*1024) {
                            printf ("Too big to print\n");
                        } else if (v->ndim == 1) {
                            printf ("        [");
                            for (j = 0; j < v->dims[0]; j++) 
                                printf("%s ", value_to_string(v->type, data, j));
                            printf ("]\n");
                        } else if (v->ndim == 2) {
                            for (j = 0; j < v->dims[0]; j++) {
                                printf ("        row %d: [", j);
                                for (k = 0; k < v->dims[1]; k++) 
                                    printf("%s ", value_to_string(v->type, data, j*v->dims[1] + k));
                                printf ("]\n");
                            }
                        } else if (v->ndim == 3) {
                            for (j = 0; j < v->dims[0]; j++) {
                                printf ("      block %d: \n", j);
                                for (k = 0; k < v->dims[1]; k++) {
                                    printf ("        row %d: [", k);
                                    for (l = 0; l < v->dims[2]; l++) {
                                        // NCSU ALACRITY-ADIOS - Fixed bug, k*v->dims[1] changed to  k*v->dims[2]
                                        printf("%s ", value_to_string(v->type, data, j*v->dims[1]*v->dims[2] + k*v->dims[2] + l));
                                    }
                                    printf ("]\n");
                                }
                                printf ("\n");
                            }
                        } else {
                            printf ("    cannot print arrays with >3 dimensions\n");
                        }
                    }
                    free (data);
                }
            }

            adios_free_varinfo (v);
        } /* variables */

        /* For all attributes */
        printf("  Attributes=%d:\n", f->nattrs);
        for (i = 0; i < f->nattrs; i++) {
            enum ADIOS_DATATYPES atype;
            int  asize;
            void *adata;
            adios_get_attr_byid (f, i, &atype, &asize, &adata);
            int type_size = adios_type_size (atype, adata);
            int nelems = asize / type_size;
            printf("    %-9s  %s = ", adios_type_to_string(atype), f->attr_namelist[i]);
            char *p = (char*)adata;
            if (nelems>1) printf("{");
            for (j=0; j<nelems; j++) {
                if (j>0) printf(", ");
                printf ("%s", value_to_string(atype, p, 0));
                p += type_size;
            }
            if (nelems>1) printf("}");
            printf("\n");
            free(adata);
        } /* attributes */

        adios_read_close (f);

    //} /* loop 'step' */
    return 0;
}