Executing nodes of a graph (as tasks) using MPI
I'm learning about MPI, but I have some doubts about its correct use. I'm using MPJ Express.
First of all, I compute a acyclic directed graph whose nodes represent tasks. The incoming arcs of a node represent its inputs and the outgoi开发者_如何学运维ng arcs its outputs. The computation of these tasks will be performed in a cluster. For now, I am running the program in my dual-core machine.
This is what I did:
-I calculated the indexes each of my nodes will have as a MPI process (the RANK). Then, I use Isend to send the information each node needs: the task it has to perform, and the ranks of its output nodes. Now, when a process finishes its computation, it sends the values calculated to processes identified by the ranks it received at first. Each process waits for input values using Irecv.
It worked well, but the whole index (RANK) pre-calculation does not seem right to me. I thought this could be a common scenario, but I haven't found anything useful.
What do you think? Is it right to somehow calculate the rank each process will have and tell each process the ranks of its outputs and inputs processes?
-I'm doing the execution with -np 10, now:
What does the 10 means if I have 2 cores?
I think I should send each task to one of this 10 processes. What happens if I have more tasks than processes?
If I have less task than process, the execution goes well but the unused processes stay alive waiting for a message. How should I kill them?
I hope I explained my doubts well.
Thank you very much for your answers and advices.
Edited: A little explanation about how I get the ranks each task will have as a process.
What I do is very simple (and maybe silly): suppose I have a list with all my nodes [v1,v2,v3] with indexes 0,1,3 respectively.
I know that the process with rank 0 will be the master process, which will send the task v1 to process with rank 1, v2 to process with rank 2, and so on. Now, I know that that rank(v1)=index(v1)+1, and the same for the rest of the nodes (this was the ranks pre-calculation).
Then the master iterates over the list [v1,v2,v3] and for each node, get the ranks of its predecessors and successor based on the graph. For example, if the graph is v1->v3->v2, the information sent to process with rank 3 is: task:v3, predecessors: (process with rank 1). successor: (process with rank 2 ).
精彩评论