<commit_before>#include <stdexcept>
#include <iostream>
#include <cmath>
#include <boost/lexical_cast.hpp>
#include <boost/timer/timer.hpp>
#include "HorizontalDiffusionSA.h"
#include "Definitions.h"
#include "Options.h"
#include <mpi.h>

#include "IJKSize.h"

#ifdef __CUDA_BACKEND__
#include "cuda_profiler_api.h"
#endif

void readOptions(int argc, char** argv)
{
    Options::setCommandLineParameters(argc, argv);

    const int& rank = Options::get<int>("rank");

    if (rank == 0) {
        std::cout << "StandaloneStencilsCUDA\n\n";
        std::cout << "usage: StandaloneStencilsCUDA [--ie isize] [--je jsize] [--ke ksize] \\\n"
                  << "                              [--sync] [--nocomm] [--nocomp] \\\n"
                  << "                              [--nh nhaloupdates] [-n nrepetitions] [--inorder]\n"
                  << std::endl;
    }
    MPI_Barrier(MPI_COMM_WORLD);

    Options::parse("isize",  "--ie",       128);
    Options::parse("jsize",  "--je",       128);
    Options::parse("ksize",  "--ke",        60);

    Options::parse("sync",   "--sync",   false);
    Options::parse("nocomm", "--nocomm", false);
    Options::parse("nocomp", "--nocomp", false);

    Options::parse("nhaloupdates", "--nh",                      2);
    Options::parse("nrep",         "-n", cNumBenchmarkRepetitions);

    Options::parse("inorder", "--inorder", false);

    std::cout << "\n";
}

void setupDevice()
{
#ifdef MVAPICH2
    const char* env_p = std::getenv("SLURM_PROCID");
    if(!env_p) {
        std::cout << "SLURM_PROCID not set" << std::endl;
        exit (EXIT_FAILURE);
    }
#elif OPENMPI
    const char* env_p = std::getenv("OMPI_COMM_WORLD_RANK");
    if(!env_p) {
        std::cout << "OMPI_COMM_WORLD_RANK not set" << std::endl;
        exit (EXIT_FAILURE);
    }
#else
    const char* env_p = "0";
#endif

    int numGPU;
    cudaError_t error = cudaGetDeviceCount(&numGPU);
    if(error)  {
        std::cout << "CUDA ERROR " << std::endl;
        exit(EXIT_FAILURE);
    }

    error = cudaSetDevice(atoi(env_p)%numGPU);
    if(error)  {
        std::cout << "CUDA ERROR " << std::endl;
        exit(EXIT_FAILURE);
    }
}

void init_mpi(int argc, char** argv) {
    MPI_Init(&argc, &argv);
    int rank;
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    Options::set("rank", rank);
}

int main(int argc, char** argv)
{
    init_mpi(argc, argv);
    readOptions(argc, argv);
    setupDevice();


    IJKSize domain(Options::get<int>("isize"),
                   Options::get<int>("jsize"),
                   Options::get<int>("ksize"));
    auto repository = std::shared_ptr<Repository>(new Repository(domain));

    const int& rank = Options::get<int>("rank");
    if (Options::get<int>("rank") == 0) {<commit_msg>Add debug information on the selected device<commit_after>#include <stdexcept>
#include <iostream>
#include <cmath>
#include <boost/lexical_cast.hpp>
#include <boost/timer/timer.hpp>
#include "HorizontalDiffusionSA.h"
#include "Definitions.h"
#include "Options.h"
#include <mpi.h>

#include "IJKSize.h"

#ifdef __CUDA_BACKEND__
#include "cuda_profiler_api.h"
#endif

void readOptions(int argc, char** argv)
{
    Options::setCommandLineParameters(argc, argv);

    const int& rank = Options::get<int>("rank");

    if (rank == 0) {
        std::cout << "StandaloneStencilsCUDA\n\n";
        std::cout << "usage: StandaloneStencilsCUDA [--ie isize] [--je jsize] [--ke ksize] \\\n"
                  << "                              [--sync] [--nocomm] [--nocomp] \\\n"
                  << "                              [--nh nhaloupdates] [-n nrepetitions] [--inorder]\n"
                  << std::endl;
    }
    MPI_Barrier(MPI_COMM_WORLD);

    Options::parse("isize",  "--ie",       128);
    Options::parse("jsize",  "--je",       128);
    Options::parse("ksize",  "--ke",        60);

    Options::parse("sync",   "--sync",   false);
    Options::parse("nocomm", "--nocomm", false);
    Options::parse("nocomp", "--nocomp", false);

    Options::parse("nhaloupdates", "--nh",                      2);
    Options::parse("nrep",         "-n", cNumBenchmarkRepetitions);

    Options::parse("inorder", "--inorder", false);

    std::cout << "\n";
}

void setupDevice()
{
#ifdef MVAPICH2
    const char* env_p = std::getenv("SLURM_PROCID");
    if(!env_p) {
        std::cout << "SLURM_PROCID not set" << std::endl;
        exit (EXIT_FAILURE);
    }
#elif OPENMPI
    const char* env_p = std::getenv("OMPI_COMM_WORLD_RANK");
    if(!env_p) {
        std::cout << "OMPI_COMM_WORLD_RANK not set" << std::endl;
        exit (EXIT_FAILURE);
    }
#else
    const char* env_p = "0";
#endif

    int numGPU;
    cudaError_t error = cudaGetDeviceCount(&numGPU);
    if(error)  {
        std::cout << "CUDA ERROR: No device found " << std::endl;
        exit(EXIT_FAILURE);
    }

    error = cudaSetDevice(atoi(env_p)%numGPU);
    if(error)  {
        std::cout << "CUDA ERROR: Could not set device " << std::to_string(atoi(env_p)%numGPU)
                  << std::endl;
        exit(EXIT_FAILURE);
    }
}

void init_mpi(int argc, char** argv) {
    MPI_Init(&argc, &argv);
    int rank;
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    Options::set("rank", rank);
}

int main(int argc, char** argv)
{
    init_mpi(argc, argv);
    readOptions(argc, argv);
    setupDevice();


    IJKSize domain(Options::get<int>("isize"),
                   Options::get<int>("jsize"),
                   Options::get<int>("ksize"));
    auto repository = std::shared_ptr<Repository>(new Repository(domain));

    const int& rank = Options::get<int>("rank");
    if (Options::get<int>("rank") == 0) {
{'fraction_non_alphanumeric': 0.17990074441687345, 'fraction_numerical': 0.004608294930875576, 'mean_word_length': 2.683420365535248, 'pattern_counts': {'":': 0, '<': 87, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4957831', 'n_tokens_mistral': 2017, 'n_tokens_neox': 1987, 'n_words': 382}