diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..01a5554b --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,18 @@ +FROM mcr.microsoft.com/devcontainers/cpp:1-ubuntu-24.04 + +ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="none" + +# Optionally install the cmake for vcpkg +COPY ./reinstall-cmake.sh /tmp/ + +RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \ + chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \ + fi \ + && rm -f /tmp/reinstall-cmake.sh + +# [Optional] Uncomment this section to install additional vcpkg ports. +# RUN su vscode -c "${VCPKG_ROOT}/vcpkg install " + +# [Optional] Uncomment this section to install additional packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..af3027eb --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,30 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/cpp +{ + "name": "C++", + "build": { + "dockerfile": "Dockerfile" + }, + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "gcc -v", + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + "remoteUser": "root", + "customizations": { + "vscode": { + "extensions": [ + "ms-vscode.makefile-tools" + ] + } + } +} diff --git a/.devcontainer/reinstall-cmake.sh b/.devcontainer/reinstall-cmake.sh new file mode 100644 index 00000000..408b81d2 --- /dev/null +++ b/.devcontainer/reinstall-cmake.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. +#------------------------------------------------------------------------------------------------------------- +# +set -e + +CMAKE_VERSION=${1:-"none"} + +if [ "${CMAKE_VERSION}" = "none" ]; then + echo "No CMake version specified, skipping CMake reinstallation" + exit 0 +fi + +# Cleanup temporary directory and associated files when exiting the script. +cleanup() { + EXIT_CODE=$? + set +e + if [[ -n "${TMP_DIR}" ]]; then + echo "Executing cleanup of tmp files" + rm -Rf "${TMP_DIR}" + fi + exit $EXIT_CODE +} +trap cleanup EXIT + + +echo "Installing CMake..." +apt-get -y purge --auto-remove cmake +mkdir -p /opt/cmake + +architecture=$(dpkg --print-architecture) +case "${architecture}" in + arm64) + ARCH=aarch64 ;; + amd64) + ARCH=x86_64 ;; + *) + echo "Unsupported architecture ${architecture}." + exit 1 + ;; +esac + +CMAKE_BINARY_NAME="cmake-${CMAKE_VERSION}-linux-${ARCH}.sh" +CMAKE_CHECKSUM_NAME="cmake-${CMAKE_VERSION}-SHA-256.txt" +TMP_DIR=$(mktemp -d -t cmake-XXXXXXXXXX) + +echo "${TMP_DIR}" +cd "${TMP_DIR}" + +curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_BINARY_NAME}" -O +curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_CHECKSUM_NAME}" -O + +sha256sum -c --ignore-missing "${CMAKE_CHECKSUM_NAME}" +sh "${TMP_DIR}/${CMAKE_BINARY_NAME}" --prefix=/opt/cmake --skip-license + +ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake +ln -s /opt/cmake/bin/ctest /usr/local/bin/ctest diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 5ac1d99c..dc4abb94 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -8,10 +8,10 @@ "include/epiworld" ], "defines": [], - "compilerPath": "/usr/bin/clang", + "compilerPath": "/usr/bin/g++", "cStandard": "gnu17", "cppStandard": "c++17", - "intelliSenseMode": "clang-x64" + "intelliSenseMode": "${default}" } ], "version": 4 diff --git a/.vscode/launch.json b/.vscode/launch.json index a50a4e77..957a5829 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -2,7 +2,7 @@ "version": "0.2.0", "configurations": [ { - "name": "C/C++: clang++ build and debug active file", + "name": "C/C++: g++ build and debug active file", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}", @@ -10,8 +10,8 @@ "cwd": "${fileDirname}", "environment": [], "externalConsole": false, - "MIMode": "lldb", - "preLaunchTask": "C/C++: clang++ build active file" + "MIMode": "gdb", + "preLaunchTask": "C/C++: g++ build active file" }, ] } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 53186679..40312305 100755 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -2,13 +2,13 @@ "tasks": [ { "type": "cppbuild", - "label": "C/C++: clang++ build active file", - "command": "/usr/bin/clang++", + "label": "C/C++: g++ build active file", + "command": "/usr/bin/g++", "args": [ - "-fcolor-diagnostics", - "-fansi-escape-codes", + "-fdiagnostics-color=always", "-g", "${file}", + "-fopenmp", "-o", "${fileDirname}/${fileBasenameNoExtension}" ], diff --git a/docker/Makefile b/docker/Makefile index 9e47e821..ea4a346f 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -1,10 +1,11 @@ DIR_UP := $(shell cd .. && pwd) +CMD="podman" build: - docker build -t gvegayon/epiworld:latest . + ${CMD} build -t gvegayon/epiworld:latest . run: - docker run -i --rm -v $(DIR_UP):/home -w /home gvegayon/epiworld:latest + ${CMD} run -i --rm -v $(DIR_UP):/home -w /home gvegayon/epiworld:latest push: - docker push gvegayon/epiworld:latest + ${CMD} push gvegayon/epiworld:latest diff --git a/examples/06-sir-omp/Makefile b/examples/06-sir-omp/Makefile index a729c60c..20626cd2 100755 --- a/examples/06-sir-omp/Makefile +++ b/examples/06-sir-omp/Makefile @@ -1,4 +1,4 @@ -CXX=clang++ +CXX=g++ main.o: main.cpp $(CXX) -std=c++11 -Wall -pedantic -g -O2 -ftree-vectorize -fopenmp main.cpp -o main.o diff --git a/examples/06b-sir-omp/Makefile b/examples/06b-sir-omp/Makefile index 64c456bd..ae58310d 100755 --- a/examples/06b-sir-omp/Makefile +++ b/examples/06b-sir-omp/Makefile @@ -1,4 +1,4 @@ -CXX=clang++ +CXX=g++ main.o: main.cpp $(CXX) -std=c++11 -Wall -pedantic -g -O2 -ftree-vectorize -fopenmp main.cpp -o main.o README.md: main.o diff --git a/examples/06b-sir-omp/main.cpp b/examples/06b-sir-omp/main.cpp index b95532db..1d21fe7a 100644 --- a/examples/06b-sir-omp/main.cpp +++ b/examples/06b-sir-omp/main.cpp @@ -8,8 +8,8 @@ using namespace epiworld; int main(int argc, char * argv[]) { - auto nthreads = 2; - auto nsims = 10; + auto nthreads = 4; + auto nsims = 100; if (argc == 3) { nthreads = strtol(argv[1], nullptr, 0); @@ -25,7 +25,7 @@ int main(int argc, char * argv[]) { ); model.agents_from_adjlist( - rgraph_smallworld(10000, 4, .01, false, model) + rgraph_smallworld(100000, 4, .01, false, model) ); auto sav = make_save_run(std::string("%03lu-episim.txt"));