Skip to content
Snippets Groups Projects
Verified Commit a5d28b19 authored by Jayesh Badwaik's avatar Jayesh Badwaik
Browse files

+ initial commit

parents
No related branches found
No related tags found
No related merge requests found
# --------------------------------------------------------------------------------------------------
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2024 Jayesh Badwaik <j.badwaik@fz-juelich.de>
# --------------------------------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.25)
project(scaler LANGUAGES CXX C)
include(GNUInstallDirs)
list(APPEND CMAKE_PREFIX_PATH "${PROJECT_SOURCE_DIR}/cmake")
find_package(quickmpi REQUIRED)
add_executable(scaler scaler.cpp)
target_link_libraries(scaler PRIVATE quickmpi::mpi)
install(TARGETS scaler DESTINATION ${CMAKE_INSTALL_BINDIR})
// -------------------------------------------------------------------------------------------------
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2024 Jayesh Badwaik <j.badwaik@fz-juelich.de>
// -------------------------------------------------------------------------------------------------
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void print_vendor_information()
{
#if defined(OPEN_MPI)
printf("openmpi\n");
#elif defined(MPICH)
printf("mpich\n");
#else
printf("unknown\n");
#endif
}
void print_version_information() { printf("%d\n", MPI_VERSION); }
void print_subversion_information() { printf("%d\n", MPI_SUBVERSION); }
void print_help()
{
printf("Incorrect Usage of probe.\n\n");
printf("Expected Usage: probe [--vendor|--version]\n");
}
int main(int argc, char** argv)
{
if (argc != 2) {
print_help();
return EXIT_FAILURE;
}
char const* operation_name_vendor = "--vendor";
char const* operation_name_version = "--version";
char const* operation_name_subversion = "--subversion";
if (strcmp(argv[1], operation_name_vendor) == 0) {
print_vendor_information();
} else if (strcmp(argv[1], operation_name_version) == 0) {
print_version_information();
} else if (strcmp(argv[1], operation_name_subversion) == 0) {
print_subversion_information();
} else {
print_help();
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
# --------------------------------------------------------------------------------------------------
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2024 Jayesh Badwaik <j.badwaik@fz-juelich.de>
# --------------------------------------------------------------------------------------------------
include(CMakePushCheckState)
cmake_push_check_state()
add_library(quickmpi::mpi INTERFACE IMPORTED)
find_program(QMPICC mpicc REQUIRED DOC "mpicc")
find_program(QMPICXX mpicxx REQUIRED DOC "mpicxx")
execute_process(
COMMAND
${QMPICC} ${CMAKE_CURRENT_LIST_DIR}/mpi/probe.c -o ${CMAKE_CURRENT_BINARY_DIR}/mpi_prober
COMMAND_ERROR_IS_FATAL ANY
)
set(QMPI_PROBE ${CMAKE_CURRENT_BINARY_DIR}/mpi_prober)
execute_process(
COMMAND ${QMPI_PROBE} --vendor
OUTPUT_VARIABLE MPI_VENDOR
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ERROR_IS_FATAL ANY)
execute_process(
COMMAND ${QMPI_PROBE} --version
OUTPUT_VARIABLE MPI_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ERROR_IS_FATAL ANY)
execute_process(
COMMAND ${QMPI_PROBE} --subversion
OUTPUT_VARIABLE MPI_SUBVERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ERROR_IS_FATAL ANY)
if(MPI_VENDOR STREQUAL "openmpi")
set(COMPILE_FLAG_PROBE "--showme:compile")
set(LINK_FLAG_PROBE "--showme:link")
elseif(MPI_VENDOR STREQUAL "mpich")
if(${MPI_VERSION} LESS 4)
set(COMPILE_FLAG_PROBE "-compile-info")
set(LINK_FLAG_PROBE "-link-info")
else()
set(COMPILE_FLAG_PROBE "-show-compile-info")
set(LINK_FLAG_PROBE "-show-link-info")
endif()
endif()
execute_process(
COMMAND ${QMPICC} ${COMPILE_FLAG_PROBE}
OUTPUT_VARIABLE MPI_COMPILE_FLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ERROR_IS_FATAL ANY)
separate_arguments(MPI_COMPILE_FLAGS UNIX_COMMAND "${MPI_COMPILE_FLAGS}")
execute_process(
COMMAND ${QMPICC} ${LINK_FLAG_PROBE}
OUTPUT_VARIABLE MPI_LINK_FLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ERROR_IS_FATAL ANY)
message(DEBUG "MPI Compile Flags: ${MPI_COMPILE_FLAGS}")
message(DEBUG "MPI Link Flags: ${MPI_LINK_FLAGS}")
string(REPLACE "-Wl,-rpath -Wl" "-Wl,-rpath" MPI_LINK_FLAGS ${MPI_LINK_FLAGS})
separate_arguments(MPI_LINK_FLAGS UNIX_COMMAND "${MPI_LINK_FLAGS}")
target_compile_options(quickmpi::mpi INTERFACE $<$<COMPILE_LANGUAGE:C>:${MPI_COMPILE_FLAGS}>)
target_link_options(quickmpi::mpi INTERFACE ${MPI_LINK_FLAGS})
execute_process(
COMMAND ${QMPICXX} ${COMPILE_FLAG_PROBE}
OUTPUT_VARIABLE MPI_COMPILE_FLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ERROR_IS_FATAL ANY)
separate_arguments(MPI_COMPILE_FLAGS UNIX_COMMAND "${MPI_COMPILE_FLAGS}")
execute_process(
COMMAND ${QMPICXX} ${LINK_FLAG_PROBE}
OUTPUT_VARIABLE MPI_LINK_FLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ERROR_IS_FATAL ANY)
string(REPLACE "-Wl,-rpath -Wl" "-Wl,-rpath" MPI_LINK_FLAGS ${MPI_LINK_FLAGS})
separate_arguments(MPI_LINK_FLAGS UNIX_COMMAND "${MPI_LINK_FLAGS}")
message(DEBUG "MPI Compile Flags: ${MPI_COMPILE_FLAGS}")
message(DEBUG "MPI Link Flags: ${MPI_LINK_FLAGS}")
target_compile_options(quickmpi::mpi INTERFACE $<$<COMPILE_LANGUAGE:CXX>:${MPI_COMPILE_FLAGS}>)
target_link_options(quickmpi::mpi INTERFACE ${MPI_LINK_FLAGS})
cmake_pop_check_state()
<!--
- SPDX-License-Identifier: CC-BY-4.0
- Copyright (C) 2024 Jayesh Badwaik <j.badwaik@fz-juelich.de>
-->
# scaler
`scaler` is a synthetic placeholder program that always runs for approximately 10 seconds but
reports a fictional runtime given by the formula below. Various behaviors of benchmarks, which are
relevant to the purposes of reporting, can be simulated by changing the parameters of the formula.
We arbitrarily fix the weak scaling efficency of the benchmark to be $k^{\log_2(n)}$.
```python
runtime = random(0.95,1.05) * m * g * c * v * p * pow(k,log(n,2))
# n : number of MPI ranks
# p : problem size
# k : scaling factor
# m : mpi factor (1.2 for OpenMPI, 1.4 for MPICH/PSMPI)
# g : cuda factor (1.2 for no GPU, 1.4 for GPU)
# c : compiler factor (1.2 for GCC, 1.4 for LLVM, 1.6 for NVHPC)
# v : version factor (random number between 0.8 and 1.2 for different versions)
```
## Usage
1. Ensure that the following dependencies are installed on your system.
a. CMake (>= 3.25)
b. C++ compiler (>= C++17)
c. MPI library (OpenMPI or MPICH)
2. Clone the repository and build the program.
```bash
git clone https://gitlab.jsc.fz-juelich.de/exacb/examples/scaler.git
mkdir build
cmake -B build -S scaler
cmake --build build
```
3. Run the program with the following command.
```bash
srun [--options] build/scaler --size <problem-size>
```
// -------------------------------------------------------------------------------------------------
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2024 Jayesh Badwaik <j.badwaik@fz-juelich.de>
// -------------------------------------------------------------------------------------------------
#include <algorithm>
#include <array>
#include <cmath>
#include <fstream>
#include <iostream>
#include <mpi.h>
#include <random>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <thread>
#if defined(OPEN_MPI)
inline constexpr double mpi_factor = 1.0;
#elif defined(MPICH)
inline constexpr double mpi_factor = 2.0;
#endif
#if defined(__CUDACC__)
inline constexpr double gpu_factor = 2;
#else
inline constexpr double gpu_factor = 1.0;
#endif
#if defined(__clang__)
inline constexpr double compiler_factor = 1.0;
#elif defined(__NVCOMPILER)
inline constexpr double compiler_factor = 2;
#else
inline constexpr double compiler_factor = 4;
#endif
void print_help()
{
printf("Incorrect Usage of scaler\n\n");
printf("Expected Usage: scaler --size <problem_size>\n");
}
int main(int argc, char** argv)
{
MPI_Init(nullptr, nullptr);
int size = 0;
int rank = 0;
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0) {
std::cout << "scaler : starting execution..." << std::endl;
auto cmdline = std::vector<std::string>(argv, argv + argc);
if (argc != 3) {
print_help();
return EXIT_FAILURE;
}
char const* operation_name_size = "--size";
double problem_size = 10'000;
double scaling = 0.9;
if (strcmp(argv[1], operation_name_size) == 0) {
problem_size = atof(argv[2]);
} else {
print_help();
return EXIT_FAILURE;
}
std::this_thread::sleep_for(std::chrono::milliseconds(10000));
double runtime = 0;
std::array<int, 624> seed_data;
std::random_device r;
std::generate_n(seed_data.data(), seed_data.size(), std::ref(r));
std::seed_seq seq(std::begin(seed_data), std::end(seed_data));
std::mt19937 eng(seq);
std::uniform_real_distribution<double> dist(0.8, 1.2);
double scaled_performance = dist(eng) * compiler_factor * mpi_factor * gpu_factor * size
* std::pow(scaling, std::log(size) / std::log(2));
runtime = problem_size / scaled_performance;
std::ofstream file("runtime");
file << runtime << std::endl;
std::cout << "Runtime: " << runtime << std::endl;
}
std::this_thread::sleep_for(std::chrono::milliseconds(10000));
if (rank == 0) {
std::ofstream file("success");
file << "true" << std::endl;
std::cout << "scaler : finished execution..." << std::endl;
}
MPI_Finalize();
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment