示例#1
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
示例#2
0
int main (int argc, char ** argv) 
{
    int         err;
    int         steps = 0, curr_step;
    int         retval = 0;

    MPI_Init (&argc, &argv);
    comm = MPI_COMM_WORLD;
    MPI_Comm_rank (comm, &rank);
    MPI_Comm_size (comm, &numproc);

    if (processArgs(argc, argv)) {
        return 1;
    }
    
    print0("Input stream            = %s\n", infilename);
    print0("Output stream           = %s\n", outfilename);
    print0("Read method             = %s (id=%d)\n", rmethodname, read_method);
    print0("Read method parameters  = \"%s\"\n", rmethodparams);
    print0("Write method            = %s\n", wmethodname);
    print0("Write method parameters = \"%s\"\n", wmethodparams);
    

    err = adios_read_init_method(read_method, comm, 
                                 "max_chunk_size=100; "
                                 "app_id =32767; \n"
                                 "verbose= 3;"
                                 "poll_interval  =  100;"
                                );

    if (!err) {
        print0 ("%s\n", adios_errmsg());
    }

    adios_init_noxml(comm);

    print0 ("Waiting to open stream %s...\n", infilename);
    f = adios_read_open_stream (infilename, read_method, comm, 
                                             ADIOS_LOCKMODE_ALL, timeout_sec);
    if (adios_errno == err_file_not_found) 
    {
        print ("rank %d: Stream not found after waiting %d seconds: %s\n", 
               rank, timeout_sec, adios_errmsg());
        retval = adios_errno;
    } 
    else if (adios_errno == err_end_of_stream) 
    {
        print ("rank %d: Stream terminated before open. %s\n", rank, adios_errmsg());
        retval = adios_errno;
    } 
    else if (f == NULL) {
        print ("rank %d: Error at opening stream: %s\n", rank, adios_errmsg());
        retval = adios_errno;
    } 
    else 
    {
        // process steps here... 
        if (f->current_step != 0) {
            print ("rank %d: WARNING: First %d steps were missed by open.\n", 
                   rank, f->current_step);
        }

        while (1)
        {
            steps++; // start counting from 1

            print0 ("File info:\n");
            print0 ("  current step:   %d\n", f->current_step);
            print0 ("  last step:      %d\n", f->last_step);
            print0 ("  # of variables: %d:\n", f->nvars);

            retval = process_metadata(steps);
            if (retval) break;

            retval = read_write(steps);
            if (retval) break;

            // advance to 1) next available step with 2) blocking wait 
            curr_step = f->current_step; // save for final bye print
            adios_advance_step (f, 0, timeout_sec);

            if (adios_errno == err_end_of_stream) 
            {
                break; // quit while loop
            }
            else if (adios_errno == err_step_notready) 
            {
                print ("rank %d: No new step arrived within the timeout. Quit. %s\n", 
                        rank, adios_errmsg());
                break; // quit while loop
            } 
            else if (f->current_step != curr_step+1) 
            {
                // we missed some steps
                print ("rank %d: WARNING: steps %d..%d were missed when advancing.\n", 
                        rank, curr_step+1, f->current_step-1);
            }

        }

        adios_read_close (f);
    } 
    print0 ("Bye after processing %d steps\n", steps);

    adios_read_finalize_method (read_method);
    adios_finalize (rank);
    MPI_Finalize ();

    return retval;
}