<commit_before>#pragma once
#include "common.h"
#include "localenv.h"

namespace swift_snails {

class GlobalMPI : public VirtualObject {
public:
    const int IP_WIDTH = 64;

    GlobalMPI() {
        // get current process's id
        CHECK(0 == MPI_Comm_rank(MPI_COMM_WORLD, &_rank));
        // get number of processes
        CHECK(0 == MPI_Comm_size(MPI_COMM_WORLD, &_size));
        // allreduce ip table
        _ip_table.assign(IP_WIDTH * _size, 0);
        std::string ip = get_local_ip();
        CHECK((int)ip.length() < IP_WIDTH);
        std::strcpy(&_ip_table[IP_WIDTH * _rank], ip.c_str());
        CHECK(0 == MPI_Allgather(MPI_IN_PLACE, 0, MPI_BYTE, &_ip_table[0], IP_WIDTH, MPI_BYTE, MPI_COMM_WORLD));
    }

    ~GlobalMPI() {
        MPI_Finalize();
    }

    int rank() {
        return _rank;
    }

    int size() {
        return _size;
    }
    
    const char* ip() {
        return &_ip_table[rank() * IP_WIDTH];
    }
<commit_msg>add GlobalMPI::initialize()<commit_after>#pragma once
#include "common.h"
#include "localenv.h"

namespace swift_snails {

class GlobalMPI : public VirtualObject {
public:
    const int IP_WIDTH = 64;

    GlobalMPI() {
        // get current process's id
        CHECK(0 == MPI_Comm_rank(MPI_COMM_WORLD, &_rank));
        // get number of processes
        CHECK(0 == MPI_Comm_size(MPI_COMM_WORLD, &_size));
        // allreduce ip table
        _ip_table.assign(IP_WIDTH * _size, 0);
        std::string ip = get_local_ip();
        CHECK((int)ip.length() < IP_WIDTH);
        std::strcpy(&_ip_table[IP_WIDTH * _rank], ip.c_str());
        CHECK(0 == MPI_Allgather(MPI_IN_PLACE, 0, MPI_BYTE, &_ip_table[0], IP_WIDTH, MPI_BYTE, MPI_COMM_WORLD));
    }

    static void initialize (int argc, char** argv) {
        LOG (INFO) << "init MPI ...";
        MPI_Init(&argc, &argv);
    }

    ~GlobalMPI() {
        MPI_Finalize();
    }

    int rank() {
        return _rank;
    }

    int size() {
        return _size;
    }
    
    const char* ip() {
        return &_ip_table[rank() * IP_WIDTH];
    }

{'fraction_non_alphanumeric': 0.13601161665053244, 'fraction_numerical': 0.007744433688286544, 'mean_word_length': 2.4856661045531196, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6490029', 'n_tokens_mistral': 763, 'n_tokens_neox': 726, 'n_words': 154}