vic/drivers/shared_image/src/vic_mpi_support.c
void
create_MPI_alarm_struct_type(MPI_Datatype *mpi_type)
{
    extern MPI_Comm MPI_COMM_VIC;

    int             nitems; // number of elements in struct
    int             status;
    int            *blocklengths;
    size_t          i;
    MPI_Aint       *offsets;
    MPI_Datatype   *mpi_types;
    MPI_Datatype    mpi_dmy_type;

    // nitems has to equal the number of elements in alarm_struct
    nitems = 6;
    blocklengths = malloc(nitems * sizeof(*blocklengths));
    check_alloc_status(blocklengths, "Memory allocation error.");

    offsets = malloc(nitems * sizeof(*offsets));
    check_alloc_status(offsets, "Memory allocation error.");

    mpi_types = malloc(nitems * sizeof(*mpi_types));
    check_alloc_status(mpi_types, "Memory allocation error.");

    // none of the elements in location_struct are arrays.
    for (i = 0; i < (size_t) nitems; i++) {
        blocklengths[i] = 1;
    }

    // reset i
    i = 0;

    // unsigned int count;
    offsets[i] = offsetof(alarm_struct, count);
    mpi_types[i++] = MPI_UNSIGNED;

    // int next_count;
    offsets[i] = offsetof(alarm_struct, next_count);
    mpi_types[i++] = MPI_INT;

    // dmy_struct next_dmy;
    offsets[i] = offsetof(alarm_struct, next_dmy);
    create_MPI_dmy_struct_type(&mpi_dmy_type);
    mpi_types[i++] = mpi_dmy_type;

    // unsigned int freq;
    offsets[i] = offsetof(alarm_struct, freq);
    mpi_types[i++] = MPI_UNSIGNED;

    // int n;
    offsets[i] = offsetof(alarm_struct, n);
    mpi_types[i++] = MPI_INT;

    // bool is_subdaily;
    offsets[i] = offsetof(alarm_struct, is_subdaily);
    mpi_types[i++] = MPI_C_BOOL;

    // make sure that the we have the right number of elements
    if (i != (size_t) nitems) {
        log_err("Miscount: %zd not equal to %d.", i, nitems);
    }

    status = MPI_Type_create_struct(nitems, blocklengths, offsets, mpi_types,
                                    mpi_type);
    check_mpi_status(status, "MPI error.");

    status = MPI_Type_commit(mpi_type);
    check_mpi_status(status, "MPI error.");

    // cleanup
    free(blocklengths);
    free(offsets);
    free(mpi_types);
    MPI_Type_free(&mpi_dmy_type);
}
/******************************************************************************
 * @brief   Create an MPI_Datatype that represents the alarm_struct
 * @details This allows MPI operations in which the entire alarm_struct
 *          can be treated as an MPI_Datatype.
 * @param mpi_type MPI_Datatype that can be used in MPI operations
 *****************************************************************************/
