0
$\begingroup$

I am trying the following code:

Stocks = FinancialData["DE:AA*", "Lookup"];
Prices = ConstantArray[0, Length[Stocks]];
Parallelize[For[i = 1, i <= Length[Stocks], i++,
Prices[[i]] = FinancialData[Stocks[[i]], "Jan. 1, 2000"]]]

Why does parallelize not work here? It should be straightforward to distribute the preallocated List to different cores. Or am I wrong?

Best, Max

Edit:

I also tried the following to no avail:

Stocks = FinancialData["DE:AA*", "Lookup"];
Prices = {};
ParallelDo[
AppendTo[Prices, FinancialData[Stocks[[i]], "Jan. 1, 2000"]], {i, 
Length[Stocks]}]
$\endgroup$
  • 1
    $\begingroup$ What about prices = ParallelMap[FinancialData[#, "Jan. 1, 2000"] &, FinancialData["DE:AA*", "Lookup"]]? $\endgroup$ – BlacKow Dec 12 '16 at 21:26
1
$\begingroup$

Answer: The second approach works if I make Prices a shared Variable:

Stocks = FinancialData["DE:A*", "Lookup"];
Prices = {};
Length[Stocks]
SetSharedVariable[Prices]
SetSharedVariable[j]
Monitor[ParallelDo[j = i;
 AppendTo[Prices, FinancialData[Stocks[[i]], "Jan. 1, 2000"]], {i, 
  Length[Stocks]}], j]
$\endgroup$

Your Answer

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

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