#include <stdio.h>
#include <mpi.h>
-#define INIT_VALUE 3
-#define TARGET_VALUE 42
-
int main (int argc, char **argv) {
int size, rank;
- int value = INIT_VALUE;
+ int value = 3;
+ double start_timer;
+
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+
+ start_timer = MPI_Wtime();
+
if (0 == rank) {
- value = TARGET_VALUE;
+ value = 17;
}
- fprintf(stderr,"node %d has value %d before broadcast\n", rank, value);
+ printf("node %d has value %d\n", rank, value);
MPI_Bcast(&value, 1, MPI_INT, 0, MPI_COMM_WORLD);
- fprintf(stderr,"node %d has value %d after broadcast\n", rank, value);
- if (value != TARGET_VALUE) {
- fprintf(stderr,"node %d don't have the target value after broadcast!!\n", rank);
- exit(1);
- }
+ printf("node %d has value %d\n", rank, value);
+
+ MPI_Barrier( MPI_COMM_WORLD );
+ if ( 0 == rank)
+ printf("Elapsed time on rank %d: %lf s\n", rank, MPI_Wtime()-start_timer);
MPI_Finalize();
return 0;
}
printf("prog: blocking, i: %d ", current_iteration);
if (i == N) {
- printf("ptime: %d us, stime: %d us, speedup: %.3f, nodes: %d, efficiency: %.3f\n",
+ printf("ptime: %ld us, stime: %ld us, speedup: %.3f, nodes: %d, efficiency: %.3f\n",
parallel_usecs,
sequential_usecs,
(double)sequential_usecs / (double)parallel_usecs,
if(0 == rank) {
printf("prog: blocking, ");
if(0 < successful_iterations) {
- printf("iterations: %d, avg. ptime: %d us, avg. stime: %d us, avg. speedup: %.3f, nodes: %d, avg. efficiency: %.3f\n",
+ printf("iterations: %d, avg. ptime: %.3f us, avg. stime: %.3f us, avg. speedup: %.3f, nodes: %d, avg. efficiency: %.3f\n",
successful_iterations,
- parallel_usecs_total / successful_iterations,
- sequential_usecs_total / successful_iterations,
+ (double) parallel_usecs_total / (double) successful_iterations,
+ (double) sequential_usecs_total / (double) successful_iterations,
(double)sequential_usecs_total / (double)parallel_usecs_total,
size,
(double)sequential_usecs_total / ((double)parallel_usecs_total * (double)size));