On Mon, 16 Feb 2015, Sven Schreiber wrote:
Am 16.02.2015 um 18:42 schrieb Allin Cottrell:
> On Mon, 16 Feb 2015, Sven Schreiber wrote:
>
>> Am 16.02.2015 um 17:58 schrieb Allin Cottrell:
>
>>> The trouble here is that the matrices a and b exist only in the rank 0
>>> process; they need to exist everywhere.
>>>
>>> <hansl>
>>> mpi --np=2
>>> matrix a
>>> matrix b
>>> if $mpirank == 0
>>> b = ones(1000,1)
>>> a = zeros(1000,1)
>>> endif
>>> mpiscatter(&b, byrows)
>>> </hansl>
>>>
>>
>> Hm, ok I understand. My spontaneous reaction would be: "but isn't this
>> what mpiscatter (or mpibroadcast) is supposed to achieve as part of
>> their job?".
>> What's the value added of requiring the pre-existence of the recipient
>> objects?
>
> It's not a question of value added, it's just how MPI works! Remember
> that each "rank" corresponds to a distinct instance of gretlmpi.
> Consider your original code, without the prior declaration of the
> matrices, from the point of view of the rank 1 process: the first line
> rank 1 sees is:
>
> mpiscatter(&b, byrows)
>
> So it's like, "mpiscatter what?? I don't know anything about this
b".
>
Yeah, I actually understood that :-)
But since we're on the gretl list my comment was aimed at the hansl wrapper
implementation: Why can't hansl see the &b in mpiscatter(&b, byrows) and
shout out: "Hey I've seen this b before, it was created in line xyz, and now
everybody's getting it, too." I mean this look-up of existing objects is what
the interpreter does all the time, no?
Not really. If you do the following, which seems analogous to me,
<hansl>
if 0
matrix b = I(3)
endif
print b
</hansl>
you'll get an error since b was never actually defined. And
if $mpirank == 0
is just like "if 0" from the point of view of all MPI processes other
than root.
Allin