Skip to content

Commit

Permalink
Merge pull request #2 from Analytics4MD/dspaces_2_w_ci
Browse files Browse the repository at this point in the history
Adds DataSpaces 2 support and GitHub CI
  • Loading branch information
jackdmarquez authored Feb 20, 2024
2 parents c8c125c + b6ba2bc commit 375f5a5
Show file tree
Hide file tree
Showing 20 changed files with 1,351 additions and 281 deletions.
52 changes: 52 additions & 0 deletions .github/basic_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
cmake_minimum_required(VERSION 3.12)
project(a4md_basic_test_ci)

set(CMAKE_VERBOSE_MAKEFILE ON)

set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

find_package(MPI REQUIRED)

cmake_policy(SET CMP0094 NEW)
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
if (NOT ${Python3_VERSION_MAJOR} EQUAL 3)
message(FATAL_ERROR "FindPython3 somehow found a Python install that wasn't Python 3")
endif ()
if (${Python3_VERSION_MINOR} LESS_EQUAL 3)
message(FATAL_ERROR "Found Python 3.${Python3_VERSION_MINOR}.${Python3_VERSION_PATCH}, which has a version less than minimum allowed of 3.3")
endif ()

find_package(Boost 1.59.0 REQUIRED COMPONENTS iostreams serialization)

find_package(A4MD REQUIRED)

add_executable(producer producer.cxx)
add_executable(consumer consumer.cxx)

target_link_libraries(producer MPI::MPI_CXX Python3::Python Boost::boost Boost::iostreams Boost::serialization ${A4MD_LIBRARIES})
target_link_libraries(consumer MPI::MPI_CXX Python3::Python Boost::boost Boost::iostreams Boost::serialization ${A4MD_LIBRARIES})
target_include_directories(producer PRIVATE ${A4MD_INCLUDE_DIRS})
target_include_directories(consumer PRIVATE ${A4MD_INCLUDE_DIRS})

install(TARGETS producer DESTINATION bin)
install(TARGETS consumer DESTINATION bin)
install(FILES flux_prod_cons.sh
DESTINATION bin
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_WRITE GROUP_EXECUTE
WORLD_READ WORLD_WRITE WORLD_EXECUTE
)
install(FILES local_prod_cons.sh
DESTINATION bin
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_WRITE GROUP_EXECUTE
WORLD_READ WORLD_WRITE WORLD_EXECUTE
)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/script/"
DESTINATION bin
USE_SOURCE_PERMISSIONS
)
79 changes: 79 additions & 0 deletions .github/basic_test/FindA4MD.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Copied from
# https://github.com/Analytics4MD/A4MD-sample-workflow

# Find A4MD include directories and libraries
# A4MD_INCLUDE_DIRECTORIES - where to find A4MD headers
# A4MD_LIBRARIES - list of libraries to link against when using A4MD
# A4MD_FOUND - Do not attempt to use A4MD if "no", "0", or undefined.

include(FindPackageHandleStandardArgs)

find_path(A4MD_INCLUDE_DIRS NAMES chunk.h HINTS
${A4MD_PREFIX}/include
/usr/include
/usr/local/include
/opt/local/include
/sw/include
)

find_library(A4MD_INGEST_LIBRARIES NAMES a4md_ingest HINTS
${A4MD_PREFIX}/lib
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)

find_library(A4MD_RETRIEVE_LIBRARIES NAMES a4md_retrieve HINTS
${A4MD_PREFIX}/lib
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)

find_library(A4MD_DTL_LIBRARIES NAMES a4md_dtl HINTS
${A4MD_PREFIX}/lib
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)

find_library(A4MD_COMMON_LIBRARIES NAMES a4md_cmn HINTS
${A4MD_PREFIX}/lib
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)

set(A4MD_LIBRARIES ${A4MD_INGEST_LIBRARIES} ${A4MD_RETRIEVE_LIBRARIES} ${A4MD_DTL_LIBRARIES} ${A4MD_COMMON_LIBRARIES})

SET(A4MD_TRANSPORT_LIBRARIES "")

find_package(dspaces CONFIG REQUIRED)
set(A4MD_INCLUDE_DIRS ${A4MD_INCLUDE_DIRS})
set(A4MD_TRANSPORT_LIBRARIES ${A4MD_TRANSPORT_LIBRARIES} dspaces::dspaces)
message(STATUS "${A4MD_TRANSPORT_LIBRARIES}")
list(APPEND A4MD_LIBRARIES ${A4MD_TRANSPORT_LIBRARIES})

find_package_handle_standard_args(A4MD DEFAULT_MSG
A4MD_INCLUDE_DIRS
A4MD_INGEST_LIBRARIES
A4MD_RETRIEVE_LIBRARIES
A4MD_DTL_LIBRARIES
A4MD_COMMON_LIBRARIES
A4MD_TRANSPORT_LIBRARIES
)

mark_as_advanced(
A4MD_INCLUDE_DIRS
A4MD_INGEST_LIBRARIES
A4MD_RETRIEVE_LIBRARIES
A4MD_DTL_LIBRARIES
A4MD_COMMON_LIBRARIES
A4MD_TRANSPORT_LIBRARIES
A4MD_LIBRARIES
A4MD_FOUND
)
156 changes: 156 additions & 0 deletions .github/basic_test/consumer.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// Copied from
// https://github.com/Analytics4MD/A4MD-sample-workflow

