Newsgroups: comp.parallel.pvm From: Clark Dorman Subject: Re: message queue Organization: PSINet Date: 17 Mar 1998 16:08:21 -0500 Message-ID: Mariusz Nowostawski writes: > Dear readers > > I have one (simple) question and I would appreciate if somebody could > tell me wether I am right or wrong. > > Let say I have 3 processes A, B and C, with tids A_ B_ and C_TID > respectively. > > A: .... > pvm_initsend(PvmDataDefault); > pvm_send(C_TID, A_MSGTAG); > > B: .... > pvm_initsend(PvmDataDefault); > pvm_send(C_TID, B_MSGTAG); > > C: ... > pvm_recv(A_TID, A_MSGTAG); > pvm_recv(B_TID, B_MSGTAG); > > > if A sends his message first, everything is fine, but if C sends its > message first, B is blocked. Yes? B doesn't get blocked because it is just sending. I believe that you wanted to write: } if A sends his message first, everything is fine, but if B sends its } message first, C is blocked. Yes? And, no, C does _not_ get blocked. The following programs show this. The first is test_order.cc. It creates two child processes, A and B. It starts B first, then A. Each is sent a message tag to use and immediately send them. A and B are the second program, test_order_slave.cc and differ by their passed arguments. The results are: elmo:toolkit (3:48pm) 46% test_order.exe child id is 262146 child id is 262147 tid_A 262147 msgtagA 2 tid_B 262146 msgtagB 3 Terminated elmo:toolkit (3:51pm) 47% I am guessing that the way that pvm queues things is that if you are looking for any message, it takes the one off the top (earliest arriving FIFO). If you want a particular message, it looks in the queue for a message that satisfies the requirements, even if it is way down in the queue. Just for fun, you can launch lots and lots of B's, (put a for loop around the 'tidB = start_child( msgtagB);' line) and it still works. //---------------------------------------------------------------------- // test_order.cc //---------------------------------------------------------------------- #include #include // Used because pvm uses FILE #include // for sleep() #include "pvm3.h" int start_child( int msgtag ); main() { pvm_start_pvmd( 0, NULL, 0); int tidA, tidB; int msgtagA = 2; int msgtagB = 3; // Start child B, then child A. tidB = start_child( msgtagB ) ; sleep ( 4 ) ; tidA = start_child( msgtagA ) ; // Force a receive from A, then from B int recv_A = pvm_recv( tidA, msgtagA ); cout << " tid_A " << tidA << " msgtagA " << msgtagA << endl; sleep( 4 ); int recv_B = pvm_recv( tidB, msgtagB ); cout << " tid_B " << tidB << " msgtagB " << msgtagB << endl; pvm_halt(); } int start_child( int msgtag_to_use ) { int child_tid; int num_started ; char *argv[1]; argv[0] = new char[ 10 ]; sprintf( argv[0], "%d", msgtag_to_use); int nums = pvm_spawn( "/home/dorman/gann/src/toolkit/test_order_slave.exe", argv , 0, NULL, 1, &child_tid ); cout << " child id is " << child_tid << endl; return child_tid; } //--- end of test_order.cc ---------------------------------------------------------- //---------------------------------------------------------------------- // test_order_slave.cc //---------------------------------------------------------------------- #include "pvm3.h" #include main( int argc, char *argv[]) { int msg_type = atoi( argv[1] ); pvm_initsend( PvmDataDefault ); pvm_send( pvm_parent(), msg_type ); } //--- end of test_order_slave.cc -----------------------------------------------