1
$\begingroup$

I am trying to get the progress indicator bar from my package to the user interface. I am failing badly. I created an mini code that mimics my main code. Here I keep track of a paralleltable.

Some how I need to take the value of the progress indicator out from the loop and package to the interface.

Here is the main code:

Get[FileNameJoin[{NotebookDirectory[EvaluationNotebook[]], 
"DummyPackage.wl"}]];
 Panel[DynamicModule[{np = 100, nd = 30, Res1 = 1.0, 
 Res2 = ProgressIndicator[0]}, 
 Column[{Style["Random", "Function"] , 
Row[{"Digits ", InputField[Dynamic[nd]]}, Spacer[5]], 
Row[{"Precision ", InputField[Dynamic[np]]}, Spacer[5]],
(*Button[Style["Inputs",Green,Bold],Res2=ProgressIndicator[0]],*)

    Button[
 Style["Calculate", Green, Bold], {Res2 = ProgressIndicator[0], 
  Res = DummyPackage`myDummyF[nd, np]; Res1 = Res[[1]]; 
  Res2 = Res[[2]];}, Method -> "Queued"],
  Row[{Style["Result ", 12, Red], 
  InputField[Dynamic[Res1], FieldSize -> 30, Enabled -> False]}, 
  Spacer[15]],
  Row[{Style["Progress ", 12, Red], Dynamic[Res2]}, Spacer[15]],
  Button[Style["Save", Green, Bold], 
 NotebookSave[EvaluationNotebook[], Interactive -> True]]
}],
Initialization :> (
Get[FileNameJoin[{NotebookDirectory[EvaluationNotebook[]], 
    "DummyPackage.wl"}]];)]]

And the package :

BeginPackage["DummyPackage`"]
LaunchKernels[$ProcessorCount];
myDummyF[nd_,np_]:=Module[{mat,mat2,aI,dl,d=0,tr=0},

 ns=200;
 mat=SetAccuracy[RandomReal[{-100,100},ns],nd];
 mat2=SetAccuracy[RandomReal[{-200,200},ns],nd];

  aI=ConstantArray[0,np];
 SetSharedVariable[d,tr];
 ParallelEvaluate[dl = 0];



 Monitor[aI=ParallelTable[If[Mod[dl++, Ceiling[nd/75]] == 0, d +=        Ceiling[nd/75]]; 
 If[iC==np,d==np];
 aI=SetAccuracy[mat.(mat2/iC^0.5),nd]
 ,{iC,np},DistributedContexts-> {"DummyPackage`"}];,tr=(d/np);];

  aInum=Apply[Plus,(aI/np)];

  Return[{aInum,ProgressIndicator[tr]}]];
  SetAttributes[{myDummyF},{ReadProtected,Protected,Locked}];
  EndPackage[];

>

$\endgroup$
5
  • 2
    $\begingroup$ I'm sorry for being picky about your posts but it is really in your interest to create minimal examples. You will get more attention. Are you sure saving, attributes or percision is related to the problem? $\endgroup$
    – Kuba
    Commented Sep 8, 2016 at 6:38
  • $\begingroup$ I thought the example was minimal. Two inputs, one array multiplication and two outputs. I could have removed the inputs nd, np but then the code does not feel complete. $\endgroup$
    – Erdem
    Commented Sep 8, 2016 at 15:26
  • $\begingroup$ As you can see by comments and upvotes, it wasn't :-/ Why removing inputs? What about things I've talked about? $\endgroup$
    – Kuba
    Commented Sep 9, 2016 at 6:48
  • $\begingroup$ You might be right or maybe it is not an interesting problem for the most. And I did not delete anything :) $\endgroup$
    – Erdem
    Commented Sep 9, 2016 at 14:27
  • 4
    $\begingroup$ I'm voting to close this question as off-topic because it is too localized. $\endgroup$
    – Kuba
    Commented Dec 7, 2016 at 21:21

1 Answer 1

1
$\begingroup$

I found a way to do it. To be honest, I am not sure how it is working. It is based on @Nasser, there is only one thing in the setup a problem is "Null" appearing during the calculation. If I can find a solution for that I will update it in here. (FYI: Tracking the progress this way has a major hit on the performance)

Get[FileNameJoin[{NotebookDirectory[EvaluationNotebook[]], 
"DummyPackage2.wl"}]];
 Panel[DynamicModule[{np = 100, nd = 30, Res = {1.0, 0}, track = 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 = DummyPackage2`myDummyF[nd, np, Unevaluated[track]]
 , Method -> "Queued"],

Row[{Style["Result ", 12, Red], 
  InputField[Dynamic[Res[[1]]], FieldSize -> 30, 
   Enabled -> False]}, Spacer[15]],
Row[{Style["Progress ", 12, Red], 
  Dynamic[ProgressIndicator[track, {0, 1}]]}, Spacer[15]],
Button[Style["Save", Green, Bold], 
 NotebookSave[EvaluationNotebook[], Interactive -> True]]
}],
Initialization :> (
Get[FileNameJoin[{NotebookDirectory[EvaluationNotebook[]], 
    "DummyPackage2.wl"}]];)]]

and the package

BeginPackage["DummyPackage2`"]
LaunchKernels[$ProcessorCount]
myDummyF[nd_,np_,track_]:=Module[{mat,mat2,aI,dl,d=0},

ns=200;
mat=SetAccuracy[RandomReal[{-100,100},ns],nd];
mat2=SetAccuracy[RandomReal[{-200,200},ns],nd];

aI=ConstantArray[0,np];


SetSharedVariable[d];
ParallelEvaluate[dl = 0];
Monitor[aI=ParallelTable[If[Mod[dl++, Ceiling[nd/75]] == 0, d +=    Ceiling[nd/75]]; 

aI=SetAccuracy[mat.(mat2/iC^0.5),nd]
,{iC,np},DistributedContexts -> {"DummyPackage2`"}];,
track=(d/np);];

iC=nd;
If[iC==nd,track=1];

aInum=Apply[Plus,(aI/np)];

Return[{aInum,track}];];
SetAttributes[{myDummyF},{ReadProtected,Protected,Locked}];
EndPackage[];
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.