Discussion:
Communication among threads on different processes
(too old to reply)
l***@yahoo.com
2008-08-29 06:09:13 UTC
Permalink
Hi all,
I'm trying to write a program that combines MPI and OpenMP, that
basically does the following:
I have 2 threads running in each process, one does some work, the
other waits for a change in a linked list that the first thread uses.
When there is a change in the linked list, this thread will tell other
such threads in the other processes, so that they can update their
linked list.

I guess what I'm really after is whether it is possible to have one
thread in one process communicate with another thread in another
process, when certain conditions are met.

If this is not possible, I'm wondering if using MPI_Isend and
MPI_Irecv can achieve the same goal, that is, instead of periodically
polling each process on whether the list has changed (which is what
I'm doing now using MPI_Send and MPI_Recv), have the process with the
changed list tell the other processes only when there is a change. If
there is no change, the processes will continue doing their work using
the existing list.

Thank you.

Regards,
Rayne
Michael Hofmann
2008-08-29 09:31:04 UTC
Permalink
Post by l***@yahoo.com
Hi all,
I'm trying to write a program that combines MPI and OpenMP, that
I have 2 threads running in each process, one does some work, the
other waits for a change in a linked list that the first thread uses.
When there is a change in the linked list, this thread will tell other
such threads in the other processes, so that they can update their
linked list.
I guess what I'm really after is whether it is possible to have one
thread in one process communicate with another thread in another
process, when certain conditions are met.
MPI and threads can work together. MPI-2 provides a special init routine
(MPI_Init_thread), to signal that you want to use MPI in a multithreaded
environment. There you can chose between different levels of thread
support (http://www.mpi-forum.org/docs/mpi-20-html/node165.htm). If only
one thread in each process uses MPI (as you mentioned for your program),
the desired level is called MPI_THREAD_FUNNELED.
Post by l***@yahoo.com
If this is not possible, I'm wondering if using MPI_Isend and
MPI_Irecv can achieve the same goal, that is, instead of periodically
polling each process on whether the list has changed (which is what
I'm doing now using MPI_Send and MPI_Recv), have the process with the
changed list tell the other processes only when there is a change. If
there is no change, the processes will continue doing their work using
the existing list.
Yes, I think that is a more appropriate solution. If there is some kind of
"work loop", you can check for incoming messages in each iteration. For
example
(1) with a call MPI_Iprobe (+ MPI_Recv if a message is available) or
(2) by executing MPI_Irecv (source = MPI_ANY_SOURCE) in advance and test
whether the request is completed or not with MPI_Test. After receiving a
message, you have to execute MPI_Irecv again and test the new request. At
the end of the loop/program, the last pending MPI_Irecv can be canceled
with MPI_Cancel.


Michael
David Cronk
2008-08-29 18:16:35 UTC
Permalink
This is going to depend on your MPI implementation and, possibly, how
your MPI was configured (i.e. Open MPI can be built with or without
thread support).

Take a look at MPI_INIT_THREAD for information on this.

http://www.mpi-forum.org/docs/mpi-20-html/node165.htm

Hope this helps.

Dave.
Post by l***@yahoo.com
Hi all,
I'm trying to write a program that combines MPI and OpenMP, that
I have 2 threads running in each process, one does some work, the
other waits for a change in a linked list that the first thread uses.
When there is a change in the linked list, this thread will tell other
such threads in the other processes, so that they can update their
linked list.
I guess what I'm really after is whether it is possible to have one
thread in one process communicate with another thread in another
process, when certain conditions are met.
If this is not possible, I'm wondering if using MPI_Isend and
MPI_Irecv can achieve the same goal, that is, instead of periodically
polling each process on whether the list has changed (which is what
I'm doing now using MPI_Send and MPI_Recv), have the process with the
changed list tell the other processes only when there is a change. If
there is no change, the processes will continue doing their work using
the existing list.
Thank you.
Regards,
Rayne
--
Dr. David Cronk, Ph.D. phone: (865) 974-3735
Research Director fax: (865) 974-8296
Innovative Computing Lab http://www.cs.utk.edu/~cronk
University of Tennessee, Knoxville
l***@yahoo.com
2008-08-31 13:13:03 UTC
Permalink
Thank you for all the replies, I will look into MPI_Init_thread.

I have 2 more questions.

Say I have a quad-core computer. If I run a MPI program locally using
"-np 4", will the 4 instances of the program automatically run on each
of the 4 cores, i.e. one instance per core? Or should I have "slots =
4" in the hostfile and run the program with "-np 1"? Or do I not have
any control over whether all 4 cores will be utilized or not?

Also, a question that is somehow related to the above question: if
using a quad-core computer leads to the one-instance-per-core
scenario, will running a MPI program on a quad-core computer be
generally faster than running the same program on 4 single-core
computers, since the physical distance between the cores/memory is
much shorter in the quad-core system than the single-core network,
which might reduce communication costs?

Thank you.

Regards,
Rayne

Loading...