0

I'm running gnuapl 1.5 with the experimental parallel features enabled. Running the following two lines across four cores:

a←b←⍳x←1000

a-⊂b ⍝This line seems to take a very long time to compute.

For smaller values of x (such as ten and one hundred), this computation doesn't have any noticeable lag.

Can anyone recommend a different approach than a-⊂b

alexweiner
  • 61
  • 4

2 Answers2

2

first of all, your output data size increases quadratically:

      a←b←⍳x←100 ◊ ⍴,⍕ a-⊂b 
33240
      a←b←⍳x←200 ◊ ⍴,⍕ a-⊂b 
146490
      a←b←⍳x←300 ◊ ⍴,⍕ a-⊂b 
349740
      a←b←⍳x←400 ◊ ⍴,⍕ a-⊂b 
642990
      a←b←⍳x←500 ◊ ⍴,⍕ a-⊂b 
1026240
      a←b←⍳x←600 ◊ ⍴,⍕ a-⊂b 
1499490
      a←b←⍳x←700 ◊ ⍴,⍕ a-⊂b 
2062740
      a←b←⍳x←800 ◊ ⍴,⍕ a-⊂b 
2715990
      a←b←⍳x←900 ◊ ⍴,⍕ a-⊂b 
3459240

Then, the delay seems to occur only when printing the data. The formatting rules of APL2 are difficult to optimize for all cases. In your case it looks like your output rows are extremely long (4292490 characters for x←1000). But even then I believe the time needed to display the data is still shorter than the time to read them.

/// Jürgen

1

Are you sure it's the computation and not echoing the result to the screen that's taking time?

I'm not on GnuAPL, but on mine it seems quick:

B←A-⊂A←⍳1000

Here I'm assigning the result to B rather than echoing it.

An alternative could be:

B←,/A∘.-A←⍳1000

The actual computation ∘.- might be quicker (though it would eat a lot of memory), but to convert it to a vector of vectors ,/ is slow. (The code looks cooler, though...)

mappo
  • 444
  • 2
  • 9
  • I am sure that it is the actually calculation, and not displaying to the screen. I also tried this one Dyalog APL and it was very speedy for A←B←⍳1000. Dyalog seems to hang for a bit at around A←B←⍳45000 on my machine. I also found that the ∘.- is also very slow for the same value. – alexweiner Apr 10 '15 at 21:52