Message Boards Message Boards

1
|
4064 Views
|
10 Replies
|
8 Total Likes
View groups...
Share
Share this post:

How to evaluate parallelized with @@@?

Posted 1 year ago

Hello, I am curious how to evaluate parallelized with @@@. For example:

a = RandomInteger[9, {10000000, 3}]
b = ReplaceAll[0 -> 1][a]
c=(Total[{#1 + #2, #2*#3, #3/#1}]) & @@@ b

This is just a case. In many situations, I need to save time when evaluating them with @@@, so I hope to use parallelize with @@@, but I can't, as I change to

Parallelize[Total[{#1 + #2, #2*#3, #3/#1}] & @@@ b]

The error is: enter image description here

POSTED BY: Zhenyu Zeng
10 Replies

Yes, I can reproduce the problem in 13.1. I am surprised that it does not work in that version. I would report the problem to Wolfram Support and ask if the change is intentional.

POSTED BY: Szabolcs Horvát
Posted 1 year ago

If you have replies from WL, I hope you can send me a copy. I am weird about why using ParallelMap takes even more than ten times time than not using ParalleleMap?

POSTED BY: Zhenyu Zeng
Posted 1 year ago

Zhenyu, the term 'I would' is an idiomatic (proxy) way of saying 'you should'. So I think that Szabolcs is suggesting that you should report this problem to Wolfram.

POSTED BY: Hans Milton
Posted 1 year ago

Hello, May you tell me why I would is an idiomatic way of saying you should and when I would means I would? Thanks.

POSTED BY: Zhenyu Zeng
Posted 1 year ago

Think of it as a way of saying "If I were you I would ...", different from "I will ...".

If you think that is confusing, consider how confusing it is for someone learning 中文 when they come across 加油 or 老马识途 :-)

POSTED BY: Updating Name
Posted 1 year ago

Thanks a lot. So, if one says "I would", one exactly says "If ... I would". Am I right? In Chinese, there are a lot of this implied meaning。

POSTED BY: Zhenyu Zeng
Posted 1 year ago
In[1]:= $Version

Out[1]= "13.1.0 for Microsoft Windows (64-bit) (June 16, 2022)"
In[3]:= list = RandomInteger[10, {20, 2}]

Out[3]= {{9, 5}, {6, 3}, {7, 5}, {9, 6}, {8, 1}, {4, 8}, {2, 8}, {6, 
  7}, {10, 8}, {3, 9}, {7, 7}, {5, 7}, {7, 7}, {8, 3}, {9, 6}, {8, 
  6}, {8, 4}, {8, 8}, {1, 7}, {1, 2}}

In[4]:= Parallelize[Print @@@ list]

During evaluation of In[4]:= Parallelize::nopar1: Print@@@list cannot be parallelized; proceeding with sequential evaluation.

During evaluation of In[4]:= 95

During evaluation of In[4]:= 63

During evaluation of In[4]:= 75

During evaluation of In[4]:= 96

During evaluation of In[4]:= 81

During evaluation of In[4]:= 48

During evaluation of In[4]:= 28

During evaluation of In[4]:= 67

During evaluation of In[4]:= 108

During evaluation of In[4]:= 39

During evaluation of In[4]:= 77

During evaluation of In[4]:= 57

During evaluation of In[4]:= 77

During evaluation of In[4]:= 83

During evaluation of In[4]:= 96

During evaluation of In[4]:= 86

During evaluation of In[4]:= 84

During evaluation of In[4]:= 88

During evaluation of In[4]:= 17

During evaluation of In[4]:= 12

Out[4]= {Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, \
Null, Null, Null, Null, Null, Null, Null, Null, Null, Null}

Weird, I still can't.

enter image description here

POSTED BY: Zhenyu Zeng

What version of Mathematica are you using? Parallelize works with @@@ for me.

In[1]:= $Version

Out[1]= "13.0.1 for Mac OS X x86 (64-bit) (January 28, 2022)"

In[2]:= list = RandomInteger[10, {20, 2}];

In[3]:= Parallelize[Print @@@ list];

(kernel 4) 108

(kernel 3) 58

(kernel 2) 59

(kernel 1) 210

(kernel 4) 10

(kernel 3) 31

(kernel 2) 08

(kernel 1) 02

(kernel 4) 86

(kernel 3) 29

(kernel 2) 22

(kernel 1) 27

(kernel 4) 88

(kernel 3) 77

(kernel 2) 11

(kernel 1) 108

(kernel 4) 63

(kernel 3) 82

(kernel 2) 84

(kernel 1) 1010
POSTED BY: Szabolcs Horvát
Posted 1 year ago

ParalllMap is terrible. Don't use it.

b = ReplaceAll[0 -> 1][RandomInteger[9, {100000000, 3}]];
Plus @@ (Total[{#1 + #2, #2*#3, #3/#1}] & @@@ b) // Timing
Plus @@ ParallelMap[Apply[Total[{#1 + #2, #2*#3, #3/#1}] &], 
   b] // Timing

Out are

{346.641, 4047515637259/1260}
{3845.88, 4047515637259/1260}
POSTED BY: Zhenyu Zeng

Perhaps do something like this:

ParallelMap[Apply[Total[{#1 + #2, #2*#3, #3/#1}] &], b]
POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract