<commit_before>/*
 * hdf5Stream.cpp
 *
 *  Created on: Nov 2018
 *      Author: <NAME>
 */

#include "hdf5Stream.h"

#include <cstdlib>
#include <iostream>
#include <map>
#include <math.h>
#include <stdexcept>
#include <string>

hdf5Stream::hdf5Stream(const std::string &streamName, const adios2::Mode mode,
                       MPI_Comm comm)
: Stream(streamName, mode)
{
    hid_t acc_tpl = H5Pcreate(H5P_FILE_ACCESS);
    MPI_Info info = MPI_INFO_NULL;
    herr_t ret = H5Pset_fapl_mpio(acc_tpl, comm, info);

    if (mode == adios2::Mode::Write)
    {
        h5file =
            H5Fcreate(streamName.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, acc_tpl);
    }
    else
    {
        h5file = H5Fopen(streamName.c_str(), H5F_ACC_RDONLY, acc_tpl);
    }
    ret = H5Pclose(acc_tpl);
}

hdf5Stream::~hdf5Stream(){};

hid_t hdf5Stream::hdf5Type(std::string &type)
{
    hid_t htype = H5T_NATIVE_CHAR;
    if (type == "double")
    {
        htype = H5T_NATIVE_DOUBLE;
    }
    else if (type == "float")
    {
        htype = H5T_NATIVE_FLOAT;
    }
    else if (type == "int")
    {
        htype = H5T_NATIVE_INT32;
    }<commit_msg>added timer to measure native hdf5 open performance<commit_after>/*
 * hdf5Stream.cpp
 *
 *  Created on: Nov 2018
 *      Author: <NAME>
 */

#include "hdf5Stream.h"

#include <cstdlib>
#include <iostream>
#include <map>
#include <math.h>
#include <stdexcept>
#include <string>

hdf5Stream::hdf5Stream(const std::string &streamName, const adios2::Mode mode,
                       MPI_Comm comm)
: Stream(streamName, mode)
{
    hid_t acc_tpl = H5Pcreate(H5P_FILE_ACCESS);
    MPI_Info info = MPI_INFO_NULL;
    herr_t ret = H5Pset_fapl_mpio(acc_tpl, comm, info);

    int myRank;
    MPI_Comm_rank(comm, &myRank);
    double timeStart, timeEnd;
    double openTime;
    double maxOpenTime, minOpenTime;

    if (mode == adios2::Mode::Write)
    {
        timeStart = MPI_Wtime();
        h5file =
            H5Fcreate(streamName.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, acc_tpl);
        timeEnd = MPI_Wtime();
    }
    else
    {
        timeStart = MPI_Wtime();
        h5file = H5Fopen(streamName.c_str(), H5F_ACC_RDONLY, acc_tpl);
        timeEnd = MPI_Wtime();
    }
    openTime = timeEnd-timeStart;
    MPI_Allreduce(&openTime, &maxOpenTime, 1, MPI_DOUBLE, MPI_MAX,
		MPI_COMM_WORLD);
    MPI_Allreduce(&openTime, &minOpenTime, 1, MPI_DOUBLE, MPI_MIN,
		MPI_COMM_WORLD);
    if (myRank == 0)
    {
        std::cout << "        Max open time = " << maxOpenTime << std::endl;
        std::cout << "        Min open time = " << minOpenTime << std::endl;
        std::ofstream open_perf_log;
        open_perf_log.open("open_perf.txt", std::ios::app);
        open_perf_log << std::to_string(maxOpenTime)+", "+std::to_string(minOpenTime)+"\n";
        open_perf_log.close();
    }
    ret = H5Pclose(acc_tpl);
}

hdf5Stream::~hdf5Stream(){};

hid_t hdf5Stream::hdf5Type(std::string &type)
{
    hid_t htype = H5T_NATIVE_CHAR;
    if (type == "double")
    {
        htype = H5T_NATIVE_DOUBLE;
    }
    else if (type == "float")
    {
        htype = H5T_NATIVE_FLOAT;
    }
    else if (type == "int")
    {
        htype = H5T_NATIVE_INT32;
    }
{'fraction_non_alphanumeric': 0.13352183474709395, 'fraction_numerical': 0.020735155513666354, 'mean_word_length': 2.8829268292682926, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1547162', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1254, 'n_words': 228}