ISAllGather withoutduplicates
Hi, Is there an easy way to gather all values of an IS across all processes in a communicator while removing duplicates? Basically, I want to go from [0] Number of indices in set 2 [0] 0 1 [0] 1 2 [1] Number of indices in set 2 [1] 0 2 [1] 1 3 to [0] Number of indices in set 3 [0] 0 1 [0] 1 2 [0] 2 3 [1] Number of indices in set 3 [1] 0 1 [1] 1 2 [1] 2 3 The way I do it right now is ierr = ISGetTotalIndices(csIS,&labels);CHKERRQ(ierr); ierr = ISGetSize(csIS,&num_cs_global);CHKERRQ(ierr); ierr = PetscMalloc(num_cs_global * sizeof(PetscInt),&labels2); for (i = 0; i < num_cs_global; i++) { labels2[i] = labels[i]; } ierr = PetscSortRemoveDupsInt(&num_cs_global,labels2);CHKERRQ(ierr); ierr = ISCreateGeneral(comm,num_cs_global,labels2,PETSC_COPY_VALUES,&csIS_global);CHKERRQ(ierr); ierr = ISRestoreTotalIndices(csIS,&labels);CHKERRQ(ierr); ierr = PetscFree(labels2);CHKERRQ(ierr); but there has to be a better way (or at least one that does not involve copying from const PetscInt *labels to PetscInt *labels2, and then uses again PETSC_COPY_VALUES). Blaise -- Department of Mathematics and Center for Computation & Technology Louisiana State University, Baton Rouge, LA 70803, USA Tel. +1 (225) 578 1612, Fax +1 (225) 578 4276 http://www.math.lsu.edu/~bourdin
On Fri, Feb 17, 2012 at 1:46 PM, Blaise Bourdin <[email protected]> wrote:
Hi,
Is there an easy way to gather all values of an IS across all processes in a communicator while removing duplicates?
Basically, I want to go from [0] Number of indices in set 2 [0] 0 1 [0] 1 2 [1] Number of indices in set 2 [1] 0 2 [1] 1 3
to [0] Number of indices in set 3 [0] 0 1 [0] 1 2 [0] 2 3 [1] Number of indices in set 3 [1] 0 1 [1] 1 2 [1] 2 3
The way I do it right now is ierr = ISGetTotalIndices(csIS,&labels);CHKERRQ(ierr); ierr = ISGetSize(csIS,&num_cs_global);CHKERRQ(ierr);
I would violate PETSc semantics here since you are going to destroy csIS anyway: PetscSortRemoveDupsInt(&num_cs_global, labels); ISCreateGeneral(comm, num_cs_global, labels, PETSC_COPY_VALUES, &csIS_global);
ierr = ISRestoreTotalIndices(csIS,&labels);CHKERRQ(ierr);
Matt
Blaise -- Department of Mathematics and Center for Computation & Technology Louisiana State University, Baton Rouge, LA 70803, USA Tel. +1 (225) 578 1612, Fax +1 (225) 578 4276 http://www.math.lsu.edu/~bourdin
-- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener
The way I do it right now is ierr = ISGetTotalIndices(csIS,&labels);CHKERRQ(ierr); ierr = ISGetSize(csIS,&num_cs_global);CHKERRQ(ierr);
I would violate PETSc semantics here since you are going to destroy csIS anyway:
PetscSortRemoveDupsInt(&num_cs_global, labels);
That's what I was thinking too, but PetscSortRemoveDupsInt expect a PetscInt* not a const PetscInt* It's not a big deal, I can live with the 2 copies, considering that the local size of the IS is going to be quite small. Blaise
ISCreateGeneral(comm, num_cs_global, labels, PETSC_COPY_VALUES, &csIS_global);
ierr = ISRestoreTotalIndices(csIS,&labels);CHKERRQ(ierr);
Matt
Blaise -- Department of Mathematics and Center for Computation & Technology Louisiana State University, Baton Rouge, LA 70803, USA Tel. +1 (225) 578 1612, Fax +1 (225) 578 4276 http://www.math.lsu.edu/~bourdin
-- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener
-- Department of Mathematics and Center for Computation & Technology Louisiana State University, Baton Rouge, LA 70803, USA Tel. +1 (225) 578 1612, Fax +1 (225) 578 4276 http://www.math.lsu.edu/~bourdin
On Fri, Feb 17, 2012 at 2:39 PM, Blaise Bourdin <[email protected]> wrote:
The way I do it right now is
ierr = ISGetTotalIndices(csIS,&labels);CHKERRQ(ierr); ierr = ISGetSize(csIS,&num_cs_global);CHKERRQ(ierr);
I would violate PETSc semantics here since you are going to destroy csIS anyway:
PetscSortRemoveDupsInt(&num_cs_global, labels);
PetscSortRemoveDupsInt(&num_cs_global, (PetscInt *) labels);
Matt
That's what I was thinking too, but PetscSortRemoveDupsInt expect a PetscInt* not a const PetscInt*
It's not a big deal, I can live with the 2 copies, considering that the local size of the IS is going to be quite small.
Blaise
ISCreateGeneral(comm, num_cs_global, labels, PETSC_COPY_VALUES, &csIS_global);
ierr = ISRestoreTotalIndices(csIS,&labels);CHKERRQ(ierr);
Matt
Blaise -- Department of Mathematics and Center for Computation & Technology Louisiana State University, Baton Rouge, LA 70803, USA Tel. +1 (225) 578 1612, Fax +1 (225) 578 4276 http://www.math.lsu.edu/~bourdin
-- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener
-- Department of Mathematics and Center for Computation & Technology Louisiana State University, Baton Rouge, LA 70803, USA Tel. +1 (225) 578 1612, Fax +1 (225) 578 4276 http://www.math.lsu.edu/~bourdin
-- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener
On Feb 17, 2012, at 2:45 PM, Matthew Knepley wrote:
On Fri, Feb 17, 2012 at 2:39 PM, Blaise Bourdin <[email protected]> wrote:
The way I do it right now is ierr = ISGetTotalIndices(csIS,&labels);CHKERRQ(ierr); ierr = ISGetSize(csIS,&num_cs_global);CHKERRQ(ierr);
I would violate PETSc semantics here since you are going to destroy csIS anyway:
PetscSortRemoveDupsInt(&num_cs_global, labels);
PetscSortRemoveDupsInt(&num_cs_global, (PetscInt *) labels);
Facepalm... Blaise
Matt
That's what I was thinking too, but PetscSortRemoveDupsInt expect a PetscInt* not a const PetscInt*
It's not a big deal, I can live with the 2 copies, considering that the local size of the IS is going to be quite small.
Blaise
ISCreateGeneral(comm, num_cs_global, labels, PETSC_COPY_VALUES, &csIS_global);
ierr = ISRestoreTotalIndices(csIS,&labels);CHKERRQ(ierr);
Matt
Blaise -- Department of Mathematics and Center for Computation & Technology Louisiana State University, Baton Rouge, LA 70803, USA Tel. +1 (225) 578 1612, Fax +1 (225) 578 4276 http://www.math.lsu.edu/~bourdin
-- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener
-- Department of Mathematics and Center for Computation & Technology Louisiana State University, Baton Rouge, LA 70803, USA Tel. +1 (225) 578 1612, Fax +1 (225) 578 4276 http://www.math.lsu.edu/~bourdin
-- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener
-- Department of Mathematics and Center for Computation & Technology Louisiana State University, Baton Rouge, LA 70803, USA Tel. +1 (225) 578 1612, Fax +1 (225) 578 4276 http://www.math.lsu.edu/~bourdin
participants (2)
-
Blaise Bourdin -
Matthew Knepley