From: Marc L. Smith (mlsmith_at_colby_dot_edu)
Date: Fri Nov 25 2005 - 12:27:50 PST
Hi Eric, Welcome to the nondeterministic world of concurrency. :-) You should no longer expect the order of your print statements (observable events) to reflect the order of execution across a distributed computation. The order of events from a single given thread *should* reflect the order of events for that thread (though I wouldn't count on this), but the interleaving of such events across all threads is nondeterministic. Furthermore, attempts to peek inside the computational box (e.g., by adding printf's, fflush's, barriers, etc.) are reminiscent of Schr�dinger's cat, in that they have an effect on the computation itself! :-) There has been earlier discussion on this list regarding such issues, their causes, and the use of real debuggers (instead of just printf's). Best, Marc -- Marc L. Smith Assistant Professor of Computer Science Colby College 5853 Mayflower Hill Waterville, Maine 04901-8858 office: 207.872.3672 fax: 207.872.3801 mlsmith_at_colby_dot_edu http://www.cs.colby.edu/~mlsmith/ Quoting Eric Frederich <eric.frederich_at_gmail_dot_com>: > Hello, and happy thanksgiving. > > I went home to visit my family and forgot to pack my UPC book that my > professor let me borrow. Anyway, I googled for upc_barrier and came > across an example. I get results which seem unexpected. Even if I add > fflush(stdout) after the printf statements I still get the hello's and > goodbye's mixed together. > Does this seem right? > > Thanks, > ~Eric > > This is my output... > > UPCR: UPC thread 1 of 2 on penguin27 (process 1 of 2, pid=11019) > UPCR: UPC thread 0 of 2 on myth (process 0 of 2, pid=14774) > Hello: Process 1 of 2 > Goodbye: Process 1 of 2 > Hello: Process 0 of 2 > Goodbye: Process 0 of 2 > > This is the code.... > > http://www.cs.mtu.edu/~merk/public/SC2005_examples/upc_barrier.c > > // Hello world in UPC > // Intro: upc_barrier > > #include <stdio.h> > #include <upc.h> > > main () > { > int t; > for( t=0; t<THREADS; t++ ) { > upc_barrier(1); > if( t == MYTHREAD ) > printf ("Hello: Process %d of %d\n", MYTHREAD, THREADS); > } > // uncomment this a see what happens > //if(MYTHREAD==0){upc_barrier(3);} > > for( t=0; t<THREADS; t++ ) { > upc_barrier(2); > if( t == MYTHREAD ) > printf ("Goodbye: Process %d of %d\n", MYTHREAD, THREADS); > } > } > > > > > -- > ------------------------ > Eric L. Frederich >