# Question on Index Sets and VecScatters

Randall Mackie randy at geosystem.us
Thu Dec 13 18:16:31 CST 2007

```Hi Matt,

Yes, I see what you're saying, and it makes sense. I'll give it
a try.

Randy

Matthew Knepley wrote:
> You could do it like that, but it seems pretty wasteful, especially in parallel
> where you might be sending a considerable amount of data. Why not do
> something like this:
>
>   1) Average all slabs into a local vector, indexed by the given k value,
>       meaning you have a map {k_0, k_1, ..., k_m} --> {0,1, ...,m}.
>
>   2) Now construct a scatter that maps each local vector into a parallel
>        vector of all the ks. The IndexSet for the from (local) vector will be
>        {0, 1, ..., m} and the IndexSet for the to (global) vector will be
>        {k_0, k_1, ... , k_m} on each process.
>
>   3) When you scatter use ADD_VALUES. Then you will have the sum, and
>       just scale the vector by the slab size.
>
> Does this makes sense to you?
>
>   Thanks,
>
>     Matt
>
> On Dec 13, 2007 5:32 PM, Randall Mackie <randy at geosystem.us> wrote:
>> I have a situation where I've put a model vector m(i,j,k) into a parallel
>> PETSc vector for use in my modeling code. However, I'm now adding a bit of code
>> where I want to do some calculations based on the 1D average of the model.
>> In other words, for each k, I want to average m(i,j), and so produce a new
>> model vector m_avg(k).
>>
>> So, to do this, it would seem that I need to create a VecScatter that will,
>> for each layer, scatter all the m(i,j) into a 2D vector, then I can take
>> the average. It would seem that I need to create an Index Set to do this,
>> but I'm a bit confused as to how to go about it actually, since I've never
>> used Index Sets.
>>
>> Can someone outline the basic steps given my description above?
>>
>> Thanks, Randy
>>
>> --
>> Randall Mackie
>> GSY-USA, Inc.
>> PMB# 643
>> 2261 Market St.,
>> San Francisco, CA 94114-1600
>> Tel (415) 469-8649
>> Fax (415) 469-5044
>>
>> California Registered Geophysicist
>>
>>
>
>
>

--
Randall Mackie
GSY-USA, Inc.
PMB# 643
2261 Market St.,
San Francisco, CA 94114-1600
Tel (415) 469-8649
Fax (415) 469-5044

California Registered Geophysicist