Global to Local Vector Mapping

Barry Smith bsmith at mcs.anl.gov
Tue Dec 4 15:39:07 CST 2007


    Tim,

     Sorry for the delay. You will need to call VecGetOwnershipRanges().

    Unfortunately it does not exist in either C or Fortran. I have put  
it into petsc-dev.
You can add the following line to include/petscvec.h
EXTERN PetscErrorCode PETSCVEC_DLLEXPORT  
VecGetOwnershipRanges(Vec,const PetscInt *[]);
add the following lines in src/vec/vec/interface/vector.c
#undef __FUNCT__
#define __FUNCT__ "VecGetOwnershipRanges"
/*@C
    VecGetOwnershipRanges - Returns the range of indices owned by EACH  
processor,
    assuming that the vectors are laid out with the
    first n1 elements on the first processor, next n2 elements on the
    second, etc.  For certain parallel layouts this range may not be
    well defined.

    Not Collective

    Input Parameter:
.  x - the vector

    Output Parameters:
.  range - array of length size+1 with the start and end+1 for each  
process

    Note:
    The high argument is one more than the last element stored locally.

    Fortran: You must PASS in an array of length size+1

    Level: beginner

    Concepts: ownership^of vectors
    Concepts: vector^ownership of elements

.seealso:   MatGetOwnershipRange(), MatGetOwnershipRanges(),  
VecGetOwnershipRange()
@*/
PetscErrorCode PETSCVEC_DLLEXPORT VecGetOwnershipRanges(Vec x,const  
PetscInt *ranges[])
{
   PetscErrorCode ierr;

   PetscFunctionBegin;
   PetscValidHeaderSpecific(x,VEC_COOKIE,1);
   PetscValidType(x,1);
   ierr = PetscMapGetGlobalRange(&x->map,ranges);CHKERRQ(ierr);
   PetscFunctionReturn(0);
}

Run make in that directory, then add to src/vec/vec/interface/ftn- 
custom/zvectorf.c
#if defined(PETSC_HAVE_FORTRAN_CAPS)
#define vecgetownershipranges_    VECGETOWNERSHIPRANGES
#elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
#define vecgetownershipranges_    vecgetownershipranges
#endif

void PETSC_STDCALL vecgetownershipranges_(Vec *x,PetscInt  
*range,PetscErrorCode *ierr)
{
   PetscMPIInt    size;
   const PetscInt *r;

   *ierr = MPI_Comm_size((*x)->map.comm,&size);if (*ierr) return;
   *ierr = VecGetOwnershipRanges(*x,&r);if (*ierr) return;
   *ierr = PetscMemcpy(range,r,(size+1)*sizeof(PetscInt));
}
and again run make in that directory.

    Let us know if any problems come up,

    Barry


On Dec 3, 2007, at 12:23 PM, Tim Stitt wrote:

> I have a problem Matthew...this is a Fortran code..which I don't  
> think this routine is compatible with. Is there any other way?
>
> Matthew Knepley wrote:
>> On Dec 3, 2007 11:49 AM, Tim Stitt <timothy.stitt at ichec.ie> wrote:
>>
>>> Hi all,
>>>
>>> Is there a quick way to map a global index for a parallel vector  
>>> to a
>>> local mapping tuple (p,i) were 'p' represents the process  
>>> containing the
>>> value and 'i' is the local index number on that process?
>>>
>>
>> PetscMapGetGlobalRange(&v->map,const &range);
>> for(p = 0; p < numProcs; ++p) if (range[p+1] > globalInd) break;
>> localInd = globalInd - range[p];
>>
>>   Matt
>>
>>
>>> As always, thanks in advance for any information provided.
>>>
>>> Tim.
>>>
>>> --
>>> Dr. Timothy Stitt <timothy_dot_stitt_at_ichec.ie>
>>> HPC Application Consultant - ICHEC (www.ichec.ie)
>>>
>>> Dublin Institute for Advanced Studies
>>> 5 Merrion Square - Dublin 2 - Ireland
>>>
>>> +353-1-6621333 (tel) / +353-1-6621477 (fax)
>>>
>>>
>>>
>>
>>
>>
>>
>
>
> -- 
> Dr. Timothy Stitt <timothy_dot_stitt_at_ichec.ie>
> HPC Application Consultant - ICHEC (www.ichec.ie)
>
> Dublin Institute for Advanced Studies
> 5 Merrion Square - Dublin 2 - Ireland
>
> +353-1-6621333 (tel) / +353-1-6621477 (fax)
>




More information about the petsc-users mailing list