6 /* # define MPI_Wtime PMPI_Wtime */
9 * This program tests that if MPI_WTIME_IS_GLOBAL is set, the timer
10 * IS in fact global. We have some suspicions about certain vendor systems
13 int CheckTime( void );
16 * Check time tests that the timers are synchronized
21 double wtick, t1, t2, t3, delta_t;
25 double max_diff = 0.0;
27 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
28 MPI_Comm_size( MPI_COMM_WORLD, &size );
33 printf( "Wtick is %lf\n", wtick );
36 for (i=1; i<size; i++) {
37 MPI_Send( MPI_BOTTOM, 0, MPI_INT, i, 0, MPI_COMM_WORLD );
38 MPI_Recv( MPI_BOTTOM, 0, MPI_INT, i, 1, MPI_COMM_WORLD,
41 MPI_Send( &t1, 1, MPI_DOUBLE, i, 2, MPI_COMM_WORLD );
42 MPI_Recv( &t2, 1, MPI_DOUBLE, i, 3, MPI_COMM_WORLD, &status );
45 printf( "Process %d(%f) to 0(%f): diff= %f\n",
46 i, 0.5 * (t1 + t3), t2, 0.5*(t1+t3)-t2 );
48 delta_t = fabs( 0.5 * (t1 + t3) - t2 );
49 if( delta_t > (t3 - t1 + wtick)) {
51 printf( "Process %d has %f; Process 0 has %f\n",
52 i, t2, 0.5 * (t1 + t3) );
54 if (delta_t > max_diff) max_diff = delta_t;
57 printf( "delta_t = %lf\n", delta_t );
59 /* Release all process for the next pass */
60 for (i=1; i<size; i++) {
61 MPI_Send( MPI_BOTTOM, 0, MPI_INT, i, 3, MPI_COMM_WORLD );
67 MPI_Recv( MPI_BOTTOM, 0, MPI_INT, 0, 0, MPI_COMM_WORLD, &status );
68 MPI_Send( MPI_BOTTOM, 0, MPI_INT, 0, 1, MPI_COMM_WORLD );
69 /* Insure a symmetric transfer */
70 MPI_Recv( &t1, 1, MPI_DOUBLE, 0, 2, MPI_COMM_WORLD, &status );
72 MPI_Send( &t2, 1, MPI_DOUBLE, 0, 3, MPI_COMM_WORLD );
73 MPI_Recv( MPI_BOTTOM, 0, MPI_INT, 0, 3, MPI_COMM_WORLD, &status );
79 int main( int argc, char **argv )
88 MPI_Init( &argc, &argv );
89 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
91 MPI_Attr_get( MPI_COMM_WORLD, MPI_WTIME_IS_GLOBAL, &v, &flag );
93 if (v) vval = *(int*)v; else vval = 0;
94 printf( "WTIME flag = %d; val = %d\n", flag, vval );
97 /* Wtime need not be set */
99 if (vval < 0 || vval > 1) {
101 fprintf( stderr, "Invalid value for WTIME_IS_GLOBAL (got %d)\n",
106 /* Wtime is global is true. Check it */
108 printf( "WTIME_IS_GLOBAL\n" );
112 /* Wait for 10 seconds */
114 while (MPI_Wtime() - t1 < 10.0) ;
120 printf( "Errors in MPI_WTIME_IS_GLOBAL\n" );
123 printf( " No Errors\n" );
126 /* The SGI implementation of MPI sometimes fails to flush stdout
127 properly. This fflush will work around that bug. */
128 /* fflush( stdout ); */