diff --git a/CMakeLists.txt b/CMakeLists.txt index befa3a7..488c85c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,7 @@ if (NOT HAVE_CLOCK_GETTIME) endif() endif() +add_subdirectory(include) add_subdirectory(src) include(CTest) diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt new file mode 100644 index 0000000..313f6db --- /dev/null +++ b/include/CMakeLists.txt @@ -0,0 +1,6 @@ +# Copyright (c) 2021-2022 Barcelona Supercomputing Center (BSC) +# SPDX-License-Identifier: GPL-3.0-or-later + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +install(FILES ovni.h DESTINATION include) diff --git a/src/ovni.h b/include/ovni.h similarity index 100% rename from src/ovni.h rename to include/ovni.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4b4544b..a7bcb60 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,69 +1,13 @@ # Copyright (c) 2021-2022 Barcelona Supercomputing Center (BSC) # SPDX-License-Identifier: GPL-3.0-or-later -add_library(ovni SHARED - ovni.c - parson.c -) +add_subdirectory(include) -set_target_properties(ovni PROPERTIES - VERSION 1.0.0 - SOVERSION 1) - -target_include_directories(ovni PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +add_library(parson STATIC parson.c) +target_include_directories(parson PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") configure_file("config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/config.h" ) include_directories(${CMAKE_CURRENT_BINARY_DIR}) -add_executable(ovniemu - chan.c - emu.c - emu_nosv.c - emu_openmp.c - emu_ovni.c - emu_tampi.c - emu_nodes.c - emu_kernel.c - emu_nanos6.c - emu_task.c - trace.c - ovni.c - parson.c - pcf.c - prv.c -) - -add_executable(ovnidump - dump.c - ovni.c - trace.c - parson.c -) - -add_executable(ovnisort - sort.c - ovni.c - trace.c - parson.c -) - -# Use _ROOT variables if available, commonly used by MPI -# installations -if(POLICY CMP0074) - cmake_policy(SET CMP0074 NEW) -endif() - -find_package(MPI REQUIRED) - -if(NOT MPI_USE_RUNPATH) - # Ensure we use RPATH (not RUNPATH) to link with MPI library, so we are - # protected against LD_LIBRARY_PATH overrides. - target_link_options(MPI::MPI_C INTERFACE "LINKER:--disable-new-dtags") -endif() - -add_executable(ovnisync ovnisync.c) -target_link_libraries(ovnisync m MPI::MPI_C) - -install(TARGETS ovni LIBRARY DESTINATION lib) -install(TARGETS ovniemu ovnidump ovnisync ovnisort RUNTIME DESTINATION bin) -install(FILES ovni.h DESTINATION include) +add_subdirectory(rt) +add_subdirectory(emu) diff --git a/src/emu/CMakeLists.txt b/src/emu/CMakeLists.txt new file mode 100644 index 0000000..9fecbbd --- /dev/null +++ b/src/emu/CMakeLists.txt @@ -0,0 +1,47 @@ +# Copyright (c) 2021-2022 Barcelona Supercomputing Center (BSC) +# SPDX-License-Identifier: GPL-3.0-or-later + +add_library(trace STATIC trace.c) +target_link_libraries(trace parson ovni-static) + +add_library(emu STATIC + chan.c + emu.c + nosv.c + openmp.c + ovni.c + tampi.c + nodes.c + kernel.c + nanos6.c + task.c + pcf.c + prv.c +) + +include_directories( + "${CMAKE_SOURCE_DIR}/src/include" + "${CMAKE_SOURCE_DIR}/src" + "${CMAKE_SOURCE_DIR}/include" +) + +add_executable(ovniemu ovniemu.c) +target_link_libraries(ovniemu emu trace) + +add_executable(ovnidump ovnidump.c) +target_link_libraries(ovnidump emu trace) + +add_executable(ovnisort ovnisort.c) +target_link_libraries(ovnisort emu trace) + +# Use _ROOT variables if available, commonly used by MPI +# installations +if(POLICY CMP0074) + cmake_policy(SET CMP0074 NEW) +endif() + +find_package(MPI REQUIRED) +add_executable(ovnisync ovnisync.c) +target_link_libraries(ovnisync m MPI::MPI_C) + +install(TARGETS ovniemu ovnidump ovnisync ovnisort RUNTIME DESTINATION bin) diff --git a/src/chan.c b/src/emu/chan.c similarity index 100% rename from src/chan.c rename to src/emu/chan.c diff --git a/src/chan.h b/src/emu/chan.h similarity index 100% rename from src/chan.h rename to src/emu/chan.h diff --git a/src/emu.c b/src/emu/emu.c similarity index 98% rename from src/emu.c rename to src/emu/emu.c index e1463f9..84f73f4 100644 --- a/src/emu.c +++ b/src/emu/emu.c @@ -448,8 +448,8 @@ emu_load_first_events(struct ovni_emu *emu) } } -static void -emulate(struct ovni_emu *emu) +void +emu_run(struct ovni_emu *emu) { emu->nev_processed = 0; emu_load_first_events(emu); @@ -1001,7 +1001,7 @@ create_pcf_cpus(struct ovni_emu *emu) } } -static void +void emu_init(struct ovni_emu *emu, int argc, char *argv[]) { memset(emu, 0, sizeof(*emu)); @@ -1184,7 +1184,7 @@ copy_configs(struct ovni_emu *emu) } } -static void +void emu_post(struct ovni_emu *emu) { /* Write the PCF files */ @@ -1197,7 +1197,7 @@ emu_post(struct ovni_emu *emu) copy_configs(emu); } -static void +void emu_destroy(struct ovni_emu *emu) { fix_prv_headers(emu); @@ -1248,24 +1248,3 @@ eerr(struct ovni_emu *emu, const char *fmt, ...) emu->cur_ev->header.clock, emu->cur_thread->tid); } - -int -main(int argc, char *argv[]) -{ - struct ovni_emu *emu = malloc(sizeof(struct ovni_emu)); - - if (emu == NULL) { - perror("malloc"); - return 1; - } - - emu_init(emu, argc, argv); - err("emulation starts\n"); - emulate(emu); - emu_post(emu); - emu_destroy(emu); - err("emulation ends\n"); - free(emu); - - return 0; -} diff --git a/src/emu.h b/src/emu/emu.h similarity index 98% rename from src/emu.h rename to src/emu/emu.h index ad033d7..ce8338e 100644 --- a/src/emu.h +++ b/src/emu/emu.h @@ -578,4 +578,9 @@ struct ovni_ethread *emu_get_thread(struct ovni_eproc *proc, int tid); void emu_cpu_update_chan(struct ovni_cpu *cpu, struct ovni_chan *cpu_chan); +void emu_init(struct ovni_emu *emu, int argc, char *argv[]); +void emu_run(struct ovni_emu *emu); +void emu_post(struct ovni_emu *emu); +void emu_destroy(struct ovni_emu *emu); + #endif /* OVNI_EMU_H */ diff --git a/src/emu_kernel.c b/src/emu/kernel.c similarity index 100% rename from src/emu_kernel.c rename to src/emu/kernel.c diff --git a/src/emu_nanos6.c b/src/emu/nanos6.c similarity index 99% rename from src/emu_nanos6.c rename to src/emu/nanos6.c index 89f4e46..f2aa2e8 100644 --- a/src/emu_nanos6.c +++ b/src/emu/nanos6.c @@ -6,7 +6,7 @@ #include "chan.h" #include "emu.h" -#include "emu_task.h" +#include "task.h" #include "ovni.h" #include "prv.h" diff --git a/src/emu_nodes.c b/src/emu/nodes.c similarity index 100% rename from src/emu_nodes.c rename to src/emu/nodes.c diff --git a/src/emu_nosv.c b/src/emu/nosv.c similarity index 99% rename from src/emu_nosv.c rename to src/emu/nosv.c index 087ba19..ee1b06f 100644 --- a/src/emu_nosv.c +++ b/src/emu/nosv.c @@ -6,7 +6,7 @@ #include "chan.h" #include "emu.h" -#include "emu_task.h" +#include "task.h" #include "ovni.h" #include "prv.h" diff --git a/src/emu_openmp.c b/src/emu/openmp.c similarity index 100% rename from src/emu_openmp.c rename to src/emu/openmp.c diff --git a/src/emu_ovni.c b/src/emu/ovni.c similarity index 100% rename from src/emu_ovni.c rename to src/emu/ovni.c diff --git a/src/dump.c b/src/emu/ovnidump.c similarity index 100% rename from src/dump.c rename to src/emu/ovnidump.c diff --git a/src/emu/ovniemu.c b/src/emu/ovniemu.c new file mode 100644 index 0000000..f81ea23 --- /dev/null +++ b/src/emu/ovniemu.c @@ -0,0 +1,24 @@ +#include "emu.h" + +#include + +int +main(int argc, char *argv[]) +{ + struct ovni_emu *emu = malloc(sizeof(struct ovni_emu)); + + if (emu == NULL) { + perror("malloc"); + return 1; + } + + emu_init(emu, argc, argv); + err("emulation starts\n"); + emu_run(emu); + emu_post(emu); + emu_destroy(emu); + err("emulation ends\n"); + free(emu); + + return 0; +} diff --git a/src/sort.c b/src/emu/ovnisort.c similarity index 100% rename from src/sort.c rename to src/emu/ovnisort.c diff --git a/src/ovnisync.c b/src/emu/ovnisync.c similarity index 100% rename from src/ovnisync.c rename to src/emu/ovnisync.c diff --git a/src/pcf.c b/src/emu/pcf.c similarity index 100% rename from src/pcf.c rename to src/emu/pcf.c diff --git a/src/pcf.h b/src/emu/pcf.h similarity index 100% rename from src/pcf.h rename to src/emu/pcf.h diff --git a/src/prv.c b/src/emu/prv.c similarity index 100% rename from src/prv.c rename to src/emu/prv.c diff --git a/src/prv.h b/src/emu/prv.h similarity index 100% rename from src/prv.h rename to src/emu/prv.h diff --git a/src/emu_tampi.c b/src/emu/tampi.c similarity index 100% rename from src/emu_tampi.c rename to src/emu/tampi.c diff --git a/src/emu_task.c b/src/emu/task.c similarity index 99% rename from src/emu_task.c rename to src/emu/task.c index 1aafdb6..ba5d122 100644 --- a/src/emu_task.c +++ b/src/emu/task.c @@ -6,7 +6,7 @@ #include "chan.h" #include "emu.h" -#include "emu_task.h" +#include "task.h" #include "ovni.h" #include "prv.h" diff --git a/src/emu_task.h b/src/emu/task.h similarity index 100% rename from src/emu_task.h rename to src/emu/task.h diff --git a/src/trace.c b/src/emu/trace.c similarity index 100% rename from src/trace.c rename to src/emu/trace.c diff --git a/src/trace.h b/src/emu/trace.h similarity index 100% rename from src/trace.h rename to src/emu/trace.h diff --git a/src/include/CMakeLists.txt b/src/include/CMakeLists.txt new file mode 100644 index 0000000..75356a2 --- /dev/null +++ b/src/include/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2021-2022 Barcelona Supercomputing Center (BSC) +# SPDX-License-Identifier: GPL-3.0-or-later + +include_directories("${CMAKE_CURRENT_SOURCE_DIR}") diff --git a/src/common.h b/src/include/common.h similarity index 100% rename from src/common.h rename to src/include/common.h diff --git a/src/compat.h b/src/include/compat.h similarity index 95% rename from src/compat.h rename to src/include/compat.h index 3ae7229..0485da2 100644 --- a/src/compat.h +++ b/src/include/compat.h @@ -19,4 +19,4 @@ gettid(void) #endif /* !__GLIBC_PREREQ(2, 30) */ #endif /* defined(__GLIBC__) */ -#endif// COMPAT_H +#endif /* COMPAT_H */ diff --git a/src/heap.h b/src/include/heap.h similarity index 100% rename from src/heap.h rename to src/include/heap.h diff --git a/src/uthash.h b/src/include/uthash.h similarity index 100% rename from src/uthash.h rename to src/include/uthash.h diff --git a/src/utlist.h b/src/include/utlist.h similarity index 100% rename from src/utlist.h rename to src/include/utlist.h diff --git a/src/rt/CMakeLists.txt b/src/rt/CMakeLists.txt new file mode 100644 index 0000000..0ce4af8 --- /dev/null +++ b/src/rt/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright (c) 2021-2022 Barcelona Supercomputing Center (BSC) +# SPDX-License-Identifier: GPL-3.0-or-later + +include_directories("${CMAKE_SOURCE_DIR}/src/include") + +add_library(ovni SHARED ovni.c) +target_link_libraries(ovni parson) +target_include_directories(ovni PUBLIC "${CMAKE_SOURCE_DIR}/include") +set_target_properties(ovni PROPERTIES + VERSION 1.0.0 + SOVERSION 1) + +add_library(ovni-static STATIC ovni.c) +target_link_libraries(ovni-static parson) +target_include_directories(ovni-static PUBLIC "${CMAKE_SOURCE_DIR}/include") + +install(TARGETS ovni LIBRARY DESTINATION lib) diff --git a/src/ovni.c b/src/rt/ovni.c similarity index 100% rename from src/ovni.c rename to src/rt/ovni.c diff --git a/test/macros.cmake b/test/macros.cmake index da3d980..670d81a 100644 --- a/test/macros.cmake +++ b/test/macros.cmake @@ -41,7 +41,7 @@ function(ovni_test source) "OVNI_NPROCS=${OVNI_TEST_NPROC}") list(APPEND OVNI_TEST_ENV - "OVNI_BUILD_DIR=${CMAKE_BINARY_DIR}/src") + "OVNI_BUILD_DIR=${CMAKE_BINARY_DIR}/src/emu") list(APPEND OVNI_TEST_ENV "OVNI_CURRENT_DIR=${CMAKE_CURRENT_BINARY_DIR}") @@ -53,6 +53,11 @@ function(ovni_test source) list(APPEND OVNI_TEST_ENV "OVNI_DO_SORT=1") endif() + include_directories( + "${CMAKE_SOURCE_DIR}/src/include" + "${CMAKE_SOURCE_DIR}/src" + "${CMAKE_SOURCE_DIR}/include" + ) add_executable("${OVNI_TEST_NAME}" "${OVNI_TEST_SOURCE}") target_link_libraries("${OVNI_TEST_NAME}" PRIVATE ovni)