5 Jul 21:32
Re: Parallel vs. sequential loops
From: Norbert Nemec <Norbert.Nemec.list@...>
Subject: Re: Parallel vs. sequential loops
Newsgroups: gmane.comp.lang.fortress.general
Date: 2008-07-05 19:32:50 GMT
Subject: Re: Parallel vs. sequential loops
Newsgroups: gmane.comp.lang.fortress.general
Date: 2008-07-05 19:32:50 GMT
dmitrey wrote:
> Norbert Nemec wrote:
>> dmitrey wrote:
>>> Norbert Nemec wrote:
>>>> dmitrey wrote:
>>>>> Norbert Nemec wrote:
>>>>>> seqloop i <- 0#n
>>>>>> vs.
>>>>>> parloop i <- 0#n
>>>>> but how would you translate current style
>>>>> for i<- 0#n, j<-seq(0#m) do {...} ?
>>>>
>>>> Split it up into two nested loops. The situation you point out is
>>>> rather specialized so a shorthand is not necessary. Forcing the
>>>> programmer to be a bit more explicit also makes the code more
>>>> readable and shows that this mixture of sequential and parallel
>>>> loop was done on purpose.
>>> I can't agree that the situation is rather specialized - look into
>>> fortress library, even now it already has a number of the cases. I
>>> had deal with lots of code (othe rprogramming languages) with
>>> several nested loops (as well as lots of other programmers, that are
>>> certainly present in the list as well) and it's really headache
>>> doing several for i for j for k ... end end end. I find current
>>> style very convenient, and it requires only single "end" statement
>>> while yours will require several.
>> Sure, nested loops are very common. But how often do you actually mix
>> parallel and sequential loops? Maybe I'm wrong in my assumption, but
>> I still think that the difference between parallel and sequential
>> loops should be more obvious that just a subtle seq().
> Despite I have no much fortress code written I have already used the
> mix, for example here's my vandermonde matrix generator written
> 2007/04/25
>
> vander[\nat n\](C) = do
> M : RR64[n,n] := array2[\RR64,n,n\](1)
> for j <- 0#n do M[j, n-1] := 1 end
> for j <- 0#n, i <- seq(1#n-1) do (*<- parallel and sec loop here*)
> M[j, n-i-1] := C[j] M[j,n-i]
> end
> M
> end
Sorry, but that seems to be an unlucky example, since it can be
expressed even more concise as:
vander[\nat n\](C) = do
M : RR64[n,n] := array2[\RR64,n,n\](1)
for j <- 0#n do
M[j, n-1] := 1
for i <- seq(1#n-1) do
M[j, n-i-1] := C[j] M[j,n-i]
end
end
M
end
But in any case: I still think that it makes sense to sacrifice the
possibility of mixing parallel and sequential loops in favor of a more
explicit syntax that aids readability and avoids offering a dangerous
implicit default.
RSS Feed