<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <limits.h>

#include <mpi.h>

#define BIGMPI_MAX 2147483648

#define MPI_ASSERT(e)  \
        ((void) ((e) ? 0 : MPI_Abort(MPI_COMM_WORLD,1) ))

/*
 * Synopsis
 *
 * int MPIX_Type_contiguous_x(MPI_Count count,
 *                            MPI_Datatype   oldtype,
 *                            MPI_Datatype * newtype)
 *
 *  Input Parameters
 *
 *   count             replication count (nonnegative integer)
 *   oldtype           old datatype (handle)
 *
 * Output Parameter
 *
 *   newtype           new datatype (handle)
 *
 */
int MPIX_Type_contiguous_x(MPI_Count count, MPI_Datatype oldtype, MPI_Datatype * newtype)
{
    int rc = MPI_SUCCESS;

    MPI_Count c = count/BIGMPI_MAX;
    MPI_Count r = count%BIGMPI_MAX;

    MPI_Datatype chunk;
    rc = MPI_Type_contiguous(BIGMPI_MAX, oldtype, &chunk);
    MPI_ASSERT(rc==MPI_SUCCESS);

    MPI_Datatype chunks;
    rc = MPI_Type_contiguous(c, chunk, &chunks);
    MPI_ASSERT(rc==MPI_SUCCESS);

    MPI_Datatype remainder;
    rc = MPI_Type_contiguous(r, oldtype, &remainder);
    MPI_ASSERT(rc==MPI_SUCCESS);

    int typesize;
    rc = MPI_Type_size(oldtype, &typesize);

    MPI_Aint remdisp                   = (MPI_Aint)c*BIGMPI_MAX*typesize; /* must explicit-cast to avoid overflow */
    int array_of_blocklengths[2]       = {1,1};
    MPI_Aint array_of_displacements[2] = {0,remdisp};
    MPI_Datatype array_of_types[2]     = {chunks,remainder};
    rc = MPI_Type_create_struct(2, array_of_blocklengths, array_of_displacements, array_of_types, newtype);
    MPI_ASSERT(rc==MPI_SUCCESS);

    /* For MPIX_Type_contiguous_x to behave like it should, we do not commit the datatype internally. */
    /*
    rc = MPI_Type_commit(newtype);
    MPI_ASSERT(rc==MPI_SUCCESS);
    */

    rc = MPI_Type_free(&chunk);
    MPI_ASSERT(rc==MPI_SUCCESS);

    rc = MPI_Type_free(&chunks);
    MPI_ASSERT(rc==MPI_SUCCESS);

    rc = MPI_Type_free(&remainder);
    MPI_ASSERT(rc==MPI_SUCCESS);

    return MPI_SUCCESS;
}

#if 0
/*
 * Synopsis
 *
 * int MPIX_Type_contiguousv_x(int ncount,
 *                             MPI_Count counts[],
 *                             MPI_Datatype   oldtypes[],
 *                             MPI_Datatype * newtypes[])
 *
 *  Input Parameters
 *
 *   ncount            length of arrays of counts and types
 *   counts            replication count (nonnegative integer)
 *   oldtypes          old datatype (handle array)
 *
 * Output Parameter
 *
 *   newtypes           new datatype (handle array)
 *
 */
