Skip to content

Commit

Permalink
Introduced MTCL namespace.
Browse files Browse the repository at this point in the history
Fixed some bugs on Makefile(s).
Fixed tests and examples in order to use the introduced namespace.
  • Loading branch information
Nicolò Tonci committed Dec 27, 2023
1 parent 94b232b commit ddebd3c
Show file tree
Hide file tree
Showing 28 changed files with 166 additions and 84 deletions.
9 changes: 7 additions & 2 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ ifdef SINGLE_IO_THREAD
CXXFLAGS +=-DSINGLE_IO_THREAD
endif

ifeq ($(findstring SHM,$(TPROTOCOL)),SHM)
CXXFLAGS += -DENABLE_SHM
LIBS += -lrt
endif

ifeq ($(findstring MPI,$(TPROTOCOL)),MPI)
CXX = mpicxx
CXXFLAGS += -DENABLE_$(TPROTOCOL)
CXXFLAGS += -DENABLE_MPI
TARGET = ../include/protocols/stop_accept
ifdef MPI_HOME
INCS += `pkg-config --cflags-only-I $(MPI_HOME)/lib/pkgconfig/ompi-cxx.pc`
Expand Down Expand Up @@ -48,7 +53,7 @@ endif
endif

CXXFLAGS += -Wall
LIBS += -pthread -lrt
LIBS += -pthread
INCLUDES = $(INCS)

SOURCES = $(wildcard *.cpp)
Expand Down
1 change: 1 addition & 0 deletions examples/hello_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "mtcl.hpp"

using namespace std::chrono_literals;
using namespace MTCL;

