5
$\begingroup$

This works as expected:

Table[x[1], {x[1], 1, 10}]

However, the parallel version

ParallelTable[x[1], {x[1], 1, 10}]

complains that the expression cannot be parallelized. (The same applies to other iterators like Subscript[x,1] etc. instead of x[1].) How can I fix that?

$\endgroup$
3
$\begingroup$

This works as well, similar to Sjoerd C. de Vries' method:

Block[{x}, x[1] = Unique[]; ParallelTable[x[1], {x[1], 1, 10}]]

{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

And this does, too:

Block[{x}, x /: Subscript[x, i] = Unique[]; 
 ParallelTable[Subscript[x, i], {Subscript[x, i], 1, 10}]]

{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

$\endgroup$
2
$\begingroup$

This works, but looks rather clumsy to me:

Hold[ParallelTable[x[1], {x[1], 1, 10}]] /.  x[i_] -> Unique[] // ReleaseHold

{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

Also works for subscripts:

Hold[ParallelTable[Subscript[x, i], {Subscript[x, i], 1, 10}]] /. 
     Subscript[x, i_] -> Unique[] // ReleaseHold

{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

$\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.