1
$\begingroup$

I am currently working on parallelizing a piece of code, as indicated in here, which explains the following, rather convoluted, way of evaluating a function; so please bare with me. But irrespective of the parallelization, the following performance issue occurs.

Say I have the functions fA and fB, both written as a package schematically of the form

BeginPackage["packagefA`"]
fA::usage = "some usage."
Begin["envfA`"]
Needs["packagefB`","somepath/packagefB.wl"];

fA[someinput_]:=Module[{input=someinput},
Some codeA
partofoutput=fB[parameter produced by Some codeA];
Some more code
];
End[]
EndPackage[]

whereas fB looks like

BeginPackage["packagefB`"]
fB::usage = "some usage."
Begin["envfB`"]

fB[input_]:=Module[{someinput=input},
some code
];
End[]
EndPackage[]

So essentially I am just calling function fB inside function fA. Finally, the function fA is then called by some notebook or script (lets call it interfaceA), which looks like

...
Needs["packagefA`","somepath/packagefA.wl"]
save=fA[someinput];
...

Here is the issue I ran into: If I have a separate interface (say interfaceB) that only calls function fB, then the evaluation of fB is relatively fast. However, if I run interfaceA and look at how long it takes to evaluate the same function fB as part of fA, then it turns out that this will take significantly longer to evaluate. Why does fB not evaluate just as quickly as part of fA compared to when I call fB directly? Does it have to do with how I load the Package packagefB within packagefA?

$\endgroup$
  • 1
    $\begingroup$ I don't think your problem can be solved without a working example. p.s. it should be Begin["`envfB`"] etc. $\endgroup$ – Kuba Jun 11 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.