Re: Parallel programming with FORALL?



On 1/13/2011 3:36 AM, glen herrmannsfeldt wrote:
Uno<merrilljensen@xxxxx> wrote:
(snip)

q2) Would you (or anyone else) take a stab at disambiguating fortran's
forall and perl's 'foreach'? An example from _Learning Perl_ p. 47 is:

foreach $rock (qw/bedrock slate lava/){
print "One rock is $rock.\n";
}

The perl foreach seems to be similar to a similar construct in
other interpreted languages, but rare in compiled languages.

It expands what is inside the ()'s, and then loops over the
elements of the expanded list.

As an example from another web site:

@Names = ('larry', 'curly', moe');

foreach (@Names) {
print $_;
}

The Unix C shell (/bin/csh) also has a similar foreach construct.
You can do things like:

foreach i ( `ls *.f` )
echo $i
gfortran $i
end

Glen,

I never understood that till now. Am I correct to think of $i as an analog to $_ in this snippet, that is, the default variable?

Normally, I'd fire it up on ubuntu, but I'm in Act III, Scene I of Pooch Screw: how I managed to lose ubuntu for a matter of months but--if the protagonist prevails--didn't lose data.

There is no array, but the list of file names from the ls
command is used as values for the loop variable.

Now, notice that it loops over the values of the array elements,
where FORALL (even though it isn't a loop construct) loops over
the subscript values, not the array element values.

There is an even more interesting form in awk, needed to loop
over elements of an associative array (the only kind in awk).

x[1]="one"
x[1000000000]="one billion"
for(i in x) print x[i];

There are only two elements in array x, with subscript values
of 1 and 1000000000. This form of for allows one to loop over
the valid subscripts for an array (and not necessarily in
increasing numerical order).

awk is a strange creature for those of us endeavoring to taxonimize unix for our first go-around.

Cheers,
--
Uno

.