vic/drivers/shared_image/src/vic_mpi_support.c
void
create_MPI_filenames_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;

    // nitems has to equal the number of elements in filenames_struct
    nitems = 10;
    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.");

    // most of the elements in filenames_struct are character arrays. Use
    // MAXSTRING as the default block length and reset as needed
    for (i = 0; i < (size_t) nitems; i++) {
        blocklengths[i] = MAXSTRING;
    }

    // reset i
    i = 0;

    // char forcing[2][MAXSTRING];
    offsets[i] = offsetof(filenames_struct, forcing);
    blocklengths[i] *= 2;
    mpi_types[i++] = MPI_CHAR;

    // char f_path_pfx[2][MAXSTRING];
    offsets[i] = offsetof(filenames_struct, f_path_pfx);
    blocklengths[i] *= 2;
    mpi_types[i++] = MPI_CHAR;

    // char global[MAXSTRING];
    offsets[i] = offsetof(filenames_struct, global);
    mpi_types[i++] = MPI_CHAR;

    // char domain[MAXSTRING];
    offsets[i] = offsetof(filenames_struct, domain);
    mpi_types[i++] = MPI_CHAR;

    // char constants[MAXSTRING];
    offsets[i] = offsetof(filenames_struct, constants);
    mpi_types[i++] = MPI_CHAR;

    // char init_state[MAXSTRING];
    offsets[i] = offsetof(filenames_struct, init_state);
    mpi_types[i++] = MPI_CHAR;

    // char params[MAXSTRING];
    offsets[i] = offsetof(filenames_struct, params);
    mpi_types[i++] = MPI_CHAR;

    // char result_dir[MAXSTRING];
    offsets[i] = offsetof(filenames_struct, result_dir);
    mpi_types[i++] = MPI_CHAR;

    // char statefile[MAXSTRING];
    offsets[i] = offsetof(filenames_struct, statefile);
    mpi_types[i++] = MPI_CHAR;

    // char log_path[MAXSTRING];
    offsets[i] = offsetof(filenames_struct, log_path);
    mpi_types[i++] = MPI_CHAR;


    // 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);
}
/******************************************************************************
 * @brief   Create an MPI_Datatype that represents the filenames_struct
 * @details This allows MPI operations in which the entire filenames_struct
 *          can be treated as an MPI_Datatype. NOTE: This function needs to be
 *          kept in-sync with the global_param_struct data type in vic_def.h.
 *
 * @param mpi_type MPI_Datatype that can be used in MPI operations
 *****************************************************************************/
@brief   Create an MPI_Datatype that represents the filenames_struct
@details This allows MPI operations in which the entire filenames_struct
can be treated as an MPI_Datatype. NOTE: This function needs to be
kept in-sync with the global_param_struct data type in vic_def.h.

@param mpi_type MPI_Datatype that can be used in MPI operations
@brief Create an MPI_Datatype that represents the filenames_struct @details This allows MPI operations in which the entire filenames_struct can be treated as an MPI_Datatype . NOTE : This function needs to be kept in - sync with the global_param_struct data type in vic_def . h . @param mpi_type MPI_Datatype that can be used in MPI operations
void
create_MPI_filenames_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;
    nitems = 10;
    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] = MAXSTRING;
    }
    i = 0;
    offsets[i] = offsetof(filenames_struct, forcing);
    blocklengths[i] *= 2;
    mpi_types[i++] = MPI_CHAR;
    offsets[i] = offsetof(filenames_struct, f_path_pfx);
    blocklengths[i] *= 2;
    mpi_types[i++] = MPI_CHAR;
    offsets[i] = offsetof(filenames_struct, global);
    mpi_types[i++] = MPI_CHAR;
    offsets[i] = offsetof(filenames_struct, domain);
    mpi_types[i++] = MPI_CHAR;
    offsets[i] = offsetof(filenames_struct, constants);
    mpi_types[i++] = MPI_CHAR;
    offsets[i] = offsetof(filenames_struct, init_state);
    mpi_types[i++] = MPI_CHAR;
    offsets[i] = offsetof(filenames_struct, params);
    mpi_types[i++] = MPI_CHAR;
    offsets[i] = offsetof(filenames_struct, result_dir);
    mpi_types[i++] = MPI_CHAR;
    offsets[i] = offsetof(filenames_struct, statefile);
    mpi_types[i++] = MPI_CHAR;
    offsets[i] = offsetof(filenames_struct, log_path);
    mpi_types[i++] = MPI_CHAR;
    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);
}
void create_MPI_filenames_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 ; nitems = 10 ; 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 ] = MAXSTRING ; } i = 0 ; offsets [ i ] = offsetof ( filenames_struct , forcing ) ; blocklengths [ i ] *= 2 ; mpi_types [ i ++ ] = MPI_CHAR ; offsets [ i ] = offsetof ( filenames_struct , f_path_pfx ) ; blocklengths [ i ] *= 2 ; mpi_types [ i ++ ] = MPI_CHAR ; offsets [ i ] = offsetof ( filenames_struct , global ) ; mpi_types [ i ++ ] = MPI_CHAR ; offsets [ i ] = offsetof ( filenames_struct , domain ) ; mpi_types [ i ++ ] = MPI_CHAR ; offsets [ i ] = offsetof ( filenames_struct , constants ) ; mpi_types [ i ++ ] = MPI_CHAR ; offsets [ i ] = offsetof ( filenames_struct , init_state ) ; mpi_types [ i ++ ] = MPI_CHAR ; offsets [ i ] = offsetof ( filenames_struct , params ) ; mpi_types [ i ++ ] = MPI_CHAR ; offsets [ i ] = offsetof ( filenames_struct , result_dir ) ; mpi_types [ i ++ ] = MPI_CHAR ; offsets [ i ] = offsetof ( filenames_struct , statefile ) ; mpi_types [ i ++ ] = MPI_CHAR ; offsets [ i ] = offsetof ( filenames_struct , log_path ) ; mpi_types [ i ++ ] = MPI_CHAR ; 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 ) ; }
@brief   Create an MPI_Datatype that represents the filenames_struct
 @details This allows MPI operations in which the entire filenames_struct
          can be treated as an MPI_Datatype.
@brief Create an MPI_Datatype that represents the filenames_struct @details This allows MPI operations in which the entire filenames_struct can be treated as an MPI_Datatype .
// number of elements in struct // nitems has to equal the number of elements in filenames_struct // most of the elements in filenames_struct are character arrays. Use // MAXSTRING as the default block length and reset as needed // reset i // char forcing[2][MAXSTRING]; // char f_path_pfx[2][MAXSTRING]; // char global[MAXSTRING]; // char domain[MAXSTRING]; // char constants[MAXSTRING]; // char init_state[MAXSTRING]; // char params[MAXSTRING]; // char result_dir[MAXSTRING]; // char statefile[MAXSTRING]; // char log_path[MAXSTRING]; // make sure that the we have the right number of elements // cleanup