int MPIX_Type_contiguousv_x(int ncount, MPI_Count counts[], MPI_Datatype oldtypes[], MPI_Datatype * newtypes[])
{
    int rc = MPI_SUCCESS;

    TODO: Implement this function

    MPI_Count c = count/BIGMPI_MAX;
    MPI_Count r = count%BIGMPI_MAX;

    MPI_Datatype chunk;
    rc = MPI_Type_contiguous(BIGMPI_MAX, oldtype, &chunk);
    MPI_ASSERT(rc==MPI_SUCCESS);

    MPI_Datatype chunks;
    rc = MPI_Type_contiguous(c, chunk, &chunks);
    MPI_ASSERT(rc==MPI_SUCCESS);

    MPI_Datatype remainder;
    rc = MPI_Type_contiguous(r, oldtype, &remainder);
    MPI_ASSERT(rc==MPI_SUCCESS);

    int typesize;
    rc = MPI_Type_size(oldtype, &typesize);

    MPI_Aint remdisp                   = (MPI_Aint)c*BIGMPI_MAX*typesize; /* must explicit-cast to avoid overflow */
    int array_of_blocklengths[2]       = {1,1};
    MPI_Aint array_of_displacements[2] = {0,remdisp};
    MPI_Datatype array_of_types[2]     = {chunks,remainder};
    rc = MPI_Type_create_struct(2, array_of_blocklengths, array_of_displacements, array_of_types, newtype);
    MPI_ASSERT(rc==MPI_SUCCESS);

    /* For MPIX_Type_contiguous_x to behave like it should, we do not commit the datatype internally. */
    /*
    rc = MPI_Type_commit(newtype);
    MPI_ASSERT(rc==MPI_SUCCESS);
    */

    rc = MPI_Type_free(&chunk);
    MPI_ASSERT(rc==MPI_SUCCESS);

    rc = MPI_Type_free(&chunks);
    MPI_ASSERT(rc==MPI_SUCCESS);

    rc = MPI_Type_free(&remainder);<commit_msg>use BIGMPI_MAX_INT here as well<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <limits.h>

#include <mpi.h>

#ifdef BIGMPI_MAX_INT_INT
const MPI_Count bigmpi_int_max = BIGMPI_MAX_INT_INT;
#else
#include <limits.h>
const MPI_Count bigmpi_int_max = INT_MAX;
#endif

/* This function does all the heavy lifting in BigMPI. */

#define MPI_ASSERT(e)  \
        ((void) ((e) ? 0 : MPI_Abort(MPI_COMM_WORLD,1) ))

/*
 * Synopsis
 *
 * int MPIX_Type_contiguous_x(MPI_Count count,
 *                            MPI_Datatype   oldtype,
 *                            MPI_Datatype * newtype)
 *
 *  Input Parameters
 *
 *   count             replication count (nonnegative integer)
 *   oldtype           old datatype (handle)
 *
 * Output Parameter
 *
 *   newtype           new datatype (handle)
 *
 */
int MPIX_Type_contiguous_x(MPI_Count count, MPI_Datatype oldtype, MPI_Datatype * newtype)
{
    int rc = MPI_SUCCESS;

    MPI_Count c = count/BIGMPI_MAX_INT;
    MPI_Count r = count%BIGMPI_MAX_INT;

    MPI_Datatype chunk;
    rc = MPI_Type_contiguous(BIGMPI_MAX_INT, oldtype, &chunk);
    MPI_ASSERT(rc==MPI_SUCCESS);

    MPI_Datatype chunks;
    rc = MPI_Type_contiguous(c, chunk, &chunks);
    MPI_ASSERT(rc==MPI_SUCCESS);

    MPI_Datatype remainder;
    rc = MPI_Type_contiguous(r, oldtype, &remainder);
    MPI_ASSERT(rc==MPI_SUCCESS);

    int typesize;
    rc = MPI_Type_size(oldtype, &typesize);

    MPI_Aint remdisp                   = (MPI_Aint)c*BIGMPI_MAX_INT*typesize; /* must explicit-cast to avoid overflow */
    int array_of_blocklengths[2]       = {1,1};
    MPI_Aint array_of_displacements[2] = {0,remdisp};
    MPI_Datatype array_of_types[2]     = {chunks,remainder};
    rc = MPI_Type_create_struct(2, array_of_blocklengths, array_of_displacements, array_of_types, newtype);
    MPI_ASSERT(rc==MPI_SUCCESS);

    /* For MPIX_Type_contiguous_x to behave like it should, we do not commit the datatype internally. */
    /*
    rc = MPI_Type_commit(newtype);
    MPI_ASSERT(rc==MPI_SUCCESS);
    */

    rc = MPI_Type_free(&chunk);
    MPI_ASSERT(rc==MPI_SUCCESS);

    rc = MPI_Type_free(&chunks);
    MPI_ASSERT(rc==MPI_SUCCESS);

    rc = MPI_Type_free(&remainder);
    MPI_ASSERT(rc==MPI_SUCCESS);

    return MPI_SUCCESS;
}

#if 0
/*
 * Synopsis
 *
 * int MPIX_Type_contiguousv_x(int ncount,
 *                             MPI_Count counts[],
 *                             MPI_Datatype   oldtypes[],
 *                             MPI_Datatype * newtypes[])
 *
 *  Input Parameters
 *
 *   ncount            length of arrays of counts and types
 *   counts            replication count (nonnegative integer)
 *   oldtypes          old datatype (handle array)
 *
 * Output Parameter
 *
 *   newtypes           new datatype (handle array)
 *
 */
int MPIX_Type_contiguousv_x(int ncount, MPI_Count counts[], MPI_Datatype oldtypes[], MPI_Datatype * newtypes[])
{
    int rc = MPI_SUCCESS;

    TODO: Implement this function

    MPI_Count c = count/BIGMPI_MAX_INT;
    MPI_Count r = count%BIGMPI_MAX_INT;

    MPI_Datatype chunk;
    rc = MPI_Type_contiguous(BIGMPI_MAX_INT, oldtype, &chunk);
    MPI_ASSERT(rc==MPI_SUCCESS);

    MPI_Datatype chunks;
    rc = MPI_Type_contiguous(c, chunk, &chunks);
    MPI_ASSERT(rc==MPI_SUCCESS);

    MPI_Datatype remainder;
    rc = MPI_Type_contiguous(r, oldtype, &remainder);
    MPI_ASSERT(rc==MPI_SUCCESS);

    int typesize;
    rc = MPI_Type_size(oldtype, &typesize);

    MPI_Aint remdisp                   = (MPI_Aint)c*BIGMPI_MAX_INT*typesize; /* must explicit-cast to avoid overflow */
    int array_of_blocklengths[2]       = {1,1};
    MPI_Aint array_of_displacements[2] = {0,remdisp};
    MPI_Datatype array_of_types[2]     = {chunks,remainder};
    rc = MPI_Type_create_struct(2, array_of_blocklengths, array_of_displacements, array_of_types, newtype);
    MPI_ASSERT(rc==MPI_SUCCESS);

    /* For MPIX_Type_contiguous_x to behave like it should, we do not commit the datatype internally. */
    /*
    rc = MPI_Type_commit(newtype);
    MPI_ASSERT(rc==MPI_SUCCESS);
    */

    rc = MPI_Type_free(&chunk);
    MPI_ASSERT(rc==MPI_SUCCESS);

    rc = MPI_Type_free(&chunks);
    MPI_ASSERT(rc==MPI_SUCCESS);

    rc = MPI_Type_free(&remainder);
{'fraction_non_alphanumeric': 0.10449206925777939, 'fraction_numerical': 0.005327521491706018, 'mean_word_length': 3.056974459724951, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, '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': '6239324', 'n_tokens_mistral': 3136, 'n_tokens_neox': 3003, 'n_words': 571}