Actual source code: pmap.c
1: /*
2: This file contains routines for basic map object implementation.
3: */
5: #include vecimpl.h
9: PetscErrorCode PetscMapDestroy_MPI(PetscMap m)
10: {
12: return(0);
13: }
15: static struct _PetscMapOps DvOps = {
16: PETSC_NULL,
17: PetscMapDestroy_MPI,
18: };
23: PetscErrorCode PetscMapCreate_MPI(PetscMap m)
24: {
25: PetscMPIInt rank,size;
26: PetscInt p;
30: PetscMemcpy(m->ops, &DvOps, sizeof(DvOps));
32: MPI_Comm_size(m->comm, &size);
33: MPI_Comm_rank(m->comm, &rank);
34: PetscSplitOwnership(m->comm,&m->n,&m->N);
35: PetscMalloc((size+1)*sizeof(PetscInt), &m->range);
36: MPI_Allgather(&m->n, 1, MPIU_INT, m->range+1, 1, MPIU_INT, m->comm);
38: m->range[0] = 0;
39: for(p = 2; p <= size; p++) {
40: m->range[p] += m->range[p-1];
41: }
43: m->rstart = m->range[rank];
44: m->rend = m->range[rank+1];
45: return(0);
46: }
51: /*@C
52: PetscMapCreateMPI - Creates a map object.
54: Collective on MPI_Comm
55:
56: Input Parameters:
57: + comm - the MPI communicator to use
58: . n - local vector length (or PETSC_DECIDE to have calculated if N is given)
59: - N - global vector length (or PETSC_DECIDE to have calculated if n is given)
61: Output Parameter:
62: . mm - the map object
64: Suggested by:
65: Robert Clay and Alan Williams, developers of ISIS++, Sandia National Laboratories.
67: Level: developer
69: Concepts: maps^creating
71: .seealso: PetscMapDestroy(), PetscMapGetLocalSize(), PetscMapGetSize(), PetscMapGetGlobalRange(),
72: PetscMapGetLocalRange()
74: @*/
75: PetscErrorCode PetscMapCreateMPI(MPI_Comm comm,PetscInt n,PetscInt N,PetscMap *m)
76: {
80: PetscMapCreate(comm, m);
81: PetscMapSetLocalSize(*m, n);
82: PetscMapSetSize(*m, N);
83: PetscMapSetType(*m, MAP_MPI);
84: return(0);
85: }