Actual source code: pmap.c

  1: #define PETSCVEC_DLL
  2: /*
  3:    This file contains routines for basic map object implementation.
  4: */

 6:  #include vecimpl.h

 10: PetscErrorCode PetscMapDestroy_MPI(PetscMap m)
 11: {
 13:   return(0);
 14: }

 16: static struct _PetscMapOps DvOps = {
 17:   PETSC_NULL,
 18:   PetscMapDestroy_MPI,
 19: };

 24: PetscErrorCode PETSCVEC_DLLEXPORT PetscMapCreate_MPI(PetscMap m)
 25: {
 26:   PetscMPIInt    rank,size;
 27:   PetscInt       p;

 31:   PetscMemcpy(m->ops, &DvOps, sizeof(DvOps));

 33:   MPI_Comm_size(m->comm, &size);
 34:   MPI_Comm_rank(m->comm, &rank);
 35:   PetscSplitOwnership(m->comm,&m->n,&m->N);
 36:   PetscMalloc((size+1)*sizeof(PetscInt), &m->range);
 37:   MPI_Allgather(&m->n, 1, MPIU_INT, m->range+1, 1, MPIU_INT, m->comm);

 39:   m->range[0] = 0;
 40:   for(p = 2; p <= size; p++) {
 41:     m->range[p] += m->range[p-1];
 42:   }

 44:   m->rstart = m->range[rank];
 45:   m->rend   = m->range[rank+1];
 46:   return(0);
 47: }

 52: /*@C
 53:    PetscMapCreateMPI - Creates a map object.

 55:    Collective on MPI_Comm
 56:  
 57:    Input Parameters:
 58: +  comm - the MPI communicator to use 
 59: .  n - local vector length (or PETSC_DECIDE to have calculated if N is given)
 60: -  N - global vector length (or PETSC_DECIDE to have calculated if n is given)

 62:    Output Parameter:
 63: .  mm - the map object

 65:    Suggested by:
 66:    Robert Clay and Alan Williams, developers of ISIS++, Sandia National Laboratories.

 68:    Level: developer

 70:    Concepts: maps^creating

 72: .seealso: PetscMapDestroy(), PetscMapGetLocalSize(), PetscMapGetSize(), PetscMapGetGlobalRange(),
 73:           PetscMapGetLocalRange()

 75: @*/
 76: PetscErrorCode PETSCVEC_DLLEXPORT PetscMapCreateMPI(MPI_Comm comm,PetscInt n,PetscInt N,PetscMap *m)
 77: {

 81:   PetscMapCreate(comm, m);
 82:   PetscMapSetLocalSize(*m, n);
 83:   PetscMapSetSize(*m, N);
 84:   PetscMapSetType(*m, MAP_MPI);
 85:   return(0);
 86: }