mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 00:31:14 +00:00
FairMQ: Implement ofi::TransportFactory ctor/dtor
This commit is contained in:
parent
72bc86f006
commit
3785c0e369
|
@ -73,6 +73,8 @@ class FairMQTransportFactory
|
|||
|
||||
virtual ~FairMQTransportFactory() {};
|
||||
|
||||
struct TransportFactoryError : std::runtime_error { using std::runtime_error::runtime_error; };
|
||||
|
||||
static auto CreateTransportFactory(const std::string& type, const std::string& id = "", const FairMQProgOptions* config = nullptr) -> std::shared_ptr<FairMQTransportFactory>;
|
||||
|
||||
static void FairMQNoCleanup(void* /*data*/, void* /*obj*/)
|
||||
|
|
|
@ -7,7 +7,12 @@
|
|||
********************************************************************************/
|
||||
|
||||
#include <fairmq/ofi/TransportFactory.h>
|
||||
#include <fairmq/Tools.h>
|
||||
|
||||
#include <rdma/fabric.h> // OFI libfabric
|
||||
#include <rdma/fi_errno.h>
|
||||
#include <stdexcept>
|
||||
#include <zmq.h>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
|
@ -19,8 +24,40 @@ namespace ofi
|
|||
using namespace std;
|
||||
|
||||
TransportFactory::TransportFactory(const string& id, const FairMQProgOptions* config)
|
||||
: FairMQTransportFactory{id}
|
||||
: FairMQTransportFactory{id}
|
||||
, fZmqContext{zmq_ctx_new()}
|
||||
{
|
||||
if (!fZmqContext)
|
||||
{
|
||||
throw TransportFactoryError{tools::ToString("Failed creating zmq context, reason: ", zmq_strerror(errno))};
|
||||
}
|
||||
|
||||
auto ofi_hints = fi_allocinfo();
|
||||
ofi_hints->caps = FI_MSG | FI_RMA;
|
||||
ofi_hints->mode = FI_ASYNC_IOV;
|
||||
ofi_hints->addr_format = FI_SOCKADDR_IN;
|
||||
auto ofi_info = fi_allocinfo();
|
||||
if (ofi_hints == nullptr || ofi_info == nullptr)
|
||||
{
|
||||
throw TransportFactoryError{"Failed allocating fi_info structs"};
|
||||
}
|
||||
auto res = fi_getinfo(FI_VERSION(1, 5), nullptr, nullptr, 0, ofi_hints, &ofi_info);
|
||||
if (res != 0)
|
||||
{
|
||||
throw TransportFactoryError{tools::ToString("Failed querying fi_getinfo, reason: ", fi_strerror(res))};
|
||||
}
|
||||
for(auto cursor{ofi_info}; cursor->next != nullptr; cursor = cursor->next)
|
||||
{
|
||||
LOG(debug) << fi_tostr(cursor, FI_TYPE_INFO);
|
||||
}
|
||||
fi_freeinfo(ofi_hints);
|
||||
fi_freeinfo(ofi_info);
|
||||
|
||||
int major, minor, patch;
|
||||
zmq_version(&major, &minor, &patch);
|
||||
auto ofi_version{fi_version()};
|
||||
LOG(debug) << "Transport: Using ZeroMQ (" << major << "." << minor << "." << patch << ") & "
|
||||
<< "OFI libfabric (API " << FI_MAJOR(ofi_version) << "." << FI_MINOR(ofi_version) << ")";
|
||||
}
|
||||
|
||||
auto TransportFactory::CreateMessage() const -> MessagePtr
|
||||
|
@ -80,6 +117,25 @@ auto TransportFactory::GetType() const -> Transport
|
|||
|
||||
TransportFactory::~TransportFactory()
|
||||
{
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
if (zmq_ctx_term(fZmqContext) != 0)
|
||||
{
|
||||
if ((errno == EINTR) && (i < 4))
|
||||
{
|
||||
LOG(warn) << "failed closing zmq context, reason: " << zmq_strerror(errno) << ", trying again";
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(error) << "failed closing zmq context, reason: " << zmq_strerror(errno);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} /* namespace ofi */
|
||||
|
|
|
@ -49,6 +49,9 @@ class TransportFactory : public FairMQTransportFactory
|
|||
auto GetType() const -> Transport override;
|
||||
|
||||
~TransportFactory() override;
|
||||
|
||||
private:
|
||||
void* fZmqContext;
|
||||
}; /* class TransportFactory */
|
||||
|
||||
} /* namespace ofi */
|
||||
|
|
Loading…
Reference in New Issue
Block a user