Message Boards Message Boards

Break ParallelTable once a valid result is obtained.

Posted 1 year ago

See my code snippet below:

In[1539]:= Clear[sVecTM,TM];
ParallelTable[
lTM=tm;
sVecTM=Array[Subscript[x, #]&,{3}];
TM=AffineTransform[{lTM,sVecTM}]//TransformationMatrix;
(*gen2=SG229me[[5]]*)
gen2=i;
lgen2=gen2[[1;;3,1;;3]];
xx=Select[ SGITA229, #[[1;;3,1;;3]]==Inverse[lTM] . lgen2 . lTM && #[[1;;3,4]]!={0,0,0}&]//First;
If[Length[xx]>0,
sol=Solve[ gen2 . TM == TM . xx, Flatten[sVecTM], Rationals ];
If [ Length[sol] > 0 && Length[sol//First]==3,
  TM=TM/.sol//First;
  If[ SetEqualQ[AMTConjOnRight[SGGenSet229me,TM]//AMTSpaceGroupOnLeft//First, SGITA229]
,TM]
]
]
,{i,SG229me}]

(kernel 43) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 7) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 10) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 11) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 15) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 16) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 18) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 25) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 33) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 36) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 40) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 41) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 2) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 18) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 36) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 29) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 40) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 1) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 16) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 31) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 6) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 21) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 27) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 3) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 13) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 37) Solve::svars :  Equations may not give solutions for all "solve" variables.

Out[1540]= {Null, Null, Null, Null, {{1, 1/2, 1/2, -(3/8)}, {1/2, 1, 
   1/2, -(3/8)}, {1/2, 1/2, 1, -(3/8)}, {0, 0, 0, 
   1}}, Null, Null, Null, Null, Null, {{1, 1/2, 1/2, -(3/8)}, {1/2, 1,
    1/2, -(3/8)}, {1/2, 1/2, 1, -(3/8)}, {0, 0, 0, 
   1}}, Null, Null, {{1, 1/2, 1/2, -(3/8)}, {1/2, 1, 1/2, -(3/8)}, {1/
   2, 1/2, 1, -(3/8)}, {0, 0, 0, 
   1}}, Null, Null, Null, Null, Null, {{1, 1/2, 1/2, -(3/8)}, {1/2, 1,
    1/2, -(3/8)}, {1/2, 1/2, 1, -(3/8)}, {0, 0, 0, 
   1}}, Null, Null, {{1, 1/2, 1/2, -(3/8)}, {1/2, 1, 1/2, -(3/8)}, {1/
   2, 1/2, 1, -(3/8)}, {0, 0, 0, 1}}, Null, {{1, 1/2, 1/
   2, -(3/8)}, {1/2, 1, 1/2, -(3/8)}, {1/2, 1/2, 1, -(3/8)}, {0, 0, 0,
    1}}, Null, {{1, 1/2, 1/2, -(3/8)}, {1/2, 1, 1/2, -(3/8)}, {1/2, 1/
   2, 1, -(3/8)}, {0, 0, 0, 
   1}}, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, \
Null, Null, {{1, 1/2, 1/2, -(3/8)}, {1/2, 1, 1/2, -(3/8)}, {1/2, 1/2, 
   1, -(3/8)}, {0, 0, 0, 1}}, {{1, 1/2, 1/2, -(3/8)}, {1/2, 1, 1/
   2, -(3/8)}, {1/2, 1/2, 1, -(3/8)}, {0, 0, 0, 
   1}}, Null, Null, Null, Null, Null, Null, Null, Null, {{1, 1/2, 1/
   2, -(3/8)}, {1/2, 1, 1/2, -(3/8)}, {1/2, 1/2, 1, -(3/8)}, {0, 0, 0,
    1}}, Null, Null, {{1, 1/2, 1/2, -(3/8)}, {1/2, 1, 1/
   2, -(3/8)}, {1/2, 1/2, 1, -(3/8)}, {0, 0, 0, 1}}, Null, Null, {{1, 
   1/2, 1/2, -(3/8)}, {1/2, 1, 1/2, -(3/8)}, {1/2, 1/2, 
   1, -(3/8)}, {0, 0, 0, 
   1}}, Null, Null, Null, Null, Null, Null, Null, {{1, 1/2, 1/
   2, -(3/8)}, {1/2, 1, 1/2, -(3/8)}, {1/2, 1/2, 1, -(3/8)}, {0, 0, 0,
    1}}, Null, {{1, 1/2, 1/2, -(3/8)}, {1/2, 1, 1/2, -(3/8)}, {1/2, 1/
   2, 1, -(3/8)}, {0, 0, 0, 
   1}}, Null, Null, Null, Null, Null, Null, {{1, 1/2, 1/
   2, -(3/8)}, {1/2, 1, 1/2, -(3/8)}, {1/2, 1/2, 1, -(3/8)}, {0, 0, 0,
    1}}, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, \
Null}

