Message Boards Message Boards

GROUPS:

Apply functions to a nested list in parallel?

Posted 6 months ago
309 Views
|
1 Reply
|
1 Total Likes
|

Hi. I have a function that generates a nested list containing coordinates, now i want to apply a function to those coordinates.

  'CoordinatesGeneration =   Function[ {m, n, a, b}, Table[Table[{a /2 (i + j), a (j - i), b /2 (k + h),  b (k - h)}, {i, -(1/2) (m - 1), (m - 1)/
          2}, {j, -(1/2) (m - 1), (m - 1)/2}], {h, -(1/2) (n - 1), (n - 1)/2}, {k, -(1/2) (n - 1), (n - 1)/2}]];'

What i tried is to flatten the list and then use partition to group the list each 4 elements and then use apply.

Apply[f ,Partition[Flatten[PositionGeneration[10, 10, a, b]], 4], {1}]]]

It worked, but now i want to do the evaluation in parallel. I try to use ParallelMap with Apply inside and ParallelCombine but it only work if the list was less than 4 groups in 5 groups it doesnt do what i wanted.

ParallelCombine[ f @@@ # &, Partition[Flatten[PositionGeneration[3, 3, a, b]], 4], Plus]

I want to parallelize it because when i have big numbers in counters m,n the evalution can take several seconds, so maybe using parallel functions can speed up a bit.

Thank you.

Map can operate at low levels in a list

In[2]:= Map[f, {{a, b}, {c, d, e}}, {2}]

Out[2]= {{f[a], f[b]}, {f[c], f[d], f[e]}}
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract