vic/drivers/shared_image/src/vic_mpi_support.c
void
gather_put_nc_field_double(int     nc_id,
                           int     var_id,
                           double  fillval,
                           size_t *start,
                           size_t *count,
                           double *var)
{
    extern int           mpi_rank;
    extern domain_struct global_domain;
    int                  status;
    size_t               grid_size;
    double              *dvar = NULL;

    // Allocate memory
    if (mpi_rank == VIC_MPI_ROOT) {
        grid_size = global_domain.n_nx * global_domain.n_ny;
        dvar = malloc(grid_size * sizeof(*dvar));
        check_alloc_status(dvar, "Memory allocation error.");
    }

    // Gather results from the nodes
    gather_field_double(fillval, dvar, var);

    // Write to netcdf
    if (mpi_rank == VIC_MPI_ROOT) {
        status = nc_put_vara_double(nc_id, var_id, start, count, dvar);
        check_nc_status(status, "Error writing values.");
        // cleanup
        free(dvar);
    }
}
/******************************************************************************
 * @brief   Gather and write double precision NetCDF field
 * @details Values are gathered to the master node and then written from the
 *          master node
 *****************************************************************************/
@brief   Gather and write double precision NetCDF field
@details Values are gathered to the master node and then written from the
master node
@brief Gather and write double precision NetCDF field @details Values are gathered to the master node and then written from the master node
void
gather_put_nc_field_double(int     nc_id,
                           int     var_id,
                           double  fillval,
                           size_t *start,
                           size_t *count,
                           double *var)
{
    extern int           mpi_rank;
    extern domain_struct global_domain;
    int                  status;
    size_t               grid_size;
    double              *dvar = NULL;
    if (mpi_rank == VIC_MPI_ROOT) {
        grid_size = global_domain.n_nx * global_domain.n_ny;
        dvar = malloc(grid_size * sizeof(*dvar));
        check_alloc_status(dvar, "Memory allocation error.");
    }
    gather_field_double(fillval, dvar, var);
    if (mpi_rank == VIC_MPI_ROOT) {
        status = nc_put_vara_double(nc_id, var_id, start, count, dvar);
        check_nc_status(status, "Error writing values.");
        free(dvar);
    }
}
void gather_put_nc_field_double ( int nc_id , int var_id , double fillval , size_t * start , size_t * count , double * var ) { extern int mpi_rank ; extern domain_struct global_domain ; int status ; size_t grid_size ; double * dvar = NULL ; if ( mpi_rank == VIC_MPI_ROOT ) { grid_size = global_domain . n_nx * global_domain . n_ny ; dvar = malloc ( grid_size * sizeof ( * dvar ) ) ; check_alloc_status ( dvar , " " ) ; } gather_field_double ( fillval , dvar , var ) ; if ( mpi_rank == VIC_MPI_ROOT ) { status = nc_put_vara_double ( nc_id , var_id , start , count , dvar ) ; check_nc_status ( status , " " ) ; free ( dvar ) ; } }
@brief   Gather and write double precision NetCDF field
 @details Values are gathered to the master node and then written from the
          master node
@brief Gather and write double precision NetCDF field @details Values are gathered to the master node and then written from the master node
// Allocate memory // Gather results from the nodes // Write to netcdf // cleanup