Actual source code: vecmpitoseq.c

  1: #include "vecimpl.h"

  5: /*@C
  6:   VecConvertMPIToSeqAll - make available all the values of
  7:   an MPIVEC on all processors as a SEQVEC

  9:   Collective

 11:   Input Parameter: 
 12: .  vin  - input MPIVEC

 14:   Output Parameter:
 15: .  vout - output SEQVEC

 17:   Level: intermediate

 19:   Notes: Each processor will have all the values
 20: .seealso VecConvertMPIToMPIZero
 21: @*/
 22: int VecConvertMPIToSeqAll(Vec vin,Vec *vout)
 23: {

 25:   int        ierr,N;
 26:   IS         is;
 27:   VecScatter ctx;


 31:   /* Check if vin is of type VECMPI ????????? */

 36:   /* Create seq vec on each proc, with the same size of the original mpi vec */
 37:   VecGetSize(vin,&N);
 38:   VecCreateSeq(PETSC_COMM_SELF,N,vout);
 39:   /* Create the VecScatter ctx with the communication info */
 40:   ISCreateStride(PETSC_COMM_SELF,N,0,1,&is);
 41:   VecScatterCreate(vin,is,*vout,is,&ctx);
 42:   /* Now trasfer the values into the seq vector */
 43:   VecScatterBegin(vin,*vout,INSERT_VALUES,SCATTER_FORWARD,ctx);
 44:   VecScatterEnd(vin,*vout,INSERT_VALUES,SCATTER_FORWARD,ctx);

 46:   ISDestroy(is);
 47:   VecScatterDestroy(ctx);
 48:   return(0);
 49: }

 53: /*@C
 54:   VecConvertMPIToMPIZero - make available all the values of
 55:   an MPIVEC on processor zero as an MPIVEC

 57:   Collective on Vec

 59:   Input Parameter: 
 60: .  vin  - input MPIVEC

 62:   Output Parameter:
 63: .  vout - output MPIVEC, with values only on processor zero.

 65:   Level: intermediate

 67: .seealso VecConvertMPIToSeqAll
 68: @*/
 69: int VecConvertMPIToMPIZero(Vec vin,Vec *vout)
 70: {

 72:   int        ierr,rank,N;
 73:   IS         is;
 74:   VecScatter ctx;


 78:   /* Check if vin is of type VECMPI ????????? */

 83:   /* Create seq vec on each proc, with the same size of the original mpi vec */
 84:   VecGetSize(vin,&N);
 85:   MPI_Comm_rank(vin->comm,&rank);

 87:   if (!rank) {
 88:     VecCreateMPI(vin->comm,N,N,vout);
 89:   } else {
 90:     VecCreateMPI(vin->comm,0,N,vout);
 91:   }

 93:   /* Create the VecScatter ctx with the communication info */
 94:   ISCreateStride(PETSC_COMM_SELF,N,0,1,&is);
 95:   VecScatterCreate(vin,is,*vout,is,&ctx);
 96:   /* Now trasfer the values into the new layout */
 97:   VecScatterBegin(vin,*vout,INSERT_VALUES,SCATTER_FORWARD,ctx);
 98:   VecScatterEnd(vin,*vout,INSERT_VALUES,SCATTER_FORWARD,ctx);
 99: 
100:   ISDestroy(is);
101:   VecScatterDestroy(ctx);
102:   return(0);
103: }