const std::string welcome{"Hello!"}; // welcome message
const std::string bye{"Bye!"}; // bye bye message
Expand Down
14 changes: 7 additions & 7 deletions examples/pingpong.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,16 @@ int main(int argc, char** argv){
#endif

int rank = atoi(argv[1]);
Manager::init(argv[1]);
MTCL::Manager::init(argv[1]);

// Listening for new connections, expecting "ping", sending "pong"
if(rank == 0) {
Manager::listen(listen_str);
MTCL::Manager::listen(listen_str);

int count = 0;
while(count < MAX_NUM_CLIENTS) {

auto handle = Manager::getNext();
auto handle = MTCL::Manager::getNext();

if(handle.isNewConnection()) {
char buff[5];
Expand Down Expand Up @@ -134,7 +134,7 @@ int main(int argc, char** argv){
else {
bool connected=false;
for(int i=0;i<10;++i) {
auto h = Manager::connect(connect_str);
auto h = MTCL::Manager::connect(connect_str);
if(h.isValid()) {
char buff[5]{'p','i','n','g','\0'};
if (h.send(buff, sizeof(buff)) != 5) {
Expand All @@ -152,11 +152,11 @@ int main(int argc, char** argv){
}
if (!connected) {
MTCL_PRINT(0, "[Client]:\t", "unable to connect to the server, exit!\n");
Manager::finalize();
MTCL::Manager::finalize();
return -1;
}

auto handle = Manager::getNext();
auto handle = MTCL::Manager::getNext();
char buff[5];
size_t r;

Expand All @@ -173,7 +173,7 @@ int main(int argc, char** argv){
}
}

Manager::finalize();
MTCL::Manager::finalize();

return 0;
}
1 change: 1 addition & 0 deletions examples/reqrep-th.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "mtcl.hpp"

using namespace std::chrono_literals;
using namespace MTCL;

const int nmsg=100;
const int maxwaittime=10; // milliseconds
Expand Down
3 changes: 3 additions & 0 deletions include/collectives/collectiveContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "uccImpl.hpp"
#endif

namespace MTCL {

class CollectiveContext : public CommunicationHandle {
friend class Manager;
Expand Down Expand Up @@ -324,4 +325,6 @@ CollectiveContext *createContext(HandleType type, int size, bool root, int rank)
}
}

} // namespace

#endif //COLLECTIVECONTEXT_HPP
3 changes: 3 additions & 0 deletions include/collectives/collectiveImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "../handle.hpp"
#include "../utils.hpp"

namespace MTCL {

enum ImplementationType {
GENERIC,
Expand Down Expand Up @@ -866,4 +867,6 @@ class AlltoallGeneric : public CollectiveImpl {
~AlltoallGeneric () {}
};

} // namespace

#endif //COLLECTIVEIMPL_HPP
3 changes: 3 additions & 0 deletions include/collectives/mpiImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <mpi.h>
#include <cassert>

namespace MTCL {
/**
* @brief MPI implementation of collective operations. Abstract class, only provides
* generic functionalities for collectives using the MPI transport. Subclasses must
Expand Down Expand Up @@ -538,4 +539,6 @@ class AlltoallMPI : public MPICollective {
}
};

} // namespace

#endif //MPICOLLIMPL_HPP
4 changes: 4 additions & 0 deletions include/collectives/uccImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "collectiveImpl.hpp"
#include <ucc/api/ucc.h>

namespace MTCL {

#define STR(x) #x
#define UCC_CHECK(_call) \
if (UCC_OK != (_call)) { \
Expand Down Expand Up @@ -689,4 +691,6 @@ class AlltoallUCC : public UCCCollective {
}
};

} // namespace

#endif //UCCCOLLIMPL_HPP
3 changes: 2 additions & 1 deletion include/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define CONFIG_HPP

#include <string>

namespace MTCL {
// -------------- some configuration parameters ----------------

// all timeouts are in microseconds unless otherwise stated
Expand Down Expand Up @@ -48,4 +48,5 @@ const int CCONNECTION_RETRY = 10;
const unsigned CCONNECTION_TIMEOUT = 100; // milliseconds
const int GATHER_THRESHOLD_MSG_SIZE = (1<<18); // bytes

} //namespace
#endif
3 changes: 3 additions & 0 deletions include/handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "protocolInterface.hpp"
#include "utils.hpp"

namespace MTCL {

enum HandleType {
MTCL_BROADCAST,
MTCL_SCATTER,
Expand Down Expand Up @@ -207,4 +209,5 @@ void ConnType::setAsClosed(Handle* h, bool blockflag){

}

} // namespace
#endif
3 changes: 3 additions & 0 deletions include/handleUser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "handle.hpp"
#include "errno.h"

namespace MTCL {

class HandleUser {
friend class ConnType;
friend class Manager;
Expand Down Expand Up @@ -203,5 +205,6 @@ class HandleUser {

};

} // namespace
#endif

16 changes: 12 additions & 4 deletions include/manager.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef MANAGER_HPP
#define MANAGER_HPP
#ifndef MTCL_MANAGER_HPP
#define MTCL_MANAGER_HPP

#include <csignal>
#include <cstdlib>
Expand All @@ -11,12 +11,12 @@
#include <thread>
#include <condition_variable>
#include <sstream>
#include <cassert>

#include "handle.hpp"
#include "handleUser.hpp"
#include "protocolInterface.hpp"
#include "protocols/tcp.hpp"
#include "protocols/shm.hpp"

#ifdef ENABLE_CONFIGFILE
#include <fstream>
Expand Down Expand Up @@ -44,6 +44,11 @@
#include "protocols/ucx.hpp"
#endif

#ifdef ENABLE_SHM
#include "protocols/shm.hpp"
#endif
namespace MTCL {

int mtcl_verbose = -1;

/**
Expand Down Expand Up @@ -216,7 +221,7 @@ class Manager {
for(auto& [prot, conn] : protocolsMap) {
conn->update();
}
if constexpr (IO_THREAD_POLL_TIMEOUT)
if constexpr (IO_THREAD_POLL_TIMEOUT > 0)
std::this_thread::sleep_for(std::chrono::microseconds(IO_THREAD_POLL_TIMEOUT));

#ifndef MTCL_DISABLE_COLLECTIVES
Expand Down Expand Up @@ -335,7 +340,9 @@ class Manager {
// default transports protocol
registerType<ConnTcp>("TCP");

#ifdef ENABLE_SHM
registerType<ConnSHM>("SHM");
#endif

#ifdef ENABLE_MPI
registerType<ConnMPI>("MPI");
Expand Down Expand Up @@ -947,4 +954,5 @@ void CollectiveContext::yield() {
}
#endif

} //namespace
#endif
3 changes: 3 additions & 0 deletions include/mtcl.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef COMMLIB_HPP
#define COMMLIB_HPP

namespace MTCL {

#if defined(ENABLE_MPI)
const bool MPI_ENABLED = true;
Expand All @@ -20,6 +21,8 @@ const bool UCX_ENABLED = false;
const bool UCC_ENABLED = false;
#endif

} // namespace


#include "config.hpp"
#include "utils.hpp"
Expand Down
4 changes: 4 additions & 0 deletions include/protocolInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <functional>
#include <errno.h>

namespace MTCL {

class Handle;
class ConnType {

Expand Down Expand Up @@ -84,4 +86,6 @@ class ConnType {
virtual void end(bool blockflag=false) = 0;
};

} // namespace

#endif
4 changes: 2 additions & 2 deletions include/protocols/mpi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "../utils.hpp"
#include "../config.hpp"


namespace MTCL {

class HandleMPI : public Handle {

Expand Down Expand Up @@ -321,6 +321,6 @@ class ConnMPI : public ConnType {
}
};


} // namespace

#endif
3 changes: 3 additions & 0 deletions include/protocols/mpip2p.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "../utils.hpp"
#include "../config.hpp"

namespace MTCL {

class HandleMPIP2P : public Handle {

Expand Down Expand Up @@ -365,4 +366,6 @@ class ConnMPIP2P : public ConnType {

};

} // namespace

#endif
3 changes: 3 additions & 0 deletions include/protocols/mqtt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "../config.hpp"
#include "../utils.hpp"

namespace MTCL {

class HandleMQTT : public Handle {

Expand Down Expand Up @@ -389,4 +390,6 @@ class ConnMQTT : public ConnType {

};

} // namespace

#endif
2 changes: 2 additions & 0 deletions include/protocols/shm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "../protocolInterface.hpp"
#include "shm_buffer.hpp"

namespace MTCL {

class HandleSHM : public Handle {
public:
Expand Down Expand Up @@ -213,5 +214,6 @@ class ConnSHM : public ConnType {

};

} // namespace

#endif
5 changes: 5 additions & 0 deletions include/protocols/shm_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@

#include <pthread.h>

namespace MTCL {

/*
* shared-memory buffer, one single slot of SHM_SMAL_MSG_SIZE size
*/

class shmBuffer {
protected:
struct buffer_element_t {
Expand Down Expand Up @@ -281,4 +284,6 @@ class shmBuffer {
}
};

} // namespace

#endif
4 changes: 3 additions & 1 deletion include/protocols/tcp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "../handle.hpp"
#include "../protocolInterface.hpp"


namespace MTCL {

class HandleTCP : public Handle {

Expand Down Expand Up @@ -426,4 +426,6 @@ class ConnTcp : public ConnType {

};

} // namespace

#endif
Loading

0 comments on commit ddebd3c

Please sign in to comment.