Unverified Commit 056228c3 authored by Eisenhauer, Greg's avatar Eisenhauer, Greg Committed by GitHub
Browse files

Merge pull request #4951 from eisenhauer/lazy-host-config

Defer hosts.yaml parsing until first access
parents 6dd07430 0743aef5
Loading
Loading
Loading
Loading
+26 −27
Original line number Diff line number Diff line
@@ -89,8 +89,6 @@ public:
};

ADIOS::GlobalServices ADIOS::m_GlobalServices;
adios2::HostOptions *StaticHostOptions = nullptr;
static std::mutex StaticHostOptionsMutex;

std::mutex PerfStubsMutex;
static std::atomic_uint adios_refcount(0); // adios objects at the same time
@@ -101,9 +99,32 @@ static std::atomic_uint adios_count(0); // total adios objects during runtime
const adios2::UserOptions &ADIOS::GetUserOptions() { return m_UserOptions; };

/** A constant reference to the host options from ~/.config/hpc-campaign/hosts.yaml */
const adios2::HostOptions &ADIOS::GetHostOptions() { return m_HostOptions; };
/** A constant reference to the host options from ~/.config/hpc-campaign/hosts.yaml */
const adios2::HostOptions &ADIOS::StaticGetHostOptions() { return *StaticHostOptions; };
const adios2::HostOptions &ADIOS::GetHostOptions()
{
    static adios2::HostOptions hostOptions = LoadHostConfig();
    return hostOptions;
}

const adios2::HostOptions &ADIOS::StaticGetHostOptions() { return GetHostOptions(); }

adios2::HostOptions ADIOS::LoadHostConfig()
{
    adios2::HostOptions hostOptions;
    std::string homePath;
#ifdef _WIN32
    homePath = getenv("HOMEPATH");
#else
    homePath = getenv("HOME");
#endif
    const std::string cfgFile = homePath + PathSeparator + ".config" + PathSeparator +
                                "hpc-campaign" + PathSeparator + "hosts.yaml";
    if (adios2sys::SystemTools::FileExists(cfgFile))
    {
        helper::Comm comm = helper::CommDummy();
        helper::ParseHostOptionsFile(comm, cfgFile, hostOptions, homePath);
    }
    return hostOptions;
}

ADIOS::ADIOS(const std::string configFile, helper::Comm comm, const std::string hostLanguage)
: m_HostLanguage(hostLanguage), m_Comm(std::move(comm)), m_ConfigFile(configFile),
@@ -124,7 +145,6 @@ ADIOS::ADIOS(const std::string configFile, helper::Comm comm, const std::string
    }
#endif
    ProcessUserConfig();
    ProcessHostConfig();
    if (!configFile.empty())
    {
        if (!adios2sys::SystemTools::FileExists(configFile))
@@ -214,27 +234,6 @@ void ADIOS::ProcessUserConfig()
    }
}

void ADIOS::ProcessHostConfig()
{
    // read config parameters from config file
    std::string homePath;
#ifdef _WIN32
    homePath = getenv("HOMEPATH");
#else
    homePath = getenv("HOME");
#endif
    const std::string cfgFile = homePath + PathSeparator + ".config" + PathSeparator +
                                "hpc-campaign" + PathSeparator + "hosts.yaml";
    if (adios2sys::SystemTools::FileExists(cfgFile))
    {
        helper::ParseHostOptionsFile(m_Comm, cfgFile, m_HostOptions, homePath);
    }
    {
        std::lock_guard<std::mutex> lck(StaticHostOptionsMutex);
        StaticHostOptions = &m_HostOptions;
    }
}

IO &ADIOS::DeclareIO(const std::string name, const ArrayOrdering ArrayOrder)
{
    auto itIO = m_IOs.find(name);
+4 −4
Original line number Diff line number Diff line
@@ -166,8 +166,9 @@ public:
     */
    const adios2::UserOptions &GetUserOptions();

    /** A constant reference to the host options from ~/.config/hpc-campaign/hosts.yaml */
    const adios2::HostOptions &GetHostOptions();
    /** A constant reference to the host options from ~/.config/hpc-campaign/hosts.yaml.
     *  Parsed lazily on first access as a singleton. */
    static const adios2::HostOptions &GetHostOptions();

private:
    /** Communicator given to parallel constructor. */
@@ -210,11 +211,10 @@ private:
                    core::IO &io);

    adios2::UserOptions m_UserOptions;
    adios2::HostOptions m_HostOptions;
    adios2::HostConfig m_Test;
    void SetUserOptionDefaults();
    void ProcessUserConfig();
    void ProcessHostConfig();
    static adios2::HostOptions LoadHostConfig();

private:
    /* Global services that we want to initialize at most once and shutdown
+2 −2
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ namespace core
Engine::Engine(const std::string engineType, IO &io, const std::string &name, const Mode openMode,
               helper::Comm comm)
: m_EngineType(engineType), m_IO(io), m_Name(name), m_OpenMode(openMode), m_Comm(std::move(comm)),
  m_UserOptions(io.m_ADIOS.GetUserOptions()), m_HostOptions(io.m_ADIOS.GetHostOptions())
  m_UserOptions(io.m_ADIOS.GetUserOptions())
{
    m_FailVerbose = (m_Comm.Rank() == 0);
}
@@ -28,7 +28,7 @@ Engine::Engine(const std::string engineType, IO &io, const std::string &name, co
Engine::Engine(const std::string engineType, IO &io, const std::string &name, const Mode openMode,
               helper::Comm comm, const char *md, const size_t mdsize)
: m_EngineType(engineType), m_IO(io), m_Name(name), m_OpenMode(openMode), m_Comm(std::move(comm)),
  m_UserOptions(io.m_ADIOS.GetUserOptions()), m_HostOptions(io.m_ADIOS.GetHostOptions())
  m_UserOptions(io.m_ADIOS.GetUserOptions())
{
    ThrowUp("Engine with metadata in memory");
}
+0 −3
Original line number Diff line number Diff line
@@ -559,9 +559,6 @@ protected:
    /** User options parsed by the ADIOS object, here just for easy reference */
    const UserOptions &m_UserOptions;

    /** Host options parsed by the ADIOS object, here just for easy reference */
    const HostOptions &m_HostOptions;

    /** keeps track of current advance status */
    StepStatus m_AdvanceStatus = StepStatus::OK;

+4 −4
Original line number Diff line number Diff line
@@ -560,7 +560,7 @@ void BP5Reader::PerformGets()
            // Determine if using HTTPS or plain HTTP
            const bool useHttps = (m_XrootdTransferProtocol == XRootDTransferProtocol::HTTPS);
            auto tup = lf_getXRootDHostPort(useHttps ? 443 : 80);
            m_Remote = std::make_unique<XrootdHttpRemote>(m_HostOptions);
            m_Remote = std::make_unique<XrootdHttpRemote>(ADIOS::GetHostOptions());
            Params params;
            params["UseHttps"] = useHttps ? "true" : "false";
            // For testing, disable SSL verification (only relevant for HTTPS)
@@ -584,7 +584,7 @@ void BP5Reader::PerformGets()
                m_XrootdTransferProtocol == XRootDTransferProtocol::XRootD)
        {
            auto tup = lf_getXRootDHostPort(1094);
            m_Remote = std::make_unique<XrootdRemote>(m_HostOptions);
            m_Remote = std::make_unique<XrootdRemote>(ADIOS::GetHostOptions());
            m_Remote->Open(std::get<0>(tup), std::get<1>(tup), m_RemoteName, m_OpenMode,
                           RowMajorOrdering);
        }
@@ -1179,8 +1179,8 @@ void BP5Reader::Init()
        if (!m_Parameters.RemoteHost.empty())
        {
            m_RemoteHost = m_Parameters.RemoteHost;
            auto it = m_HostOptions.find(m_Parameters.RemoteHost);
            if (it != m_HostOptions.end())
            auto it = ADIOS::GetHostOptions().find(m_Parameters.RemoteHost);
            if (it != ADIOS::GetHostOptions().end())
            {
                for (auto &hc : it->second)
                {
Loading