Am 16.02.2015 um 16:54 schrieb Allin Cottrell:
On Mon, 16 Feb 2015, Sven Schreiber wrote:
> Am 16.02.2015 um 14:45 schrieb Allin Cottrell:
>> On Mon, 16 Feb 2015, Sven Schreiber wrote:
>>
>>> Am 16.02.2015 um 09:22 schrieb Riccardo (Jack) Lucchetti:
>
>>>>
>>>> Yes, it should be ok. Is anything broken?
>>>
>>> No (or at least I haven't found out yet), but I think the example is
>>> too sophisticated. I mean, the example is excellent and shouldn't go
>>> away, but IMO there should be something of the "Hello world" type,
>>> much shorter. I will try to produce a minimal example.
>>
>> OK, thanks.
>>
So here's a working attempt, still longer than I wanted though... but
there are lots of comments! Eventually I will check out from which
number T on the speed gain outweighs the overhead.
-sven
<hansl>
# The not-quite-"Hello world" of gretl-mpi
# prepare the common input
T = 100
matrix in = ones(T,1)
# and transfer it
mwrite(in, "in.mat", 1)
mpi --np=2 # can change the num of procs
matrix b, c # must declare for all procs
# get the input data with the root process 0
matrix b = $mpirank == 0 ? mread("in.mat", 1) : b
# divide up the input data
mpiscatter(&b, byrows)
# this is the parallelized operation
matrix c = sin(b) + log(b)
# collect the results
mpireduce(&c, vcat) # vertical stacking
# output in root process
if $mpirank == 0
print c
endif
end mpi
</hansl>