<commit_before>#include <sirius.h>

double test_gemm(int M, int N, int K, std::vector<int> mpi_grid)
{
    runtime::Timer t("test_gemm"); 

    int bs = 32;
    BLACS_grid blacs_grid(mpi_comm_world(), mpi_grid[0], mpi_grid[1]);

    splindex<block> spl_K(K, mpi_comm_world().size(), mpi_comm_world().rank());
    
    matrix<double_complex> a(spl_K.local_size(), M);
    matrix<double_complex> b(spl_K.local_size(), N);

    //matrix<double_complex> c(M, N);
    dmatrix<double_complex> c(M, N, blacs_grid, bs, bs);
    c.zero();

    for (int i = 0; i < M; i++)
    {
        for (int j = 0; j < spl_K.local_size(); j++)
            a(j, i) = 0.1; //type_wrapper<double_complex>::random();
    }
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < spl_K.local_size(); j++)
            b(j, i) = 0.1; //type_wrapper<double_complex>::random();
    }

    runtime::Timer t1("gemm_only");

    mdarray<double_complex, 2> a_tmp(spl_K.local_size(), c.num_rows_local(0));
    mdarray<double_complex, 2> b_tmp(spl_K.local_size(), c.num_cols_local(0));
    mdarray<double_complex, 3> c_tmp(c.num_rows_local(0), c.num_cols_local(0), 2);

    std::array<MPI_Request, 2> req = {MPI_REQUEST_NULL, MPI_REQUEST_NULL};
    std::array<std::pair<int, int>, 2> pos;
    
    int s = 0;
    for (int rank_col = 0; rank_col < mpi_grid[1]; rank_col++)
    {
        for (int rank_row = 0; rank_row < mpi_grid[0]; rank_row++)<commit_msg>measure reduction time separately<commit_after>#include <sirius.h>

double test_gemm(int M, int N, int K, std::vector<int> mpi_grid)
{
    runtime::Timer t("test_gemm"); 

    int bs = 32;
    BLACS_grid blacs_grid(mpi_comm_world(), mpi_grid[0], mpi_grid[1]);

    splindex<block> spl_K(K, mpi_comm_world().size(), mpi_comm_world().rank());
    
    matrix<double_complex> a(spl_K.local_size(), M);
    matrix<double_complex> b(spl_K.local_size(), N);

    //matrix<double_complex> c(M, N);
    dmatrix<double_complex> c(M, N, blacs_grid, bs, bs);
    c.zero();

    for (int i = 0; i < M; i++)
    {
        for (int j = 0; j < spl_K.local_size(); j++)
            a(j, i) = 0.1; //type_wrapper<double_complex>::random();
    }
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < spl_K.local_size(); j++)
            b(j, i) = 0.1; //type_wrapper<double_complex>::random();
    }
    mdarray<double_complex, 3> c_tmp(c.num_rows_local(0), c.num_cols_local(0), 2);
    c_tmp.zero();

    runtime::Timer t2("reduce_only");
    for (int rank_col = 0; rank_col < mpi_grid[1]; rank_col++)
    {
        for (int rank_row = 0; rank_row < mpi_grid[0]; rank_row++)
        {
            mpi_comm_world().reduce(c_tmp.at<CPU>(0, 0, 0), c_tmp.ld() * c.num_cols_local(rank_col), blacs_grid.cart_rank(rank_row, rank_col));
        }
    }
    double tval2 = t2.stop();
    double perf2 = 8e-9 * M * N * K / tval2 / mpi_comm_world().size();
    if (mpi_comm_world().rank() == 0)
    {
        printf("reduction time (sec) : %12.6f\n", tval2);
        printf("absolute peak performance (GFlops / rank): %12.6f\n", perf2);
    }



    runtime::Timer t1("gemm_only");

    mdarray<double_complex, 2> a_tmp(spl_K.local_size(), c.num_rows_local(0));
    mdarray<double_complex, 2> b_tmp(spl_K.local_size(), c.num_cols_local(0));

    std::array<MPI_Request, 2> req = {MPI_REQUEST_NULL, MPI_REQUEST_NULL};
    std::array<std::pair<int, int>, 2> pos;
    
    int s = 0;
    for (int rank_col = 0; rank_col < mpi_grid[1]; rank_col++)
    {
        for (int rank_row = 0; rank_row < mpi_grid[0]; rank_row++)
{'fraction_non_alphanumeric': 0.17762039660056658, 'fraction_numerical': 0.02237960339943343, 'mean_word_length': 3.22874251497006, 'pattern_counts': {'":': 0, '<': 48, '<?xml version=': 0, '>': 34, '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': '1525997', 'n_tokens_mistral': 1482, 'n_tokens_neox': 1405, 'n_words': 286}