#include <unistd.h>
#include "mpi.h"
#ifdef DTL_DECAF
#include "decaf_reader.h"
#include <bredala/data_model/boost_macros.h>
#endif
#include "dataspaces_reader.h"
#include "md_stager.h"
#include "md_analyzer.h"
#include "md_retriever.h"
#include "timer.h"

#define DTL_COLOR 0
#define NON_DTL_COLOR 1
#define ROOT 0

int main (int argc, const char** argv)
{
MPI_Init(NULL,NULL);
int rank, app_rank;
MPI_Comm global_comm = MPI_COMM_WORLD;
MPI_Comm app_comm, dtl_comm;
int color;
int *appnum, present;
MPI_Comm_rank(global_comm, &rank);
MPI_Comm_get_attr(global_comm, MPI_APPNUM, &appnum, &present);
MPI_Comm_split(global_comm, *appnum, rank, &app_comm);
MPI_Comm_rank(app_comm, &app_rank);
MPI_Comm_free(&app_comm);
if (app_rank == ROOT)
{
color = DTL_COLOR;
}
else
{
color = NON_DTL_COLOR;
}
MPI_Comm_split(global_comm, color, rank, &dtl_comm);

if (app_rank == ROOT)
{
printf("---======== In Consummer::main()\n");
if (argc < 2)
{
fprintf(stderr, "./consumer decaf json_conf py_path py_func n_frames\n");
fprintf(stderr, "./consumer dataspaces client_id group_id py_path py_func n_frames\n");
return -1;
}
std::string dtl_type((char*)argv[1]);
#ifdef DTL_DECAF
if ( (dtl_type.compare("decaf") != 0) && (dtl_type.compare("dataspaces") != 0) )
{
fprintf(stderr, "ERROR: DTL type must be decaf or dataspaces\n");
return -1;
}
#else
if (dtl_type.compare("dataspaces") != 0)
{
fprintf(stderr, "ERROR: DTL type must be dataspaces\n");
return -1;
}
#endif
std::string json_conf;
std::string py_path;
std::string py_func;
int client_id;
int group_id;
int n_frames;
if (dtl_type.compare("decaf") == 0)
{
if (argc != 6)
{
fprintf(stderr, "ERROR: ./consumer decaf json_conf py_path py_func n_frames\n");
return -1;
}
// Input arguments
json_conf = (char*)argv[2];
py_path = (char*)argv[3];
py_func = (char*)argv[4];
n_frames = atoi(argv[5]);
}

if (dtl_type.compare("dataspaces") == 0)
{
if (argc != 7)
{
fprintf(stderr, "ERROR: ./consumer dataspaces client_id group_id py_path py_func n_frames\n");
return -1;
}
// Input arguments
client_id = atoi(argv[2]);
group_id = atoi(argv[3]);
py_path = (char*)argv[4];
py_func = (char*)argv[5];
n_frames = atoi(argv[6]);
}

// Number of chunks
unsigned long int total_chunks = n_frames;// +1 for the call before simulation starts

// Preprocess Python path
std::size_t module_start = py_path.find_last_of("/");
std::size_t module_end = py_path.rfind(".py");
if (module_end == std::string::npos)
{
fprintf(stderr, "ERROR: Expecting a python module in the python script path argument.\n");
return -1;
}
// get directory
std::string py_dir = (std::string::npos==module_start)? std::string(".") : py_path.substr(0,module_start);
// get file
std::string py_name = py_path.substr(module_start+1, module_end-module_start-1);
printf("Python directory : %s\n", py_dir.c_str());
printf("Python script name : %s\n", py_name.c_str());
printf("Python function: %s\n", py_func.c_str());


ChunkReader* chunk_reader;
#ifdef DTL_DECAF
if (dtl_type.compare("decaf") == 0)
{
chunk_reader = new DecafReader(json_conf, total_chunks, dtl_comm);
}
#endif
if (dtl_type.compare("dataspaces") == 0)
{
chunk_reader = new DataSpacesReader(client_id, group_id, total_chunks, dtl_comm);
}

ChunkWriter *chunk_writer = new MDAnalyzer((char*)py_name.c_str(), (char*)py_func.c_str(), (char*)py_dir.c_str());

ChunkStager *chunk_stager = new MDStager(chunk_reader, chunk_writer);
int n_window_width = 1;
Retriever *retriever = new MDRetriever(*chunk_stager, n_frames, n_window_width);

// Main run
TimeVar t_start = timeNow();
retriever->run();
DurationMilli md_retriever_time_ms = timeNow()-t_start;
auto total_md_retriever_time_ms = md_retriever_time_ms.count();
printf("total_retriever_time_ms : %f\n",total_md_retriever_time_ms);

// Free memory
delete retriever;
delete chunk_stager;
delete chunk_writer;
delete chunk_reader;
}

MPI_Comm_free(&dtl_comm);
MPI_Finalize();
return 0;
}
Loading

0 comments on commit 375f5a5

Please sign in to comment.