|
[Sponsors] |
Storing and using variables on a specific processor |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
July 10, 2019, 02:40 |
Storing and using variables on a specific processor
|
#1 |
Member
Ashish Magar
Join Date: Jul 2016
Location: Mumbai, India
Posts: 81
Rep Power: 9 |
Hello guys,
I will describe my problem briefly. In my modified code, I am doing certain computations (such as averaging and stuff) on some pipes. The mesh is huge and I wanted to decompose, such that the whole pipe section comes under one processor. This was done. I wanted to declare some variables which are to be used only on the same processor as the pipe and to be accessed at different times during an outer iteration (maybe piso). I was trying to do something like this: Code:
if(Pstream::MyProcNo() == 1){ int a[100]; } //Some solving to be done everywhere if(Pstream::MyProcNo() == 1){ a[50] = 5; } Code:
a is not declared in this scope Is there some way I can do this, or am I doing this completely wrong? Thanks |
|
July 10, 2019, 04:53 |
|
#2 | |
Member
Hosein
Join Date: Nov 2011
Location: Germany
Posts: 93
Rep Power: 14 |
Quote:
The point is once your variable is defined enclosed in curly braces its lifetime will come to an end once the control reaches to the end of the brace. In case you define a variable like this you need to make sure that you finish your job with that extra variable inside that territory. But it seems you want to have it for later use. Hence, you may allocate dynamically your variable with the help of a small function giving the size of your variable to be zero for other procs and giving the desired size for your specific proc. exp. Code:
void assign(int& arraySize, int nproc, int procID) { if(procID == 1) // assuming your case { arraySize = 100; } else { arraySize = 0; } } Code:
int arraySize; assign(arraySize, nProc, procID); int* a = new int[arraySize]; |
||
|
|