18 static VecAndScatter scatter_part(Vec v_in,
int start,
int length,
int target_rank) {
24 MPI_Comm_rank(PetscObjectComm((PetscObject)v_in), &rank);
26 if (rank != target_rank) {
30 ierr = VecCreateSeq(PETSC_COMM_SELF, length, &result.v);
33 ierr = ISCreateStride(PETSC_COMM_SELF, length, start, 1, &is);
36 ierr = VecScatterCreate(v_in, is, result.v, NULL, &result.scatter);
39 ierr = ISDestroy(&is);
50 static Vec get_natural_work(DM dm) {
54 ierr = PetscObjectQuery((PetscObject)dm,
"natural_work", (PetscObject*)&result);
59 ierr = DMDACreateNaturalVector(dm, &v);
60 PISM_CHK(ierr,
"DMDACreateNaturalVector");
62 ierr = PetscObjectCompose((PetscObject)dm,
"natural_work", (PetscObject)(v));
63 PISM_CHK(ierr,
"PetscObjectCompose");
67 ierr = VecDestroy(&v);
80 static Vec proc0_copy(DM dm,
int start,
int length) {
82 PetscErrorCode ierr = 0;
84 ierr = PetscObjectQuery((PetscObject)dm,
"v_proc0", (PetscObject*)&v_proc0);
87 if (v_proc0 == NULL) {
92 auto natural_work = get_natural_work(dm);
97 auto vs = scatter_part(natural_work, start, length, 0);
100 ierr = PetscObjectCompose((PetscObject)dm,
"scatter_to_zero",
101 (PetscObject)(vs.scatter));
102 PISM_CHK(ierr,
"PetscObjectCompose");
105 ierr = PetscObjectCompose((PetscObject)dm,
"v_proc0",
107 PISM_CHK(ierr,
"PetscObjectCompose");
109 VecScatterDestroy(&vs.scatter);
#define PISM_CHK(errcode, name)