Group Abstract Group Abstract

Message Boards Message Boards

1
|
3.8K Views
|
5 Replies
|
1 Total Like
View groups...
Share
Share this post:

Assigning a name to variables depending on the thread number.

Posted 5 years ago

Hello,

I would like to name the variables dynamically, e.g. so that their names depend on the number of the thread being executed. Something like below:

n = 3;(*numer wątku*)
ParallelDo[
  Subscript[t, i] = Table[Random[], {10}], {i, n}];
t = Table[0, {10}];
Do[t += Subscript[t, i], {i, n}];
t

Unfortunately, table t has all zeros.

I tried to sum in a loop, I tried to use the $KernelID variable. Unfortunately, it didn't help.

The program "sees" the results because it can write them out:

n = 3;(*numer wątku*)
ParallelDo[
Subscript[t, i] = Table[Random[], {10}]; 
Print[Subscript[t, i]], {i, n}]

I am asking for a hint (it is certainly not very simple).

If "n" is greater than the number of threads, will the program (after the prompt) also work?

Best regards, DM

POSTED BY: D M
5 Replies
Posted 5 years ago

Thanks, did you try to write my code with your tip? Because I still don't know how to do it ...

POSTED BY: D M
Posted 5 years ago
Posted 5 years ago

Hi,

Because these arrays can be different in number, they can all be referenced at the same time (my Random [] is just an example).

POSTED BY: D M
Posted 5 years ago

Hi D M,

Can you explain the reason for wanting to do this

I would like to name the variables dynamically, e.g. so that their names depend on the number of the thread being executed.

POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard