vic/drivers/shared_image/src/vic_mpi_support.c
void
gather_field_double(double  fillval,
                    double *dvar,
                    double *var)
{
    extern MPI_Comm      MPI_COMM_VIC;
    extern domain_struct global_domain;
    extern domain_struct local_domain;
    extern int           mpi_rank;
    extern int          *mpi_map_global_array_offsets;
    extern int          *mpi_map_local_array_sizes;
    extern size_t       *filter_active_cells;
    extern size_t       *mpi_map_mapping_array;
    int                  status;
    double              *dvar_gathered = NULL;
    double              *dvar_remapped = NULL;
    size_t               grid_size;
    size_t               i;

    if (mpi_rank == VIC_MPI_ROOT) {
        grid_size = global_domain.n_nx * global_domain.n_ny;
        for (i = 0; i < grid_size; i++) {
            dvar[i] = fillval;
        }
        dvar_gathered =
            malloc(global_domain.ncells_active * sizeof(*dvar_gathered));
        check_alloc_status(dvar_gathered, "Memory allocation error.");

        dvar_remapped =
            malloc(global_domain.ncells_active * sizeof(*dvar_remapped));
        check_alloc_status(dvar_remapped, "Memory allocation error.");
    }
    // Gather the results from the nodes, result for the local node is in the
    // array *var (which is a function argument)
    status = MPI_Gatherv(var, local_domain.ncells_active, MPI_DOUBLE,
                         dvar_gathered, mpi_map_local_array_sizes,
                         mpi_map_global_array_offsets, MPI_DOUBLE,
                         VIC_MPI_ROOT, MPI_COMM_VIC);
    check_mpi_status(status, "MPI error.");
    if (mpi_rank == VIC_MPI_ROOT) {
        // remap the array
        map(sizeof(double), global_domain.ncells_active, NULL,
            mpi_map_mapping_array, dvar_gathered, dvar_remapped);
        // expand to full grid size
        map(sizeof(double), global_domain.ncells_active, NULL,
            filter_active_cells, dvar_remapped, dvar);
        // cleanup
        free(dvar_gathered);
        free(dvar_remapped);
    }
}
/******************************************************************************
 * @brief   Gather double precision variable
 * @details Values are gathered to the master node
 *****************************************************************************/
@brief   Gather double precision variable
@details Values are gathered to the master node
@brief Gather double precision variable @details Values are gathered to the master node
void
gather_field_double(double  fillval,
                    double *dvar,
                    double *var)
{
    extern MPI_Comm      MPI_COMM_VIC;
    extern domain_struct global_domain;
    extern domain_struct local_domain;
    extern int           mpi_rank;
    extern int          *mpi_map_global_array_offsets;
    extern int          *mpi_map_local_array_sizes;
    extern size_t       *filter_active_cells;
    extern size_t       *mpi_map_mapping_array;
    int                  status;
    double              *dvar_gathered = NULL;
    double              *dvar_remapped = NULL;
    size_t               grid_size;
    size_t               i;
    if (mpi_rank == VIC_MPI_ROOT) {
        grid_size = global_domain.n_nx * global_domain.n_ny;
        for (i = 0; i < grid_size; i++) {
            dvar[i] = fillval;
        }
        dvar_gathered =
            malloc(global_domain.ncells_active * sizeof(*dvar_gathered));
        check_alloc_status(dvar_gathered, "Memory allocation error.");
        dvar_remapped =
            malloc(global_domain.ncells_active * sizeof(*dvar_remapped));
        check_alloc_status(dvar_remapped, "Memory allocation error.");
    }
    status = MPI_Gatherv(var, local_domain.ncells_active, MPI_DOUBLE,
                         dvar_gathered, mpi_map_local_array_sizes,
                         mpi_map_global_array_offsets, MPI_DOUBLE,
                         VIC_MPI_ROOT, MPI_COMM_VIC);
    check_mpi_status(status, "MPI error.");
    if (mpi_rank == VIC_MPI_ROOT) {
        map(sizeof(double), global_domain.ncells_active, NULL,
            mpi_map_mapping_array, dvar_gathered, dvar_remapped);
        map(sizeof(double), global_domain.ncells_active, NULL,
            filter_active_cells, dvar_remapped, dvar);
        free(dvar_gathered);
        free(dvar_remapped);
    }
}
void gather_field_double ( double fillval , double * dvar , double * var ) { extern MPI_Comm MPI_COMM_VIC ; extern domain_struct global_domain ; extern domain_struct local_domain ; extern int mpi_rank ; extern int * mpi_map_global_array_offsets ; extern int * mpi_map_local_array_sizes ; extern size_t * filter_active_cells ; extern size_t * mpi_map_mapping_array ; int status ; double * dvar_gathered = NULL ; double * dvar_remapped = NULL ; size_t grid_size ; size_t i ; if ( mpi_rank == VIC_MPI_ROOT ) { grid_size = global_domain . n_nx * global_domain . n_ny ; for ( i = 0 ; i < grid_size ; i ++ ) { dvar [ i ] = fillval ; } dvar_gathered = malloc ( global_domain . ncells_active * sizeof ( * dvar_gathered ) ) ; check_alloc_status ( dvar_gathered , " " ) ; dvar_remapped = malloc ( global_domain . ncells_active * sizeof ( * dvar_remapped ) ) ; check_alloc_status ( dvar_remapped , " " ) ; } status = MPI_Gatherv ( var , local_domain . ncells_active , MPI_DOUBLE , dvar_gathered , mpi_map_local_array_sizes , mpi_map_global_array_offsets , MPI_DOUBLE , VIC_MPI_ROOT , MPI_COMM_VIC ) ; check_mpi_status ( status , " " ) ; if ( mpi_rank == VIC_MPI_ROOT ) { map ( sizeof ( double ) , global_domain . ncells_active , NULL , mpi_map_mapping_array , dvar_gathered , dvar_remapped ) ; map ( sizeof ( double ) , global_domain . ncells_active , NULL , filter_active_cells , dvar_remapped , dvar ) ; free ( dvar_gathered ) ; free ( dvar_remapped ) ; } }
@brief   Gather double precision variable
 @details Values are gathered to the master node
@brief Gather double precision variable @details Values are gathered to the master node
// Gather the results from the nodes, result for the local node is in the // array *var (which is a function argument) // remap the array // expand to full grid size // cleanup