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 vecimpl.h
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
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
53: /*@C
54: PetscMapCreateMPI - Creates a map object.
56: Collective on MPI_Comm
57:
58: Input Parameters:
59: + comm - the MPI communicator to use
60: . n - local vector length (or PETSC_DECIDE to have calculated if N is given)
61: - N - global vector length (or PETSC_DECIDE to have calculated if n is given)
63: Output Parameter:
64: . mm - the map object
66: Suggested by:
67: Robert Clay and Alan Williams, developers of ISIS++, Sandia National Laboratories.
69: Level: developer
71: Concepts: maps^creating
73: .seealso: PetscMapDestroy(), PetscMapGetLocalSize(), PetscMapGetSize(), PetscMapGetGlobalRange(),
74: PetscMapGetLocalRange()
76: @*/
77: int PetscMapCreateMPI(MPI_Comm comm,int n,int N,PetscMap *m)
78: {
82: PetscMapCreate(comm, m);
83: PetscMapSetLocalSize(*m, n);
84: PetscMapSetSize(*m, N);
85: PetscMapSetType(*m, MAP_MPI);
86: return(0);
87: }