Example #1
0
    /** Prepare the write operation:
     *  Define ADIOS variable, increase params.adiosGroupSize and write attribute (if attrName is non-empty)
     *
     *  Must be called before executing the functor
     */
    void prepare(ThreadParams& params, T_Attribute attribute = T_Attribute())
    {
        typedef traits::PICToAdios<T_Scalar> AdiosSkalarType;
        typedef pmacc::math::UInt64<simDim> Dimensions;

        log<picLog::INPUT_OUTPUT> ("ADIOS: prepare write %1%D scalars: %2%") % simDim % name;

        params.adiosGroupSize += sizeof(T_Scalar);
        if(!attrName.empty())
            params.adiosGroupSize += sizeof(T_Attribute);

        // Size over all processes
        Dimensions globalDomainSize = Dimensions::create(1);
        // Offset for this process
        Dimensions localDomainOffset = Dimensions::create(0);

        for (uint32_t d = 0; d < simDim; ++d)
        {
            globalDomainSize[d] = Environment<simDim>::get().GridController().getGpuNodes()[d];
            localDomainOffset[d] = Environment<simDim>::get().GridController().getPosition()[d];
        }

        std::string datasetName = params.adiosBasePath + name;

        varId = defineAdiosVar<simDim>(
                    params.adiosGroupHandle,
                    datasetName.c_str(),
                    nullptr,
                    AdiosSkalarType().type,
                    Dimensions::create(1),
                    globalDomainSize,
                    localDomainOffset,
                    true,
                    params.adiosCompression);

        if(!attrName.empty())
        {
            typedef traits::PICToAdios<T_Attribute> AdiosAttrType;

            log<picLog::INPUT_OUTPUT> ("ADIOS: write attribute %1% of %2%D scalars: %3%") % attrName % simDim % name;
            ADIOS_CMD( adios_define_attribute_byvalue(params.adiosGroupHandle,
                       attrName.c_str(), datasetName.c_str(),
                       AdiosAttrType().type, 1, (void*)&attribute) );
        }
    }
Example #2
0
/**
 * Define attributes in the bp file
 */
SEXP R_define_attr(SEXP R_group,
                   SEXP R_attrname,
                   SEXP R_nelems,
                   SEXP R_values)
{
    int64_t m_adios_group = (int64_t)(REAL(R_group)[0]);
    const char *attrname = CHARPT(R_attrname, 0); 
    int nelems = asInteger(R_nelems);
    char **values;
    values = malloc(nelems);

    int i;
    for(i = 0; i < nelems; i++)
        values[i] = (char*)CHAR(STRING_ELT(R_values,i));

    adios_define_attribute_byvalue(m_adios_group,
                                   attrname, "",
                                   adios_string_array,
                                   nelems,
                                   values);

    return R_NilValue;
}
Example #3
0
int main (int argc, char ** argv) 
{
    char        filename [256];
    int         rank, size, i, j;
    int         NX = 100, gb, offset;  //local/global/offset
    double      t[NX];
    int         nblocks = 3;
    MPI_Comm    comm = MPI_COMM_WORLD;
    char g_str[100], o_str[100], l_str[100];
    // attributes (from C variables)
    int someints[5] = {5,4,3,2,1};
    double somedoubles[5] = {5.55555, 4.4444, 3.333, 2.22, 1.1};

    /* ADIOS variables declarations for matching gwrite_temperature.ch */
    uint64_t    adios_groupsize, adios_totalsize;

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

    gb = nblocks * NX * size;
    sprintf (g_str, "%d", gb);
    sprintf (l_str, "%d", NX);

    strcpy (filename, "no_xml_write_byid.bp");

    adios_init_noxml (comm);
    adios_set_max_buffer_size (10);

    int64_t       m_adios_group;
    int64_t       m_adios_file;
    int64_t       var_ids[nblocks];

    adios_declare_group (&m_adios_group, "restart", "iter", adios_flag_yes);
    adios_select_method (m_adios_group, "MPI", "", "");

    for (i = 0; i < nblocks; i++)
    {
        offset = rank * nblocks * NX + i * NX;
        sprintf (o_str, "%d", offset);
        var_ids[i] = adios_define_var (m_adios_group, "temperature"
                                       ,"", adios_double
                                       ,l_str, g_str, o_str
        );
        adios_set_transform (var_ids[i], "none");

        // This is here just for fun
        uint64_t varsize = adios_expected_var_size(var_ids[i]);
        // adios_expected_var_size() works here because the definition of the variable
        // does not depend on any dimension variable (but defined with numerical dimensions)
        fprintf (stderr, "Temperature block %d is %" PRIu64 " bytes\n", i, varsize);
    }

    // add some attributes
    adios_define_attribute_byvalue (m_adios_group,
                                    "single_string","", adios_string,  1, "A single string attribute");
    char *strings[] = {"X","Yy","ZzZ"};
    adios_define_attribute_byvalue (m_adios_group,
                                    "three_strings","", adios_string_array,  3, strings);
    adios_define_attribute_byvalue (m_adios_group,
                                    "single_int",   "", adios_integer, 1, &someints);
    adios_define_attribute_byvalue (m_adios_group,
                                    "single_double","", adios_double,  1, &somedoubles);
    adios_define_attribute_byvalue (m_adios_group,
                                    "five_ints",    "", adios_integer, 5, &someints);
    adios_define_attribute_byvalue (m_adios_group,
                                    "five_double",  "", adios_double,  5, &somedoubles);



    adios_open (&m_adios_file, "restart", filename, "w", comm);

    adios_groupsize = nblocks * (4 + 4 + 4 + NX * 8);

    adios_group_size (m_adios_file, adios_groupsize, &adios_totalsize);
    /* now we will write the data for each sub block */
    for (i = 0; i < nblocks; i++)
    {
        offset = rank * nblocks * NX + i * NX;
        for (j = 0; j < NX; j++)
            t[j] = offset + j;

        adios_write_byid(m_adios_file, var_ids[i], t);
    }

    adios_close (m_adios_file);

    MPI_Barrier (comm);

    adios_finalize (rank);

    MPI_Finalize ();
    return 0;
}