Actual source code: pmap.c

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

 6:  #include private/vecimpl.h

 10: PetscErrorCode PETSCVEC_DLLEXPORT PetscMapInitialize(MPI_Comm comm,PetscMap *map)
 11: {
 12:   PetscMPIInt    rank,size;
 13:   PetscInt       p;

 17:   MPI_Comm_size(comm, &size);
 18:   MPI_Comm_rank(comm, &rank);
 19:   if (map->bs <=0) {SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"BlockSize not yet set");}
 20:   if (map->n > 0) map->n = map->n/map->bs;
 21:   if (map->N > 0) map->N = map->N/map->bs;
 22:   PetscSplitOwnership(comm,&map->n,&map->N);
 23:   map->n = map->n*map->bs;
 24:   map->N = map->N*map->bs;
 25:   if (!map->range) {
 26:     PetscMalloc((size+1)*sizeof(PetscInt), &map->range);
 27:   }
 28:   MPI_Allgather(&map->n, 1, MPIU_INT, map->range+1, 1, MPIU_INT, comm);

 30:   map->range[0] = 0;
 31:   for(p = 2; p <= size; p++) {
 32:     map->range[p] += map->range[p-1];
 33:   }

 35:   map->rstart = map->range[rank];
 36:   map->rend   = map->range[rank+1];
 37:   return(0);
 38: }

 42: PetscErrorCode PETSCVEC_DLLEXPORT PetscMapCopy(MPI_Comm comm,PetscMap *in,PetscMap *out)
 43: {
 44:   PetscMPIInt    size;
 46:   PetscInt       *range = out->range;

 49:   MPI_Comm_size(comm,&size);
 50:   PetscMemcpy(out,in,sizeof(PetscMap));
 51:   if (!range) {
 52:     PetscMalloc((size+1)*sizeof(PetscInt),&out->range);
 53:   } else {
 54:     out->range = range;
 55:   }
 56:   PetscMemcpy(out->range,in->range,(size+1)*sizeof(PetscInt));
 57:   return(0);
 58: }