1
$\begingroup$

The following code

ClearAttributes[Times, Orderless];
temp = b*a;
Do[
  Print[temp];, {i, 1}
]

will print

b*a

However, the following code

ClearAttributes[Times, Orderless];
temp = b*a;
ParallelDo[
 Print[temp];, {i, 1}
]

will print

a*b

My understanding is that the ClearAttributes is only working on the current kernel before the parallel kernels are created. Thus, the parallel kernels have not had their Times cleared of the Orderless attribute. Is there a way to keep the Orderless attribute for Times cleared in the ParallelDo without putting the line

ClearAttributes[Times, Orderless];

in the ParallelDo loop?

$\endgroup$
  • 1
    $\begingroup$ Why is there even a need to do ClearAttributes[Times, Orderless]? $\endgroup$ – J. M. will be back soon Sep 25 '18 at 18:43
  • $\begingroup$ I'm trying to simplify a messy expression that utilizes NonCommutativeMultiply. I'm removing the Orderless attribute so that I can thread NonCommutativeMultiply over Times for use later during the simplification without the Orderless attribute changing the order of how I defined my variables. I'm not sure if there is a better way to do that. $\endgroup$ – D W Sep 25 '18 at 18:53
  • 1
    $\begingroup$ If your "product" isn't actually commutative, and NonCommutativeMultiply[] is already in use, you can use e.g. CircleTimes[] as a dummy operator, which won't autosort the factors. $\endgroup$ – J. M. will be back soon Sep 25 '18 at 18:58

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.