Hello, I am trying to transfer the indicator bar to the user interface for my application but I fail to do so. I have 2 problems:
- When I use ParallelDo loop the indicator bar is not get updated with the calculation. I tried to implant the idea from http://stackoverflow.com/questions/7352461/monitoring-progress-of-a-parallel-computation-in-mathematica , no success.
- I would like to insert a row to my user interface where I can insert the indicator bar.
I got the idea using Monitor and ProgressIndicator couple from -> http://stackoverflow.com/questions/4398214/update-a-progress-bar-in-mathematica
Here, what I did so far. Main code
Get[FileNameJoin[{NotebookDirectory[EvaluationNotebook[]],
"DummyPackage.wl"}]];
Panel[DynamicModule[{np = 1000, nd = 30, Res = 1.0},
Column[{Style["Random", "Function"] ,
Row[{"Digits ", InputField[Dynamic[nd]]}, Spacer[5]],
Row[{"Precision ", InputField[Dynamic[np]]}, Spacer[5]],
Button[Style["Calculate", Green, Bold],
Res = DummyPackage`myDummyF[nd, np], Method -> "Queued"],
Row[{Style["Result ", 12, Red],
InputField[Dynamic[Res], FieldSize -> 30, Enabled -> False]},
Spacer[15]]
}],
Initialization :> (
Get[FileNameJoin[{NotebookDirectory[EvaluationNotebook[]],
"DummyPackage.wl"}]];)]]
the package
BeginPackage["DummyPackage`"]
myDummyF[nd_,np_]:=Module[{mat,mat2,aI},
ns=200;
mat=SetAccuracy[RandomReal[{-100,100},ns],nd];
mat2=SetAccuracy[RandomReal[{-200,200},ns],nd];
aI=ConstantArray[0,np];
SetSharedVariable[aI,iC];
Time=AbsoluteTiming[
If[nd<=16,
Monitor[Do[
If[iC==2,Print["---------------------"]];
If[iC==2,Print["Do Loop"," nd= ",nd," np= ",np]];
aI[[iC]]=SetAccuracy[mat.(mat2/iC^0.5),nd],{iC,np}],
ProgressIndicator[Dynamic[iC/np]]],
Monitor[ParallelDo[
If[iC==2,Print["---------------------"]];
If[iC==2,Print[" ParallelDo Loop"," nd= ",nd," np= ",np]];
aI[[iC]]=SetAccuracy[mat.(mat2/iC^0.5),nd],{iC,np}],ProgressIndicator[Dynamic[iC/np]]]]];
Print["Do loop time = ",Time[[1]]];
aInum=Apply[Plus,(aI/np)];
Print["Total = ",aInum];
Print["---------------------"];
Return[aInum]]
SetAttributes[{myDummyF},{ReadProtected,Protected,Locked}];
EndPackage[];
Here I can't see the bar in the nb. If I don't use a user interface for example :
myDummyF[nd_, np_] := Module[{mat, mat2, aI},
ns = 200;
mat = SetAccuracy[RandomReal[{-100, 100}, ns], nd];
mat2 = SetAccuracy[RandomReal[{-200, 200}, ns], nd];
aI = ConstantArray[0, np];
SetSharedVariable[aI, iC];
Time = AbsoluteTiming[
If[nd <= 16,
Monitor[Do[
If[iC == 2, Print["Do Loop"]];
aI[[iC]] = SetAccuracy[mat.(mat2/iC^0.5), nd], {iC, np}],
ProgressIndicator[Dynamic[iC/np]]],
Monitor[ParallelDo[
If[iC == 2, Print[" ParallelDo Loop"]];
aI[[iC]] = SetAccuracy[mat.(mat2/iC^0.5), nd], {iC, np}],
ProgressIndicator[Dynamic[iC/np]]]]];
Print["Do loop time = ", Time[[1]], ", np = ", np, ", nd = ", nd];
aInum = Apply[Plus, (aI/np)];
Print["Total = ", aInum];
Return[aInum]];
np = 100000;
nd = 15;
myDummyF[nd, np];
Do Loop version is working but I am not able to make it work for ParallelDo.
Thank you.
ps: I could not attach .wl format so I saved the package as .m file.
Attachments: