Reputation: 1606
My understanding of how MPI allocates memory for shared use between different processes is that you need initialize them before MPI_Init.
typedef struct Car {
// struct
} Car;
int main
(int argc, char *argv[])
{
// Shared variables
int size, rank;
Car cars[20];
MPI_Init(&argc, &argv);
MPI_Comm_Size(MPI_COMM_WORLD, &size);
MPI_Comm_Rank(MPI_COMM_WORLD, &rank);
// Node logic
}
Is this correct? If so, how would I handle a case where if I wanted as many cars as the number of nodes?
Upvotes: 1
Views: 78
Reputation: 78364
MPI does not allocate memory for shared use across processes. In MPI each process is responsible for its own memory management. If you want to allocate an array of size size
on each process then you have to allocate the memory after the call to MPI_comm_size
. After that you either initialise the values on each process individually, or you initialise them on one process and exchange messages to update the other processes.
But you still don't have shared memory. You have an array of the same name on each process and you, the programer, are writing code to ensure that each process has the same view of the values in that array.
Upvotes: 2