Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ endif()

add_subdirectory(src)

# Run the tests
enable_testing()
add_subdirectory(test)
if(NOT IMPORT_AS_LIB)
# Run the tests
enable_testing()
add_subdirectory(test)

# Generate and inspect documentation
add_subdirectory(docs)
# Generate and inspect documentation
add_subdirectory(docs)
endif()
10 changes: 6 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set(rscore_srcs
init.c
core/sync.c
datatypes/msg_queue.c
distributed/control_msg.c
core/control_msg.c
gvt/fossil.c
gvt/gvt.c
gvt/termination.c
Expand All @@ -35,7 +35,7 @@ endif()
add_library(rscore STATIC ${rscore_srcs})

target_compile_definitions(rscore PRIVATE ROOTSIM_VERSION="${PROJECT_VERSION}")
target_include_directories(rscore PRIVATE .)
target_include_directories(rscore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include/)
target_link_libraries(rscore ${CMAKE_THREAD_LIBS_INIT} ${EXTRA_LIBS})

if(NOT DISABLE_MPI)
Expand All @@ -44,5 +44,7 @@ if(NOT DISABLE_MPI)
target_link_libraries(rscore ${MPI_C_LIBRARIES})
endif()

install(FILES ROOT-Sim.h DESTINATION include)
install(TARGETS rscore LIBRARY DESTINATION lib)
if(NOT IMPORT_AS_LIB)
install(DIRECTORY include/ DESTINATION include)
install(TARGETS rscore LIBRARY DESTINATION lib)
endif()
135 changes: 135 additions & 0 deletions src/core/control_msg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/**
* @file core/control_msg.c
*
* @brief MPI remote control messages module
*
* The module in which remote control messages are wired to the other modules
*
* SPDX-FileCopyrightText: 2008-2023 HPDCS Group <rootsim@googlegroups.com>
* SPDX-License-Identifier: GPL-3.0-only
*/
#include "include/ROOT-Sim/sdk.h"
#include "control_msg.h"
#include "distributed/mpi.h"

/// This structure is used to store the handlers for the control messages
struct library_handler {
/// The control message id
unsigned control_msg_id;
/// The handler for the control message
control_msg_handler_t handler;
};

/// The array of handlers for the control messages
static struct library_handler *library_handlers = NULL;
/// The capacity of the array of handlers for the control messages
static size_t library_handlers_capacity = 0;
/// The current number of used slots in the array of handlers for the control messages
static size_t library_handlers_size = 0;
/// The next control message ID
static int next_control_msg_id = FIRST_LIBRARY_CONTROL_MSG_ID;

/**
* @brief Initialize the control message module
*/
void control_msg_init(void)
{
if(library_handlers != NULL) {
logger(LOG_WARN, "Trying to reinitialize control message module, ignoring!");
return;
}

size_t size = INITIAL_HANDLERS_CAPACITY * sizeof(*library_handlers);
void *ptr = malloc(size);
if (ptr != NULL) {
library_handlers_capacity = INITIAL_HANDLERS_CAPACITY;
library_handlers = ptr;
} else {
logger(LOG_FATAL, "Error initializing control message module!");
abort();
}
}

/**
* @brief Finalize the control message module
*/
void control_msg_fini(void)
{
if(library_handlers != NULL) {
free(library_handlers);
library_handlers = NULL;
}
}

int control_msg_register_handler(control_msg_handler_t handler)
{
if (library_handlers_size >= library_handlers_capacity) {
size_t new_capacity = library_handlers_capacity * 2;
struct library_handler *new_handlers = realloc(library_handlers, new_capacity * sizeof(*new_handlers));
if (new_handlers == NULL) {
logger(LOG_FATAL, "Error registering external library handler!");
abort();
}
library_handlers = new_handlers;
library_handlers_capacity = new_capacity;
}

int ret = next_control_msg_id++;
library_handlers[library_handlers_size].control_msg_id = ret;
library_handlers[library_handlers_size].handler = handler;
library_handlers_size++;
return ret;
}


/**
* @brief Invoke a library handler
* @param code the control message ID
* @param payload the payload of the control message
*/
void invoke_library_handler(unsigned code, const void *payload)
{
for (size_t i = 0; i < library_handlers_size; i++) {
if (library_handlers[i].control_msg_id == code) {
library_handlers[i].handler(code, payload);
return;
}
}
logger(LOG_FATAL, "No library handler registered for code %u", code);
abort();
}


/**
* @brief Handle a received control message
* @param ctrl the tag of the received control message
*/
void control_msg_process(enum platform_ctrl_msg_code ctrl)
{
switch(ctrl) {
case MSG_CTRL_GVT_START:
gvt_start_processing();
break;
case MSG_CTRL_GVT_DONE:
gvt_on_done_ctrl_msg();
break;
case MSG_CTRL_TERMINATION:
termination_on_ctrl_msg();
break;
default:
#ifndef NDEBUG
logger(LOG_WARN, "Unknown control message code %d", ctrl);
#else
__builtin_unreachable();
#endif
}
}

void control_msg_broadcast(unsigned ctrl, const void *payload, size_t size)
{
if(global_config.serial || (n_nodes == 1)) {
invoke_library_handler(ctrl, payload);
} else {
mpi_library_control_msg_broadcast(ctrl, payload, size);
}
}
49 changes: 49 additions & 0 deletions src/core/control_msg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* @file core/control_msg.h
*
* @brief MPI remote control messages header
*
* The module in which remote control messages are wired to the other modules
*
* SPDX-FileCopyrightText: 2008-2023 HPDCS Group <rootsim@googlegroups.com>
* SPDX-License-Identifier: GPL-3.0-only
*/
#pragma once

#include "lp/msg.h"
#include "gvt/gvt.h"
#include "gvt/termination.h"
#include "include/ROOT-Sim/sdk.h"

/// The initial size of the handlers dynamic vector
#define INITIAL_HANDLERS_CAPACITY 4
/// The first control message ID that will be returned to the external libraries
#define FIRST_LIBRARY_CONTROL_MSG_ID 0

/// The size of the maximum payload of a control message
#define CONTROL_MSG_PAYLOAD_SIZE 16

/// A control message MPI tag value
enum platform_ctrl_msg_code {
/// Used by the master to start a new gvt reduction operation
MSG_CTRL_GVT_START = 1,
/// Used by slaves to signal their completion of the gvt protocol
MSG_CTRL_GVT_DONE,
/// Used in broadcast to signal that local LPs can terminate
MSG_CTRL_TERMINATION
};

/// A control message that can be user by higher-level libraries to synchronize actions
/* cppcheck-suppress misra-c2012-2.4
* The payload is anything used specified, and the size is checked in the code */
struct library_ctrl_msg {
/// The control message code
unsigned ctrl_code;
/// The payload of the control message
unsigned char payload[CONTROL_MSG_PAYLOAD_SIZE];
};

extern void control_msg_init(void);
extern void control_msg_fini(void);
extern void control_msg_process(enum platform_ctrl_msg_code ctrl);
extern void invoke_library_handler(unsigned code, const void *payload);
32 changes: 0 additions & 32 deletions src/distributed/control_msg.c

This file was deleted.

26 changes: 0 additions & 26 deletions src/distributed/control_msg.h

This file was deleted.

Loading