Actual source code: pmap.c
1: /*$Id: pmap.c,v 1.21 2001/07/20 21:18:16 bsmith Exp $*/
3: /*
4: This file contains routines for basic map object implementation.
5: */
7: #include src/vec/vecimpl.h
9: #undef __FUNCT__
11: int PetscMapDestroy_MPI(PetscMap m)
12: {
14: return(0);
15: }
17: static struct _PetscMapOps DvOps = {
18: PETSC_NULL,
19: PetscMapDestroy_MPI,
20: };
22: EXTERN_C_BEGIN
23: #undef __FUNCT__
25: int PetscMapCreate_MPI(PetscMap m)
26: {
27: int rank,size;
28: int p;
32: PetscMemcpy(m->ops, &DvOps, sizeof(DvOps));
34: MPI_Comm_size(m->comm, &size);
35: MPI_Comm_rank(m->comm, &rank);
36: PetscSplitOwnership(m->comm,&m->n,&m->N);
37: PetscMalloc((size+1)*sizeof(int), &m->range);
38: MPI_Allgather(&m->n, 1, MPI_INT, m->range+1, 1, MPI_INT, m->comm);
40: m->range[0] = 0;
41: for(p = 2; p <= size; p++) {
42: m->range[p] += m->range[p-1];
43: }
45: m->rstart = m->range[rank];
46: m->rend = m->range[rank+1];
47: return(0);
48: }
49: EXTERN_C_END
51: EXTERN_C_BEGIN
52: #undef __FUNCT__
54: int PetscMapSerialize_MPI(MPI_Comm comm, PetscMap *map, PetscViewer viewer, PetscTruth store)
55: {
56: PetscMap m;
57: int fd;
58: int n, N, checkN;
59: int numProcs;
60: int ierr;
63: PetscViewerBinaryGetDescriptor(viewer, &fd);
64: if (store) {
65: m = *map;
66: MPI_Comm_size(m->comm, &numProcs);
67: PetscBinaryWrite(fd, &m->n, 1, PETSC_INT, 0);
68: PetscBinaryWrite(fd, &m->N, 1, PETSC_INT, 0);
69: PetscBinaryWrite(fd, &m->rstart, 1, PETSC_INT, 0);
70: PetscBinaryWrite(fd, &m->rend, 1, PETSC_INT, 0);
71: PetscBinaryWrite(fd, m->range, numProcs+1, PETSC_INT, 0);
72: } else {
73: PetscBinaryRead(fd, &n, 1, PETSC_INT);
74: PetscBinaryRead(fd, &N, 1, PETSC_INT);
75: MPI_Allreduce(&n, &checkN, 1, MPI_INT, MPI_SUM, comm);
76: if (checkN != N) SETERRQ(PETSC_ERR_ARG_CORRUPT, "Invalid partition");
77: PetscMapCreate(comm, &m);
78: PetscMapSetLocalSize(m, n);
79: PetscMapSetSize(m, N);
80: MPI_Comm_size(comm, &numProcs);
81: PetscMalloc((numProcs+1) * sizeof(int), &m->range);
82: PetscBinaryRead(fd, &m->rstart, 1, PETSC_INT);
83: PetscBinaryRead(fd, &m->rend, 1, PETSC_INT);
84: PetscBinaryRead(fd, m->range, numProcs+1, PETSC_INT);
86: *map = m;
87: }
89: return(0);
90: }
91: EXTERN_C_END
93: #undef __FUNCT__
95: /*@C
96: PetscMapCreateMPI - Creates a map object.
98: Collective on MPI_Comm
99:
100: Input Parameters:
101: + comm - the MPI communicator to use
102: . n - local vector length (or PETSC_DECIDE to have calculated if N is given)
103: - N - global vector length (or PETSC_DECIDE to have calculated if n is given)
105: Output Parameter:
106: . mm - the map object
108: Suggested by:
109: Robert Clay and Alan Williams, developers of ISIS++, Sandia National Laboratories.
111: Level: developer
113: Concepts: maps^creating
115: .seealso: PetscMapDestroy(), PetscMapGetLocalSize(), PetscMapGetSize(), PetscMapGetGlobalRange(),
116: PetscMapGetLocalRange()
118: @*/
119: int PetscMapCreateMPI(MPI_Comm comm,int n,int N,PetscMap *m)
120: {
124: PetscMapCreate(comm, m);
125: PetscMapSetLocalSize(*m, n);
126: PetscMapSetSize(*m, N);
127: PetscMapSetType(*m, MAP_MPI);
128: return(0);
129: }