Actual source code: vecmpitoseq.c
1: #include "src/vec/vecimpl.h"
3: /*@C
4: VecConvertMPIToSeqAll - make available all the values of
5: an MPIVEC on all processors as a SEQVEC
7: Collective
9: Input Parameter:
10: . vin - input MPIVEC
12: Output Parameter:
13: . vout - output SEQVEC
15: Level: intermediate
17: Notes: Each processor will have all the values
18: .seealso VecConvertMPIToMPIZero
19: @*/
20: int VecConvertMPIToSeqAll(Vec vin,Vec *vout)
21: {
23: int ierr,N;
24: IS is;
25: VecScatter ctx;
29: /* Check if vin is of type VECMPI ????????? */
33: /* Create seq vec on each proc, with the same size of the original mpi vec */
34: VecGetSize(vin,&N);
35: VecCreateSeq(PETSC_COMM_SELF,N,vout);
36: /* Create the VecScatter ctx with the communication info */
37: ISCreateStride(PETSC_COMM_SELF,N,0,1,&is);
38: VecScatterCreate(vin,is,*vout,is,&ctx);
39: /* Now trasfer the values into the seq vector */
40: VecScatterBegin(vin,*vout,INSERT_VALUES,SCATTER_FORWARD,ctx);
41: VecScatterEnd(vin,*vout,INSERT_VALUES,SCATTER_FORWARD,ctx);
43: ISDestroy(is);
44: VecScatterDestroy(ctx);
45: return(0);
46: }
48: /*@C
49: VecConvertMPIToMPIZero - make available all the values of
50: an MPIVEC on processor zero as an MPIVEC
52: Collective on Vec
54: Input Parameter:
55: . vin - input MPIVEC
57: Output Parameter:
58: . vout - output MPIVEC, with values only on processor zero.
60: Level: intermediate
62: .seealso VecConvertMPIToSeqAll
63: @*/
64: int VecConvertMPIToMPIZero(Vec vin,Vec *vout)
65: {
67: int ierr,rank,N;
68: IS is;
69: VecScatter ctx;
73: /* Check if vin is of type VECMPI ????????? */
77: /* Create seq vec on each proc, with the same size of the original mpi vec */
78: VecGetSize(vin,&N);
79: MPI_Comm_rank(vin->comm,&rank);
81: if (!rank) {
82: VecCreateMPI(vin->comm,N,N,vout);
83: } else {
84: VecCreateMPI(vin->comm,0,N,vout);
85: }
87: /* Create the VecScatter ctx with the communication info */
88: ISCreateStride(PETSC_COMM_SELF,N,0,1,&is);
89: VecScatterCreate(vin,is,*vout,is,&ctx);
90: /* Now trasfer the values into the new layout */
91: VecScatterBegin(vin,*vout,INSERT_VALUES,SCATTER_FORWARD,ctx);
92: VecScatterEnd(vin,*vout,INSERT_VALUES,SCATTER_FORWARD,ctx);
93:
94: ISDestroy(is);
95: VecScatterDestroy(ctx);
96: return(0);
97: }