I want to eliminate the invalid results displayed as Null and Break the ParallelTable command once a valid result is obtained, which is, in the above example, the 5th entry in the result table. Any tips for achieving this goal?

Regards,
Zhao

POSTED BY: Hongyi Zhao
2 Replies
Posted 1 year ago

I tried all the methods recommended there, and they all seemed to work. Below is one of them:

In[242]:= Clear[sVecTM,x,TM];
ParallelTable[
(*Here should first check the metric and then select the ones for further checking*)
lTM=gen2conjs[[17]];
sVecTM=Array[x,{3}];
TM=AffineTransform[{lTM,sVecTM}]//TransformationMatrix;
(*gen2=SG229me[[5]]*)
gen2=i;
lgen2=gen2[[1;;3,1;;3]];
xx=Select[ SGITA229, #[[1;;3,1;;3]]==Inverse[lTM] . lgen2 . lTM && #[[1;;3,4]]!={0,0,0}&]//First;
If[Length[xx]>0,
sol=Solve[ gen2 . TM == TM . xx, Flatten[sVecTM], Rationals ];
If [ Length[sol] > 0 && Length[sol//First]==3,
  TM=TM/.sol//First;
  If[ SetEqualQ[AMTConjOnRight[SGGenSet229me,TM]//AMTSpaceGroupOnLeft//First, SGITA229]
,TM, Return[, Table]]
]
]
,{i,SG229me}]//DeleteCases[#,Null,2]&//Union

(kernel 13) Solve::svars :  Equations may not give solutions for all "solve" variables.

(kernel 21) Solve::svars :  Equations may not give solutions for all "solve" variables.

Out[243]= {{{-(1/2), -1, -(1/2), 5/8}, {-1, -(1/2), -(1/2), 1/
   8}, {-(1/2), -(1/2), -1, 9/8}, {0, 0, 0, 1}}, {{-(1/2), -1, -(1/2),
    5/8}, {-1, -(1/2), -(1/2), 5/8}, {-(1/2), -(1/2), -1, 5/8}, {0, 0,
    0, 1}}, {{-(1/2), -1, -(1/2), 5/8}, {-1, -(1/2), -(1/2), 9/
   8}, {-(1/2), -(1/2), -1, 1/8}, {0, 0, 0, 1}}, {{-(1/2), -1, -(1/2),
    9/8}, {-1, -(1/2), -(1/2), 1/8}, {-(1/2), -(1/2), -1, 5/8}, {0, 0,
    0, 1}}, {{-(1/2), -1, -(1/2), 9/8}, {-1, -(1/2), -(1/2), 5/
   8}, {-(1/2), -(1/2), -1, 1/8}, {0, 0, 0, 1}}}

But as you can see, there are still multiple results returned. My explanation for this phenomenon is as follows: when parallelization is enabled, the task is distributed over different cores. Because of the parallel computing feature of the task, it is possible that the valid results are found almost simultaneously by different sub-processes (threads) running on different cores, which ultimately led to the above observed behavior.

I still don't know whether there is an accurate method to control the number of results returned.

POSTED BY: Hongyi Zhao

I typically use the suggestions here. Should work fine with ParallelTable but I have never tried that.

POSTED BY: Rohit Namjoshi
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