Message Boards Message Boards

0
|
3318 Views
|
6 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Run NestWhile in parallel mode.

Posted 1 year ago

Are there methods to run NestWhile in parallel mode?

Regards,
Zhao

POSTED BY: Hongyi Zhao
6 Replies
Posted 1 year ago

See the following example code snippet, which is based on the method here:

In[19]:= gMatrix = 
  SparseArray[{{1, 3} -> 1, {2, 1} -> 1, {3, 2} -> 
     1, {4, 4} -> -(1/2), {4, 5} -> -(1/2), {4, 6} -> -(1/2), {4, 
      7} -> -(1/2), {5, 4} -> 1/2, {5, 5} -> -(1/2), {5, 6} -> 
     1/2, {5, 7} -> -(1/2), {6, 4} -> 
     1/2, {6, 5} -> -(1/2), {6, 6} -> -(1/2), {6, 7} -> 1/2, {7, 4} ->
      1/2, {7, 5} -> 
     1/2, {7, 6} -> -(1/2), {7, 7} -> -(1/2), {_, _} -> 0}, 7];

hMatrix = 
  SparseArray[{{1, 5} -> 
     1, {2, 2} -> -(1/2), {2, 3} -> -(1/2), {2, 6} -> 1/2, {2, 7} -> 
     1/2, {3, 2} -> 1/2, {3, 3} -> -(1/2), {3, 6} -> -(1/2), {3, 7} ->
      1/2, {4, 1} -> 1, {5, 4} -> 1, {6, 2} -> -(1/2), {6, 3} -> 
     1/2, {6, 6} -> -(1/2), {6, 7} -> 
     1/2, {7, 2} -> -(1/2), {7, 3} -> -(1/2), {7, 6} -> -(1/2), {7, 
      7} -> -(1/2), {_, _} -> 0}, 7];

kMatrix = 
  SparseArray[{{1, 4} -> -1, {2, 2} -> -(1/2), {2, 3} -> -(1/2), {2, 
      6} -> -(1/2), {2, 7} -> 1/2, {3, 2} -> 
     1/2, {3, 3} -> -(1/2), {3, 6} -> -(1/2), {3, 7} -> -(1/2), {4, 
      5} -> -1, {5, 1} -> 1, {6, 2} -> 1/2, {6, 3} -> 
     1/2, {6, 6} -> -(1/2), {6, 7} -> 1/2, {7, 2} -> -(1/2), {7, 3} ->
      1/2, {7, 6} -> -(1/2), {7, 7} -> -(1/2), {_, _} -> 0}, 7];

gen=  {gMatrix, hMatrix, kMatrix};    
count = 0; (matrices = NestWhile[(Print[count++]; 
             Union[#~Join~Flatten[Outer[Dot, gen, #, 1], 1]]) &, 
               {IdentityMatrix[7]}, Length[#2] != Length[#1] &, 2, 99]) // Length // Timing

During evaluation of In[19]:= 0

During evaluation of In[19]:= 1

During evaluation of In[19]:= 2

During evaluation of In[19]:= 3

During evaluation of In[19]:= 4

During evaluation of In[19]:= 5

During evaluation of In[19]:= 6

During evaluation of In[19]:= 7

During evaluation of In[19]:= 8

During evaluation of In[19]:= 9

During evaluation of In[19]:= 10

During evaluation of In[19]:= 11

During evaluation of In[19]:= 12

During evaluation of In[19]:= 13

Out[23]= {2.27465, 6048}
POSTED BY: Hongyi Zhao

Can the computation performed by the function passed to NestWhile be parallelized?

POSTED BY: Rohit Namjoshi
Posted 1 year ago

How would you propose that might be done?

I don't know. I ask, only because I have a time-consuming calculation based on NestWhile, so I want to take advantage of parallelism to improve the efficiency.

POSTED BY: Hongyi Zhao

How would you propose that might be done?

(What I'm asking, in slightly more detail, is that questions lacking algorithmic answers be avoided. Absent a clear suggestion in the initial post as to how parallelism might be attained in principle, this is simply not a suitable question for the forum.)

POSTED BY: Daniel Lichtblau
Posted 1 year ago

So how do we take advantage of parallel computing in this scenario?

POSTED BY: Hongyi Zhao

I do not think this is possible - how could parallelize a function where each iteration uses the result from the previous iteration?

POSTED BY: Jason Biggs
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