diff --git a/source/adios2/CMakeLists.txt b/source/adios2/CMakeLists.txt index 3e7b1d37ea..0228b4d832 100644 --- a/source/adios2/CMakeLists.txt +++ b/source/adios2/CMakeLists.txt @@ -238,7 +238,7 @@ endif() if (ADIOS2_HAVE_SST) # EVPath-enabled remote file transport - target_sources(adios2_core PRIVATE toolkit/remote/remote_common.cpp toolkit/transport/file/FileRemote.cpp) + target_sources(adios2_core PRIVATE toolkit/remote/remote_common.cpp toolkit/transport/file/FileRemote.cpp toolkit/remote/EVPathRemote.cpp) target_link_libraries(adios2_core PRIVATE adios2::thirdparty::EVPath) add_subdirectory(toolkit/remote) endif() diff --git a/source/adios2/engine/bp5/BP5Reader.cpp b/source/adios2/engine/bp5/BP5Reader.cpp index dcddb24a57..ee0103a303 100644 --- a/source/adios2/engine/bp5/BP5Reader.cpp +++ b/source/adios2/engine/bp5/BP5Reader.cpp @@ -10,6 +10,7 @@ #include "BP5Reader.tcc" #include "adios2/helper/adiosMath.h" // SetWithinLimit +#include "adios2/toolkit/remote/EVPathRemote.h" #include "adios2/toolkit/transport/file/FileFStream.h" #include @@ -283,15 +284,27 @@ void BP5Reader::PerformGets() if (m_BP5Deserializer->PendingGetRequests.size() == 0) return; + std::string RemoteName; if (!m_Parameters.RemoteDataPath.empty()) { - m_Remote.Open("localhost", RemoteCommon::ServerPort, m_Parameters.RemoteDataPath, - m_OpenMode, RowMajorOrdering); + RemoteName = m_Parameters.RemoteDataPath; } else if (getenv("DoRemote")) { - m_Remote.Open("localhost", RemoteCommon::ServerPort, m_Name, m_OpenMode, - RowMajorOrdering); + RemoteName = m_Name; + } + (void)RowMajorOrdering; // Use in case no remotes available +#ifdef ADIOS2_HAVE_SST + m_Remote = std::unique_ptr(new EVPathRemote()); + m_Remote->Open("localhost", EVPathRemoteCommon::ServerPort, RemoteName, m_OpenMode, + RowMajorOrdering); +#endif + if (m_Remote == nullptr) + { + helper::Throw( + "Engine", "BP5Reader", "OpenFiles", + "Remote file " + m_Name + + " cannot be opened. Possible server or file specification error."); } if (!m_Remote) { @@ -324,7 +337,7 @@ void BP5Reader::PerformRemoteGets() auto GetRequests = m_BP5Deserializer->PendingGetRequests; for (auto &Req : GetRequests) { - m_Remote.Get(Req.VarName, Req.RelStep, Req.BlockID, Req.Count, Req.Start, Req.Data); + m_Remote->Get(Req.VarName, Req.RelStep, Req.BlockID, Req.Count, Req.Start, Req.Data); } } diff --git a/source/adios2/engine/bp5/BP5Reader.h b/source/adios2/engine/bp5/BP5Reader.h index 6e8508041c..a09ff491d0 100644 --- a/source/adios2/engine/bp5/BP5Reader.h +++ b/source/adios2/engine/bp5/BP5Reader.h @@ -95,7 +95,7 @@ class BP5Reader : public BP5Engine, public Engine /* transport manager for managing the active flag file */ transportman::TransportMan m_ActiveFlagFileManager; bool m_dataIsRemote = false; - Remote m_Remote; + std::unique_ptr m_Remote; bool m_WriterIsActive = true; adios2::profiling::JSONProfiler m_JSONProfiler; diff --git a/source/adios2/toolkit/remote/EVPathRemote.cpp b/source/adios2/toolkit/remote/EVPathRemote.cpp new file mode 100644 index 0000000000..96666a43c7 --- /dev/null +++ b/source/adios2/toolkit/remote/EVPathRemote.cpp @@ -0,0 +1,219 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + */ +#include "EVPathRemote.h" +#include "Remote.h" +#include "adios2/core/ADIOS.h" +#include "adios2/helper/adiosLog.h" +#include "adios2/helper/adiosString.h" +#include "adios2/helper/adiosSystem.h" +#ifdef _MSC_VER +#define strdup(x) _strdup(x) +#endif + +#define ThrowUp(x) \ + helper::Throw("Core", "Engine", "ThrowUp", \ + "Non-overridden function " + std::string(x) + \ + " called in Remote") + +namespace adios2 +{ + +EVPathRemote::EVPathRemote() {} + +#ifdef ADIOS2_HAVE_SST +EVPathRemote::~EVPathRemote() +{ + if (m_conn) + CMConnection_close(m_conn); +} + +void OpenResponseHandler(CManager cm, CMConnection conn, void *vevent, void *client_data, + attr_list attrs) +{ + EVPathRemoteCommon::OpenResponseMsg open_response_msg = + static_cast(vevent); + + void *obj = CMCondition_get_client_data(cm, open_response_msg->OpenResponseCondition); + static_cast(obj)->m_ID = open_response_msg->FileHandle; + CMCondition_signal(cm, open_response_msg->OpenResponseCondition); + return; +}; + +void OpenSimpleResponseHandler(CManager cm, CMConnection conn, void *vevent, void *client_data, + attr_list attrs) +{ + EVPathRemoteCommon::OpenSimpleResponseMsg open_response_msg = + static_cast(vevent); + + void *obj = CMCondition_get_client_data(cm, open_response_msg->OpenResponseCondition); + static_cast(obj)->m_ID = open_response_msg->FileHandle; + static_cast(obj)->m_Size = open_response_msg->FileSize; + CMCondition_signal(cm, open_response_msg->OpenResponseCondition); + return; +}; + +void ReadResponseHandler(CManager cm, CMConnection conn, void *vevent, void *client_data, + attr_list attrs) +{ + EVPathRemoteCommon::ReadResponseMsg read_response_msg = + static_cast(vevent); + memcpy(read_response_msg->Dest, read_response_msg->ReadData, read_response_msg->Size); + CMCondition_signal(cm, read_response_msg->ReadResponseCondition); + return; +}; + +CManagerSingleton &CManagerSingleton::Instance(EVPathRemoteCommon::Remote_evpath_state &ev_state) +{ + std::mutex mtx; + const std::lock_guard lock(mtx); + static CManagerSingleton instance; + ev_state = instance.internalEvState; + return instance; +} + +void EVPathRemote::InitCMData() +{ + (void)CManagerSingleton::Instance(ev_state); + static std::once_flag flag; + std::call_once(flag, [&]() { + CMregister_handler(ev_state.OpenResponseFormat, (CMHandlerFunc)OpenResponseHandler, + &ev_state); + CMregister_handler(ev_state.ReadResponseFormat, (CMHandlerFunc)ReadResponseHandler, + &ev_state); + CMregister_handler(ev_state.OpenSimpleResponseFormat, + (CMHandlerFunc)OpenSimpleResponseHandler, &ev_state); + CMregister_handler(ev_state.ReadResponseFormat, (CMHandlerFunc)ReadResponseHandler, + &ev_state); + }); +} + +void EVPathRemote::Open(const std::string hostname, const int32_t port, const std::string filename, + const Mode mode, bool RowMajorOrdering) +{ + + EVPathRemoteCommon::_OpenFileMsg open_msg; + InitCMData(); + attr_list contact_list = create_attr_list(); + atom_t CM_IP_PORT = -1; + atom_t CM_IP_HOSTNAME = -1; + CM_IP_HOSTNAME = attr_atom_from_string("IP_HOST"); + CM_IP_PORT = attr_atom_from_string("IP_PORT"); + add_attr(contact_list, CM_IP_HOSTNAME, Attr_String, (attr_value)strdup(hostname.c_str())); + add_attr(contact_list, CM_IP_PORT, Attr_Int4, (attr_value)port); + m_conn = CMinitiate_conn(ev_state.cm, contact_list); + free_attr_list(contact_list); + if (!m_conn) + return; + + memset(&open_msg, 0, sizeof(open_msg)); + open_msg.FileName = (char *)filename.c_str(); + switch (mode) + { + case Mode::Read: + open_msg.Mode = EVPathRemoteCommon::RemoteFileMode::RemoteOpen; + break; + case Mode::ReadRandomAccess: + open_msg.Mode = EVPathRemoteCommon::RemoteFileMode::RemoteOpenRandomAccess; + break; + default: + break; + } + open_msg.OpenResponseCondition = CMCondition_get(ev_state.cm, m_conn); + open_msg.RowMajorOrder = RowMajorOrdering; + CMCondition_set_client_data(ev_state.cm, open_msg.OpenResponseCondition, (void *)this); + CMwrite(m_conn, ev_state.OpenFileFormat, &open_msg); + CMCondition_wait(ev_state.cm, open_msg.OpenResponseCondition); + m_Active = true; +} + +void EVPathRemote::OpenSimpleFile(const std::string hostname, const int32_t port, + const std::string filename) +{ + + EVPathRemoteCommon::_OpenSimpleFileMsg open_msg; + InitCMData(); + attr_list contact_list = create_attr_list(); + atom_t CM_IP_PORT = -1; + atom_t CM_IP_HOSTNAME = -1; + CM_IP_HOSTNAME = attr_atom_from_string("IP_HOST"); + CM_IP_PORT = attr_atom_from_string("IP_PORT"); + add_attr(contact_list, CM_IP_HOSTNAME, Attr_String, (attr_value)strdup(hostname.c_str())); + add_attr(contact_list, CM_IP_PORT, Attr_Int4, (attr_value)port); + m_conn = CMinitiate_conn(ev_state.cm, contact_list); + free_attr_list(contact_list); + if (!m_conn) + return; + + memset(&open_msg, 0, sizeof(open_msg)); + open_msg.FileName = (char *)filename.c_str(); + open_msg.OpenResponseCondition = CMCondition_get(ev_state.cm, m_conn); + CMCondition_set_client_data(ev_state.cm, open_msg.OpenResponseCondition, (void *)this); + CMwrite(m_conn, ev_state.OpenSimpleFileFormat, &open_msg); + CMCondition_wait(ev_state.cm, open_msg.OpenResponseCondition); + m_Active = true; +} + +EVPathRemote::GetHandle EVPathRemote::Get(char *VarName, size_t Step, size_t BlockID, Dims &Count, + Dims &Start, void *dest) +{ + EVPathRemoteCommon::_GetRequestMsg GetMsg; + memset(&GetMsg, 0, sizeof(GetMsg)); + GetMsg.GetResponseCondition = CMCondition_get(ev_state.cm, m_conn); + GetMsg.FileHandle = m_ID; + GetMsg.VarName = VarName; + GetMsg.Step = Step; + GetMsg.BlockID = BlockID; + GetMsg.DimCount = (int)Count.size(); + GetMsg.Count = Count.data(); + GetMsg.Start = Start.data(); + GetMsg.Dest = dest; + CMwrite(m_conn, ev_state.GetRequestFormat, &GetMsg); + CMCondition_wait(ev_state.cm, GetMsg.GetResponseCondition); + return GetMsg.GetResponseCondition; +} + +EVPathRemote::GetHandle EVPathRemote::Read(size_t Start, size_t Size, void *Dest) +{ + EVPathRemoteCommon::_ReadRequestMsg ReadMsg; + memset(&ReadMsg, 0, sizeof(ReadMsg)); + ReadMsg.ReadResponseCondition = CMCondition_get(ev_state.cm, m_conn); + ReadMsg.FileHandle = m_ID; + ReadMsg.Offset = Start; + ReadMsg.Size = Size; + ReadMsg.Dest = Dest; + CMwrite(m_conn, ev_state.ReadRequestFormat, &ReadMsg); + CMCondition_wait(ev_state.cm, ReadMsg.ReadResponseCondition); + return ReadMsg.ReadResponseCondition; +} + +bool EVPathRemote::WaitForGet(GetHandle handle) +{ + return CMCondition_wait(ev_state.cm, (int)handle); +} +#else + +void EVPathRemote::Open(const std::string hostname, const int32_t port, const std::string filename, + const Mode mode, bool RowMajorOrdering){}; + +void EVPathRemote::OpenSimpleFile(const std::string hostname, const int32_t port, + const std::string filename){}; + +EVPathRemote::GetHandle EVPathRemote::Get(char *VarName, size_t Step, size_t BlockID, Dims &Count, + Dims &Start, void *dest) +{ + return static_cast(0); +}; + +bool EVPathRemote::WaitForGet(GetHandle handle) { return false; } + +EVPathRemote::GetHandle EVPathRemote::Read(size_t Start, size_t Size, void *Dest) +{ + return static_cast(0); +}; +EVPathRemote::~EVPathRemote() {} +#endif + +} // end namespace adios2 diff --git a/source/adios2/toolkit/remote/EVPathRemote.h b/source/adios2/toolkit/remote/EVPathRemote.h new file mode 100644 index 0000000000..ae445de145 --- /dev/null +++ b/source/adios2/toolkit/remote/EVPathRemote.h @@ -0,0 +1,89 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + */ + +#ifndef ADIOS2_TOOLKIT_REMOTE_EVPATHREMOTE_H_ +#define ADIOS2_TOOLKIT_REMOTE_EVPATHREMOTE_H_ + +/// \cond EXCLUDE_FROM_DOXYGEN +#include +#include +#include +/// \endcond + +#include "adios2/toolkit/profiling/iochrono/IOChrono.h" + +#include "Remote.h" +#include "adios2/common/ADIOSConfig.h" + +#include "remote_common.h" + +namespace adios2 +{ + +class EVPathRemote : public Remote +{ + +public: + profiling::IOChrono m_Profiler; ///< profiles Open, Write/Read, Close + + /** + * Base constructor that all derived classes pass + * @param type from derived class + * @param comm passed to m_Comm + */ + EVPathRemote(); + ~EVPathRemote(); + + explicit operator bool() const { return m_Active; } + + void Open(const std::string hostname, const int32_t port, const std::string filename, + const Mode mode, bool RowMajorOrdering); + + void OpenSimpleFile(const std::string hostname, const int32_t port, const std::string filename); + + typedef int GetHandle; + + GetHandle Get(char *VarName, size_t Step, size_t BlockID, Dims &Count, Dims &Start, void *dest); + + bool WaitForGet(GetHandle handle); + + GetHandle Read(size_t Start, size_t Size, void *Dest); + + int64_t m_ID; + +private: +#ifdef ADIOS2_HAVE_SST + void InitCMData(); + EVPathRemoteCommon::Remote_evpath_state ev_state; + CMConnection m_conn = NULL; + std::mutex m_CMInitMutex; +#endif + bool m_Active = false; +}; + +#ifdef ADIOS2_HAVE_SST +class CManagerSingleton +{ +public: + static CManagerSingleton &Instance(EVPathRemoteCommon::Remote_evpath_state &ev_state); + +private: + CManager m_cm = NULL; + EVPathRemoteCommon::Remote_evpath_state internalEvState; + CManagerSingleton() + { + m_cm = CManager_create(); + internalEvState.cm = m_cm; + RegisterFormats(internalEvState); + CMfork_comm_thread(internalEvState.cm); + } + + ~CManagerSingleton() { CManager_close(m_cm); } +}; +#endif + +} // end namespace adios2 + +#endif /* ADIOS2_TOOLKIT_EVPATHREMOTE_REMOTE_H_ */ diff --git a/source/adios2/toolkit/remote/Remote.cpp b/source/adios2/toolkit/remote/Remote.cpp index 1d3a1afe62..909f14c886 100644 --- a/source/adios2/toolkit/remote/Remote.cpp +++ b/source/adios2/toolkit/remote/Remote.cpp @@ -4,6 +4,7 @@ * */ #include "Remote.h" +#include "EVPathRemote.h" #include "adios2/core/ADIOS.h" #include "adios2/helper/adiosLog.h" #include "adios2/helper/adiosString.h" @@ -12,198 +13,45 @@ #define strdup(x) _strdup(x) #endif -namespace adios2 -{ - -Remote::Remote() {} - -#ifdef ADIOS2_HAVE_SST -Remote::~Remote() -{ - if (m_conn) - CMConnection_close(m_conn); -} - -void OpenResponseHandler(CManager cm, CMConnection conn, void *vevent, void *client_data, - attr_list attrs) -{ - RemoteCommon::OpenResponseMsg open_response_msg = - static_cast(vevent); - - void *obj = CMCondition_get_client_data(cm, open_response_msg->OpenResponseCondition); - static_cast(obj)->m_ID = open_response_msg->FileHandle; - CMCondition_signal(cm, open_response_msg->OpenResponseCondition); - return; -}; - -void OpenSimpleResponseHandler(CManager cm, CMConnection conn, void *vevent, void *client_data, - attr_list attrs) -{ - RemoteCommon::OpenSimpleResponseMsg open_response_msg = - static_cast(vevent); - - void *obj = CMCondition_get_client_data(cm, open_response_msg->OpenResponseCondition); - static_cast(obj)->m_ID = open_response_msg->FileHandle; - static_cast(obj)->m_Size = open_response_msg->FileSize; - CMCondition_signal(cm, open_response_msg->OpenResponseCondition); - return; -}; - -void ReadResponseHandler(CManager cm, CMConnection conn, void *vevent, void *client_data, - attr_list attrs) -{ - RemoteCommon::ReadResponseMsg read_response_msg = - static_cast(vevent); - memcpy(read_response_msg->Dest, read_response_msg->ReadData, read_response_msg->Size); - CMCondition_signal(cm, read_response_msg->ReadResponseCondition); - return; -}; +#define ThrowUp(x) \ + helper::Throw("Core", "Engine", "ThrowUp", \ + "Non-overridden function " + std::string(x) + \ + " called in Remote") -CManagerSingleton &CManagerSingleton::Instance(RemoteCommon::Remote_evpath_state &ev_state) -{ - std::mutex mtx; - const std::lock_guard lock(mtx); - static CManagerSingleton instance; - ev_state = instance.internalEvState; - return instance; -} - -void Remote::InitCMData() +namespace adios2 { - (void)CManagerSingleton::Instance(ev_state); - static std::once_flag flag; - std::call_once(flag, [&]() { - CMregister_handler(ev_state.OpenResponseFormat, (CMHandlerFunc)OpenResponseHandler, - &ev_state); - CMregister_handler(ev_state.ReadResponseFormat, (CMHandlerFunc)ReadResponseHandler, - &ev_state); - CMregister_handler(ev_state.OpenSimpleResponseFormat, - (CMHandlerFunc)OpenSimpleResponseHandler, &ev_state); - CMregister_handler(ev_state.ReadResponseFormat, (CMHandlerFunc)ReadResponseHandler, - &ev_state); - }); -} void Remote::Open(const std::string hostname, const int32_t port, const std::string filename, const Mode mode, bool RowMajorOrdering) { - - RemoteCommon::_OpenFileMsg open_msg; - InitCMData(); - attr_list contact_list = create_attr_list(); - atom_t CM_IP_PORT = -1; - atom_t CM_IP_HOSTNAME = -1; - CM_IP_HOSTNAME = attr_atom_from_string("IP_HOST"); - CM_IP_PORT = attr_atom_from_string("IP_PORT"); - add_attr(contact_list, CM_IP_HOSTNAME, Attr_String, (attr_value)strdup(hostname.c_str())); - add_attr(contact_list, CM_IP_PORT, Attr_Int4, (attr_value)port); - m_conn = CMinitiate_conn(ev_state.cm, contact_list); - free_attr_list(contact_list); - if (!m_conn) - return; - - memset(&open_msg, 0, sizeof(open_msg)); - open_msg.FileName = (char *)filename.c_str(); - switch (mode) - { - case Mode::Read: - open_msg.Mode = RemoteCommon::RemoteFileMode::RemoteOpen; - break; - case Mode::ReadRandomAccess: - open_msg.Mode = RemoteCommon::RemoteFileMode::RemoteOpenRandomAccess; - break; - default: - break; - } - open_msg.OpenResponseCondition = CMCondition_get(ev_state.cm, m_conn); - open_msg.RowMajorOrder = RowMajorOrdering; - CMCondition_set_client_data(ev_state.cm, open_msg.OpenResponseCondition, (void *)this); - CMwrite(m_conn, ev_state.OpenFileFormat, &open_msg); - CMCondition_wait(ev_state.cm, open_msg.OpenResponseCondition); - m_Active = true; -} + ThrowUp(("RemoteOpen")); +}; void Remote::OpenSimpleFile(const std::string hostname, const int32_t port, const std::string filename) { - - RemoteCommon::_OpenSimpleFileMsg open_msg; - InitCMData(); - attr_list contact_list = create_attr_list(); - atom_t CM_IP_PORT = -1; - atom_t CM_IP_HOSTNAME = -1; - CM_IP_HOSTNAME = attr_atom_from_string("IP_HOST"); - CM_IP_PORT = attr_atom_from_string("IP_PORT"); - add_attr(contact_list, CM_IP_HOSTNAME, Attr_String, (attr_value)strdup(hostname.c_str())); - add_attr(contact_list, CM_IP_PORT, Attr_Int4, (attr_value)port); - m_conn = CMinitiate_conn(ev_state.cm, contact_list); - free_attr_list(contact_list); - if (!m_conn) - return; - - memset(&open_msg, 0, sizeof(open_msg)); - open_msg.FileName = (char *)filename.c_str(); - open_msg.OpenResponseCondition = CMCondition_get(ev_state.cm, m_conn); - CMCondition_set_client_data(ev_state.cm, open_msg.OpenResponseCondition, (void *)this); - CMwrite(m_conn, ev_state.OpenSimpleFileFormat, &open_msg); - CMCondition_wait(ev_state.cm, open_msg.OpenResponseCondition); - m_Active = true; -} + ThrowUp("RemoteSimpleOpen"); +}; Remote::GetHandle Remote::Get(char *VarName, size_t Step, size_t BlockID, Dims &Count, Dims &Start, void *dest) { - RemoteCommon::_GetRequestMsg GetMsg; - memset(&GetMsg, 0, sizeof(GetMsg)); - GetMsg.GetResponseCondition = CMCondition_get(ev_state.cm, m_conn); - GetMsg.FileHandle = m_ID; - GetMsg.VarName = VarName; - GetMsg.Step = Step; - GetMsg.BlockID = BlockID; - GetMsg.DimCount = (int)Count.size(); - GetMsg.Count = Count.data(); - GetMsg.Start = Start.data(); - GetMsg.Dest = dest; - CMwrite(m_conn, ev_state.GetRequestFormat, &GetMsg); - CMCondition_wait(ev_state.cm, GetMsg.GetResponseCondition); - return GetMsg.GetResponseCondition; -} + ThrowUp("RemoteGet"); + return 0; +}; -Remote::GetHandle Remote::Read(size_t Start, size_t Size, void *Dest) +bool Remote::WaitForGet(GetHandle handle) { - RemoteCommon::_ReadRequestMsg ReadMsg; - memset(&ReadMsg, 0, sizeof(ReadMsg)); - ReadMsg.ReadResponseCondition = CMCondition_get(ev_state.cm, m_conn); - ReadMsg.FileHandle = m_ID; - ReadMsg.Offset = Start; - ReadMsg.Size = Size; - ReadMsg.Dest = Dest; - CMwrite(m_conn, ev_state.ReadRequestFormat, &ReadMsg); - CMCondition_wait(ev_state.cm, ReadMsg.ReadResponseCondition); - return ReadMsg.ReadResponseCondition; + ThrowUp("RemoteWaitForGet"); + return false; } -bool Remote::WaitForGet(GetHandle handle) { return CMCondition_wait(ev_state.cm, (int)handle); } -#else - -void Remote::Open(const std::string hostname, const int32_t port, const std::string filename, - const Mode mode, bool RowMajorOrdering){}; - -void Remote::OpenSimpleFile(const std::string hostname, const int32_t port, - const std::string filename){}; - -Remote::GetHandle Remote::Get(char *VarName, size_t Step, size_t BlockID, Dims &Count, Dims &Start, - void *dest) -{ - return static_cast(0); -}; - -bool Remote::WaitForGet(GetHandle handle) { return false; } - Remote::GetHandle Remote::Read(size_t Start, size_t Size, void *Dest) { - return static_cast(0); + ThrowUp("RemoteRead"); + return 0; }; Remote::~Remote() {} -#endif +Remote::Remote() {} + } // end namespace adios2 diff --git a/source/adios2/toolkit/remote/Remote.h b/source/adios2/toolkit/remote/Remote.h index 9e432516fa..3853e6e193 100644 --- a/source/adios2/toolkit/remote/Remote.h +++ b/source/adios2/toolkit/remote/Remote.h @@ -16,72 +16,34 @@ #include "adios2/common/ADIOSConfig.h" -#include "remote_common.h" - namespace adios2 { class Remote { public: - profiling::IOChrono m_Profiler; ///< profiles Open, Write/Read, Close - - /** - * Base constructor that all derived classes pass - * @param type from derived class - * @param comm passed to m_Comm - */ Remote(); - ~Remote(); + virtual ~Remote(); - explicit operator bool() const { return m_Active; } + virtual explicit operator bool() const { return false; } - void Open(const std::string hostname, const int32_t port, const std::string filename, - const Mode mode, bool RowMajorOrdering); + virtual void Open(const std::string hostname, const int32_t port, const std::string filename, + const Mode mode, bool RowMajorOrdering); - void OpenSimpleFile(const std::string hostname, const int32_t port, const std::string filename); + virtual void OpenSimpleFile(const std::string hostname, const int32_t port, + const std::string filename); typedef int GetHandle; - GetHandle Get(char *VarName, size_t Step, size_t BlockID, Dims &Count, Dims &Start, void *dest); + virtual GetHandle Get(char *VarName, size_t Step, size_t BlockID, Dims &Count, Dims &Start, + void *dest); - bool WaitForGet(GetHandle handle); + virtual bool WaitForGet(GetHandle handle); - GetHandle Read(size_t Start, size_t Size, void *Dest); + virtual GetHandle Read(size_t Start, size_t Size, void *Dest); - int64_t m_ID; size_t m_Size; - -private: -#ifdef ADIOS2_HAVE_SST - void InitCMData(); - RemoteCommon::Remote_evpath_state ev_state; - CMConnection m_conn = NULL; - std::mutex m_CMInitMutex; -#endif - bool m_Active = false; -}; - -#ifdef ADIOS2_HAVE_SST -class CManagerSingleton -{ -public: - static CManagerSingleton &Instance(RemoteCommon::Remote_evpath_state &ev_state); - -private: - CManager m_cm = NULL; - RemoteCommon::Remote_evpath_state internalEvState; - CManagerSingleton() - { - m_cm = CManager_create(); - internalEvState.cm = m_cm; - RegisterFormats(internalEvState); - CMfork_comm_thread(internalEvState.cm); - } - - ~CManagerSingleton() { CManager_close(m_cm); } }; -#endif } // end namespace adios2 diff --git a/source/adios2/toolkit/remote/remote_common.cpp b/source/adios2/toolkit/remote/remote_common.cpp index bab73b0462..4cc14441c5 100644 --- a/source/adios2/toolkit/remote/remote_common.cpp +++ b/source/adios2/toolkit/remote/remote_common.cpp @@ -5,7 +5,7 @@ namespace adios2 { -namespace RemoteCommon +namespace EVPathRemoteCommon { FMField OpenFileList[] = { @@ -134,23 +134,30 @@ FMStructDescRec StatusResponseStructs[] = { {"StatusResponse", StatusResponseList, sizeof(struct _StatusResponseMsg), NULL}, {NULL, NULL, 0, NULL}}; -void RegisterFormats(RemoteCommon::Remote_evpath_state &ev_state) +void RegisterFormats(EVPathRemoteCommon::Remote_evpath_state &ev_state) { - ev_state.OpenFileFormat = CMregister_format(ev_state.cm, RemoteCommon::OpenFileStructs); + ev_state.OpenFileFormat = CMregister_format(ev_state.cm, EVPathRemoteCommon::OpenFileStructs); ev_state.OpenSimpleFileFormat = - CMregister_format(ev_state.cm, RemoteCommon::OpenSimpleFileStructs); - ev_state.OpenResponseFormat = CMregister_format(ev_state.cm, RemoteCommon::OpenResponseStructs); + CMregister_format(ev_state.cm, EVPathRemoteCommon::OpenSimpleFileStructs); + ev_state.OpenResponseFormat = + CMregister_format(ev_state.cm, EVPathRemoteCommon::OpenResponseStructs); ev_state.OpenSimpleResponseFormat = - CMregister_format(ev_state.cm, RemoteCommon::OpenSimpleResponseStructs); - ev_state.GetRequestFormat = CMregister_format(ev_state.cm, RemoteCommon::GetRequestStructs); - ev_state.ReadRequestFormat = CMregister_format(ev_state.cm, RemoteCommon::ReadRequestStructs); - ev_state.ReadResponseFormat = CMregister_format(ev_state.cm, RemoteCommon::ReadResponseStructs); - ev_state.CloseFileFormat = CMregister_format(ev_state.cm, RemoteCommon::CloseFileStructs); - ev_state.KillServerFormat = CMregister_format(ev_state.cm, RemoteCommon::KillServerStructs); - ev_state.KillResponseFormat = CMregister_format(ev_state.cm, RemoteCommon::KillResponseStructs); - ev_state.StatusServerFormat = CMregister_format(ev_state.cm, RemoteCommon::StatusServerStructs); + CMregister_format(ev_state.cm, EVPathRemoteCommon::OpenSimpleResponseStructs); + ev_state.GetRequestFormat = + CMregister_format(ev_state.cm, EVPathRemoteCommon::GetRequestStructs); + ev_state.ReadRequestFormat = + CMregister_format(ev_state.cm, EVPathRemoteCommon::ReadRequestStructs); + ev_state.ReadResponseFormat = + CMregister_format(ev_state.cm, EVPathRemoteCommon::ReadResponseStructs); + ev_state.CloseFileFormat = CMregister_format(ev_state.cm, EVPathRemoteCommon::CloseFileStructs); + ev_state.KillServerFormat = + CMregister_format(ev_state.cm, EVPathRemoteCommon::KillServerStructs); + ev_state.KillResponseFormat = + CMregister_format(ev_state.cm, EVPathRemoteCommon::KillResponseStructs); + ev_state.StatusServerFormat = + CMregister_format(ev_state.cm, EVPathRemoteCommon::StatusServerStructs); ev_state.StatusResponseFormat = - CMregister_format(ev_state.cm, RemoteCommon::StatusResponseStructs); + CMregister_format(ev_state.cm, EVPathRemoteCommon::StatusResponseStructs); } } } diff --git a/source/adios2/toolkit/remote/remote_common.h b/source/adios2/toolkit/remote/remote_common.h index 0d78bd290a..6ecf3a09f3 100644 --- a/source/adios2/toolkit/remote/remote_common.h +++ b/source/adios2/toolkit/remote/remote_common.h @@ -5,7 +5,7 @@ namespace adios2 { -namespace RemoteCommon +namespace EVPathRemoteCommon { const int ServerPort = 26200; diff --git a/source/adios2/toolkit/remote/remote_server.cpp b/source/adios2/toolkit/remote/remote_server.cpp index cef276ac08..03940403e4 100644 --- a/source/adios2/toolkit/remote/remote_server.cpp +++ b/source/adios2/toolkit/remote/remote_server.cpp @@ -36,7 +36,7 @@ #include "remote_common.h" -using namespace adios2::RemoteCommon; +using namespace adios2::EVPathRemoteCommon; using namespace adios2::core; using namespace adios2; @@ -94,8 +94,9 @@ class AnonADIOSFile std::string m_FileName; size_t m_BytesSent = 0; size_t m_OperationCount = 0; - RemoteFileMode m_mode = RemoteCommon::RemoteFileMode::RemoteOpen; - AnonADIOSFile(std::string FileName, RemoteCommon::RemoteFileMode mode, bool RowMajorArrays) + RemoteFileMode m_mode = EVPathRemoteCommon::RemoteFileMode::RemoteOpen; + AnonADIOSFile(std::string FileName, EVPathRemoteCommon::RemoteFileMode mode, + bool RowMajorArrays) { Mode adios_read_mode = adios2::Mode::Read; m_FileName = FileName; diff --git a/source/adios2/toolkit/transport/file/FileRemote.cpp b/source/adios2/toolkit/transport/file/FileRemote.cpp index 28477c58d4..36779920c4 100644 --- a/source/adios2/toolkit/transport/file/FileRemote.cpp +++ b/source/adios2/toolkit/transport/file/FileRemote.cpp @@ -8,6 +8,7 @@ #include "adios2/helper/adiosLog.h" #include "adios2/helper/adiosString.h" #include "adios2/helper/adiosSystem.h" +#include "adios2/toolkit/remote/EVPathRemote.h" #include // remove #include // strerror @@ -95,9 +96,10 @@ void FileRemote::Open(const std::string &name, const Mode openMode, const bool a case Mode::Read: { ProfilerStart("open"); - m_Remote.OpenSimpleFile("localhost", RemoteCommon::ServerPort, m_Name); + m_Remote = std::unique_ptr(new EVPathRemote()); + m_Remote->OpenSimpleFile("localhost", EVPathRemoteCommon::ServerPort, m_Name); ProfilerStop("open"); - m_Size = m_Remote.m_Size; + m_Size = m_Remote->m_Size; break; } default: @@ -156,7 +158,7 @@ void FileRemote::Read(char *buffer, size_t size, size_t start) " whose size is " + std::to_string(m_Size)); } - m_Remote.Read(start, size, buffer); + m_Remote->Read(start, size, buffer); if (m_IsCached) { } diff --git a/source/adios2/toolkit/transport/file/FileRemote.h b/source/adios2/toolkit/transport/file/FileRemote.h index 27c1a73d70..e2531a9323 100644 --- a/source/adios2/toolkit/transport/file/FileRemote.h +++ b/source/adios2/toolkit/transport/file/FileRemote.h @@ -73,7 +73,7 @@ class FileRemote : public Transport // static class Impl m_ImplSingleton; // Impl *m_Impl; // std::unique_ptr m_Impl; - Remote m_Remote; + std::unique_ptr m_Remote; int m_Errno = 0; bool m_IsOpening = false; std::future m_OpenFuture;