vic/drivers/shared_image/src/vic_mpi_support.c
void
scatter_field_double(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_filtered = NULL;
    double              *dvar_mapped = NULL;

    if (mpi_rank == VIC_MPI_ROOT) {
        dvar_filtered =
            malloc(global_domain.ncells_active * sizeof(*dvar_filtered));
        check_alloc_status(dvar_filtered, "Memory allocation error.");

        dvar_mapped =
            malloc(global_domain.ncells_active * sizeof(*dvar_mapped));
        check_alloc_status(dvar_mapped, "Memory allocation error.");

        // filter the active cells only
        map(sizeof(double), global_domain.ncells_active, filter_active_cells,
            NULL, dvar, dvar_filtered);
        // map to prepare for MPI_Scatterv
        map(sizeof(double), global_domain.ncells_active, mpi_map_mapping_array,
            NULL, dvar_filtered, dvar_mapped);
        free(dvar);
        free(dvar_filtered);
    }

    // Scatter the results to the nodes, result for the local node is in the
    // array *var (which is a function argument)
    status = MPI_Scatterv(dvar_mapped, mpi_map_local_array_sizes,
                          mpi_map_global_array_offsets, MPI_DOUBLE,
                          var, local_domain.ncells_active, MPI_DOUBLE,
                          VIC_MPI_ROOT, MPI_COMM_VIC);
    check_mpi_status(status, "MPI error.");

    if (mpi_rank == VIC_MPI_ROOT) {
        free(dvar_mapped);
    }
}
/******************************************************************************
 * @brief   Scatter double precision variable
 * @details values from master node are scattered to the local nodes
 *****************************************************************************/
@brief   Scatter double precision variable
@details values from master node are scattered to the local nodes
@brief Scatter double precision variable @details values from master node are scattered to the local nodes
void
scatter_field_double(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_filtered = NULL;
    double              *dvar_mapped = NULL;
    if (mpi_rank == VIC_MPI_ROOT) {
        dvar_filtered =
            malloc(global_domain.ncells_active * sizeof(*dvar_filtered));
        check_alloc_status(dvar_filtered, "Memory allocation error.");
        dvar_mapped =
            malloc(global_domain.ncells_active * sizeof(*dvar_mapped));
        check_alloc_status(dvar_mapped, "Memory allocation error.");
        map(sizeof(double), global_domain.ncells_active, filter_active_cells,
            NULL, dvar, dvar_filtered);
        map(sizeof(double), global_domain.ncells_active, mpi_map_mapping_array,
            NULL, dvar_filtered, dvar_mapped);
        free(dvar);
        free(dvar_filtered);
    }
    status = MPI_Scatterv(dvar_mapped, mpi_map_local_array_sizes,
                          mpi_map_global_array_offsets, MPI_DOUBLE,
                          var, local_domain.ncells_active, MPI_DOUBLE,
                          VIC_MPI_ROOT, MPI_COMM_VIC);
    check_mpi_status(status, "MPI error.");
    if (mpi_rank == VIC_MPI_ROOT) {
        free(dvar_mapped);
    }
}
void scatter_field_double ( 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_filtered = NULL ; double * dvar_mapped = NULL ; if ( mpi_rank == VIC_MPI_ROOT ) { dvar_filtered = malloc ( global_domain . ncells_active * sizeof ( * dvar_filtered ) ) ; check_alloc_status ( dvar_filtered , " " ) ; dvar_mapped = malloc ( global_domain . ncells_active * sizeof ( * dvar_mapped ) ) ; check_alloc_status ( dvar_mapped , " " ) ; map ( sizeof ( double ) , global_domain . ncells_active , filter_active_cells , NULL , dvar , dvar_filtered ) ; map ( sizeof ( double ) , global_domain . ncells_active , mpi_map_mapping_array , NULL , dvar_filtered , dvar_mapped ) ; free ( dvar ) ; free ( dvar_filtered ) ; } status = MPI_Scatterv ( dvar_mapped , mpi_map_local_array_sizes , mpi_map_global_array_offsets , MPI_DOUBLE , var , local_domain . ncells_active , MPI_DOUBLE , VIC_MPI_ROOT , MPI_COMM_VIC ) ; check_mpi_status ( status , " " ) ; if ( mpi_rank == VIC_MPI_ROOT ) { free ( dvar_mapped ) ; } }
@brief   Scatter double precision variable
 @details values from master node are scattered to the local nodes
@brief Scatter double precision variable @details values from master node are scattered to the local nodes
// filter the active cells only // map to prepare for MPI_Scatterv // Scatter the results to the nodes, result for the local node is in the // array *var (which is a function argument)