Actual source code: vecmpitoseq.c
1: #include "src/vec/vecimpl.h"
3: #undef __FUNCT__
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 ????????? */
35: /* Create seq vec on each proc, with the same size of the original mpi vec */
36: VecGetSize(vin,&N);
37: VecCreateSeq(PETSC_COMM_SELF,N,vout);
38: /* Create the VecScatter ctx with the communication info */
39: ISCreateStride(PETSC_COMM_SELF,N,0,1,&is);
40: VecScatterCreate(vin,is,*vout,is,&ctx);
41: /* Now trasfer the values into the seq vector */
42: VecScatterBegin(vin,*vout,INSERT_VALUES,SCATTER_FORWARD,ctx);
43: VecScatterEnd(vin,*vout,INSERT_VALUES,SCATTER_FORWARD,ctx);
45: ISDestroy(is);
46: VecScatterDestroy(ctx);
47: return(0);
48: }
50: #undef __FUNCT__
52: /*@C
53: VecConvertMPIToMPIZero - make available all the values of
54: an MPIVEC on processor zero as an MPIVEC
56: Collective on Vec
58: Input Parameter:
59: . vin - input MPIVEC
61: Output Parameter:
62: . vout - output MPIVEC, with values only on processor zero.
64: Level: intermediate
66: .seealso VecConvertMPIToSeqAll
67: @*/
68: int VecConvertMPIToMPIZero(Vec vin,Vec *vout)
69: {
71: int ierr,rank,N;
72: IS is;
73: VecScatter ctx;
77: /* Check if vin is of type VECMPI ????????? */
81: /* Create seq vec on each proc, with the same size of the original mpi vec */
82: VecGetSize(vin,&N);
83: MPI_Comm_rank(vin->comm,&rank);
85: if (!rank) {
86: VecCreateMPI(vin->comm,N,N,vout);
87: } else {
88: VecCreateMPI(vin->comm,0,N,vout);
89: }
91: /* Create the VecScatter ctx with the communication info */
92: ISCreateStride(PETSC_COMM_SELF,N,0,1,&is);
93: VecScatterCreate(vin,is,*vout,is,&ctx);
94: /* Now trasfer the values into the new layout */
95: VecScatterBegin(vin,*vout,INSERT_VALUES,SCATTER_FORWARD,ctx);
96: VecScatterEnd(vin,*vout,INSERT_VALUES,SCATTER_FORWARD,ctx);
97:
98: ISDestroy(is);
99: VecScatterDestroy(ctx);
100: return(0);
101: }