@brief   Create an MPI_Datatype that represents the alarm_struct
@details This allows MPI operations in which the entire alarm_struct
can be treated as an MPI_Datatype.
@param mpi_type MPI_Datatype that can be used in MPI operations
@brief Create an MPI_Datatype that represents the alarm_struct @details This allows MPI operations in which the entire alarm_struct can be treated as an MPI_Datatype . @param mpi_type MPI_Datatype that can be used in MPI operations
void
create_MPI_alarm_struct_type(MPI_Datatype *mpi_type)
{
    extern MPI_Comm MPI_COMM_VIC;
    int             nitems; 
    int             status;
    int            *blocklengths;
    size_t          i;
    MPI_Aint       *offsets;
    MPI_Datatype   *mpi_types;
    MPI_Datatype    mpi_dmy_type;
    nitems = 6;
    blocklengths = malloc(nitems * sizeof(*blocklengths));
    check_alloc_status(blocklengths, "Memory allocation error.");
    offsets = malloc(nitems * sizeof(*offsets));
    check_alloc_status(offsets, "Memory allocation error.");
    mpi_types = malloc(nitems * sizeof(*mpi_types));
    check_alloc_status(mpi_types, "Memory allocation error.");
    for (i = 0; i < (size_t) nitems; i++) {
        blocklengths[i] = 1;
    }
    i = 0;
    offsets[i] = offsetof(alarm_struct, count);
    mpi_types[i++] = MPI_UNSIGNED;
    offsets[i] = offsetof(alarm_struct, next_count);
    mpi_types[i++] = MPI_INT;
    offsets[i] = offsetof(alarm_struct, next_dmy);
    create_MPI_dmy_struct_type(&mpi_dmy_type);
    mpi_types[i++] = mpi_dmy_type;
    offsets[i] = offsetof(alarm_struct, freq);
    mpi_types[i++] = MPI_UNSIGNED;
    offsets[i] = offsetof(alarm_struct, n);
    mpi_types[i++] = MPI_INT;
    offsets[i] = offsetof(alarm_struct, is_subdaily);
    mpi_types[i++] = MPI_C_BOOL;
    if (i != (size_t) nitems) {
        log_err("Miscount: %zd not equal to %d.", i, nitems);
    }
    status = MPI_Type_create_struct(nitems, blocklengths, offsets, mpi_types,
                                    mpi_type);
    check_mpi_status(status, "MPI error.");
    status = MPI_Type_commit(mpi_type);
    check_mpi_status(status, "MPI error.");
    free(blocklengths);
    free(offsets);
    free(mpi_types);
    MPI_Type_free(&mpi_dmy_type);
}
void create_MPI_alarm_struct_type ( MPI_Datatype * mpi_type ) { extern MPI_Comm MPI_COMM_VIC ; int nitems ; int status ; int * blocklengths ; size_t i ; MPI_Aint * offsets ; MPI_Datatype * mpi_types ; MPI_Datatype mpi_dmy_type ; nitems = 6 ; blocklengths = malloc ( nitems * sizeof ( * blocklengths ) ) ; check_alloc_status ( blocklengths , " " ) ; offsets = malloc ( nitems * sizeof ( * offsets ) ) ; check_alloc_status ( offsets , " " ) ; mpi_types = malloc ( nitems * sizeof ( * mpi_types ) ) ; check_alloc_status ( mpi_types , " " ) ; for ( i = 0 ; i < ( size_t ) nitems ; i ++ ) { blocklengths [ i ] = 1 ; } i = 0 ; offsets [ i ] = offsetof ( alarm_struct , count ) ; mpi_types [ i ++ ] = MPI_UNSIGNED ; offsets [ i ] = offsetof ( alarm_struct , next_count ) ; mpi_types [ i ++ ] = MPI_INT ; offsets [ i ] = offsetof ( alarm_struct , next_dmy ) ; create_MPI_dmy_struct_type ( & mpi_dmy_type ) ; mpi_types [ i ++ ] = mpi_dmy_type ; offsets [ i ] = offsetof ( alarm_struct , freq ) ; mpi_types [ i ++ ] = MPI_UNSIGNED ; offsets [ i ] = offsetof ( alarm_struct , n ) ; mpi_types [ i ++ ] = MPI_INT ; offsets [ i ] = offsetof ( alarm_struct , is_subdaily ) ; mpi_types [ i ++ ] = MPI_C_BOOL ; if ( i != ( size_t ) nitems ) { log_err ( " " , i , nitems ) ; } status = MPI_Type_create_struct ( nitems , blocklengths , offsets , mpi_types , mpi_type ) ; check_mpi_status ( status , " " ) ; status = MPI_Type_commit ( mpi_type ) ; check_mpi_status ( status , " " ) ; free ( blocklengths ) ; free ( offsets ) ; free ( mpi_types ) ; MPI_Type_free ( & mpi_dmy_type ) ; }
@brief   Create an MPI_Datatype that represents the alarm_struct
 @details This allows MPI operations in which the entire alarm_struct
          can be treated as an MPI_Datatype.
@brief Create an MPI_Datatype that represents the alarm_struct @details This allows MPI operations in which the entire alarm_struct can be treated as an MPI_Datatype .
// number of elements in struct // nitems has to equal the number of elements in alarm_struct // none of the elements in location_struct are arrays. // reset i // unsigned int count; // int next_count; // dmy_struct next_dmy; // unsigned int freq; // int n; // bool is_subdaily; // make sure that the we have the right number of elements // cleanup