Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
- corrected mvmul.c to avoid warnings
authorgenaud <genaud@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 26 Jun 2009 10:57:42 +0000 (10:57 +0000)
committergenaud <genaud@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 26 Jun 2009 10:57:42 +0000 (10:57 +0000)
- added MPI_Wtime in bcast example.

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6365 48e7efb5-ca39-0410-a469-dd3cf9ba447f

examples/smpi/bcast.c
examples/smpi/mvmul.c

index 002061c..27b58ee 100644 (file)
@@ -1,25 +1,27 @@
 #include <stdio.h>
 #include <mpi.h>
 
 #include <stdio.h>
 #include <mpi.h>
 
-#define INIT_VALUE 3
-#define TARGET_VALUE 42
-
 int main (int argc, char **argv) {
   int size, rank;
 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);
   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) {
   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);
   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;
 }
   MPI_Finalize();
   return 0;
 }
index aa32e30..68f09ab 100644 (file)
@@ -168,7 +168,7 @@ int main(int argc, char* argv[]) {
         printf("prog: blocking, i: %d ", current_iteration);
 
         if (i == N) {
         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,
               parallel_usecs,
               sequential_usecs,
               (double)sequential_usecs / (double)parallel_usecs,
@@ -196,10 +196,10 @@ int main(int argc, char* argv[]) {
   if(0 == rank) {
     printf("prog: blocking, ");
     if(0 < successful_iterations) {
   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,
           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));
           (double)sequential_usecs_total / (double)parallel_usecs_total,
           size,
           (double)sequential_usecs_total / ((double)parallel_usecs_total * (double)size));