r87: Upgraded from MPI to MPI++
[ctsim.git] / src / phm2rs.cpp
index 1e158836251c4f5ee1c3405d4420e1c3b7705480..78a9f5faf2905acfa8d19f882dee779a2395d003 100644 (file)
@@ -9,8 +9,11 @@
 **   1984 -- Final DOS version  
 **   1999 -- First UNIX version
 **
-**  $Id: phm2rs.cpp,v 1.1 2000/06/07 02:29:05 kevin Exp $
+**  $Id: phm2rs.cpp,v 1.2 2000/06/07 10:12:05 kevin Exp $
 **  $Log: phm2rs.cpp,v $
+**  Revision 1.2  2000/06/07 10:12:05  kevin
+**  Upgraded from MPI to MPI++
+**
 **  Revision 1.1  2000/06/07 02:29:05  kevin
 **  Initial C++ versions
 **
@@ -89,7 +92,7 @@ static struct option phm2rs_options[] =
 void 
 phm2rs_usage (const char *program)
 {
-#ifdef MPI_CT
+#ifdef HAVE_MPI
 if (mpi_ct.my_rank == 0)
   {
 #endif  
@@ -120,13 +123,13 @@ if (mpi_ct.my_rank == 0)
   fprintf(stdout,"     --debug      Debug mode\n");
   fprintf(stdout,"     --version    Print version\n");
   fprintf(stdout,"     --help       Print this help message\n");
-#ifdef MPI_CT
+#ifdef HAVE_MPI
   }
-  MPI_Abort(mpi_ct.comm, 1);
+  mpi_ct.comm.Abort(1);
 #endif
 }
 
-#ifdef MPI_CT
+#ifdef HAVE_MPI
 void mpi_gather_rs (RAYSUM *rs_global, RAYSUM *rs_local, const int opt_debug);
 #endif
 
@@ -147,7 +150,7 @@ phm2rs_main (const int argc, char *const argv[])
   double opt_rotangle = 1;
   double time_start = 0, time_end = 0;
 
-#ifndef MPI_CT
+#ifndef HAVE_MPI
   time_start = td_current_sec();
 #else
   RAYSUM *rs_local;
@@ -155,19 +158,20 @@ phm2rs_main (const int argc, char *const argv[])
   char **mpi_argv = (char **) argv;
   double mpi_t1 = 0, mpi_t2 = 0, mpi_t, mpi_t_g;
 
-  MPI_Init(&mpi_argc, &mpi_argv);
-  MPI_Comm_dup (MPI_COMM_WORLD, &mpi_ct.comm);
-  MPI_Comm_size(mpi_ct.comm, &mpi_ct.nproc);
-  MPI_Comm_rank(mpi_ct.comm, &mpi_ct.my_rank);
+  MPI::Init (mpi_argc, mpi_argv);
+  mpi_ct.comm = MPI::COMM_WORLD.Dup ();
+  mpi_ct.nproc = mpi_ct.comm.Get_size();
+  mpi_ct.my_rank = mpi_ct.comm.Get_rank();
 
-  if (mpi_ct.nproc > MPI_MAX_PROCESS) {
-    sys_error(ERR_FATAL, "Number of mpi processes (%d) exceeds max processes (%d)", mpi_ct.nproc, MPI_MAX_PROCESS);
-    exit(1);
+  if (mpi_ct.nproc > CT_MPI_MAX_PROCESS) {
+    sys_error(ERR_FATAL, "Number of mpi processes (%d) exceeds max processes (%d)",
+             mpi_ct.nproc, CT_MPI_MAX_PROCESS);
   }
-  time_start = MPI_Wtime();
+
+  time_start = MPI::Wtime();
 #endif
   
-#ifdef MPI_CT
+#ifdef HAVE_MPI
   if (mpi_ct.my_rank == 0) {
 #endif
     strcpy(opt_desc, "");
@@ -189,7 +193,7 @@ phm2rs_main (const int argc, char *const argv[])
        phm = phm_create (opt_phmnum);
        break;
       case O_PHMFILE:
-#ifdef MPI_CT
+#ifdef HAVE_MPI
        if (mpi_ct.my_rank == 0)
          fprintf(stderr, "Can not read phantom from file in MPI mode\n");
        return (1);
@@ -289,20 +293,20 @@ phm2rs_main (const int argc, char *const argv[])
       strncat(str, opt_desc, sizeof(str));
     }
     strncpy(opt_desc, str, sizeof(opt_desc));
-#ifdef MPI_CT
+#ifdef HAVE_MPI
   }
 #endif
 
-#ifdef MPI_CT
-  MPI_Barrier(mpi_ct.comm);
-  MPI_Bcast(&opt_rotangle, 1, MPI_DOUBLE, 0, mpi_ct.comm);
-  MPI_Bcast(&opt_nview, 1, MPI_INT, 0, mpi_ct.comm);
-  MPI_Bcast(&opt_ndet, 1, MPI_INT, 0, mpi_ct.comm);
-  MPI_Bcast(&opt_nray, 1, MPI_INT, 0, mpi_ct.comm);
-  MPI_Bcast(&opt_phmnum, 1, MPI_INT, 0, mpi_ct.comm);
-  MPI_Bcast(&opt_verbose, 1, MPI_INT, 0, mpi_ct.comm);
-  MPI_Bcast(&opt_debug, 1, MPI_INT, 0, mpi_ct.comm);
-  MPI_Bcast(&opt_trace, 1, MPI_INT, 0, mpi_ct.comm);
+#ifdef HAVE_MPI
+  mpi_ct.comm.Barrier ();
+  mpi_ct.comm.Bcast (&opt_rotangle, 1, MPI::DOUBLE, 0);
+  mpi_ct.comm.Bcast (&opt_nview, 1, MPI::INT, 0);
+  mpi_ct.comm.Bcast (&opt_ndet, 1, MPI::INT, 0);
+  mpi_ct.comm.Bcast (&opt_nray, 1, MPI::INT, 0);
+  mpi_ct.comm.Bcast (&opt_phmnum, 1, MPI::INT, 0);
+  mpi_ct.comm.Bcast (&opt_verbose, 1, MPI::INT, 0);
+  mpi_ct.comm.Bcast (&opt_debug, 1, MPI::INT, 0);
+  mpi_ct.comm.Bcast (&opt_trace, 1, MPI::INT, 0);
 
   if (mpi_ct.my_rank > 0 && opt_phmnum >= 0)
     phm = phm_create (opt_phmnum);
@@ -311,7 +315,7 @@ phm2rs_main (const int argc, char *const argv[])
   opt_rotangle *= PI;
   det = detector_create (phm, DETECTOR_PARALLEL, opt_ndet, opt_nview, opt_nray, opt_rotangle);
 
-#ifdef MPI_CT
+#ifdef HAVE_MPI
   mpi_ct_calc_work_units(opt_nview);
   if (mpi_ct.my_rank == 0) {
     rs_global = raysum_create_from_det (opt_outfile, det);
@@ -324,23 +328,23 @@ phm2rs_main (const int argc, char *const argv[])
     printf("rs_local->nview = %d (process %d)\n", rs_local->nview, mpi_ct.my_rank);
 
   if (opt_verbose)
-    mpi_t1 = MPI_Wtime();
+    mpi_t1 = MPI::Wtime();
   raysum_collect (rs_local, det, phm, mpi_ct.start_work_unit[mpi_ct.my_rank], opt_trace, FALSE);
   if (opt_verbose) {
-    mpi_t2 = MPI_Wtime();
+    mpi_t2 = MPI::Wtime();
     mpi_t = mpi_t2 - mpi_t1;
-    MPI_Reduce(&mpi_t, &mpi_t_g, 1, MPI_DOUBLE, MPI_MAX, 0, mpi_ct.comm);
+    mpi_ct.comm.Reduce(&mpi_t, &mpi_t_g, 1, MPI::DOUBLE, MPI::MAX, 0);
     if (mpi_ct.my_rank == 0)
       printf("Time to collect rs = %f secs, Max = %f secs\n", mpi_t, mpi_t_g);
   }
 
   if (opt_verbose)
-    mpi_t1 = MPI_Wtime();
+    mpi_t1 = MPI::Wtime();
   mpi_gather_rs(rs_global, rs_local, opt_debug);
   if (opt_verbose) {
-    mpi_t2 = MPI_Wtime();
+    mpi_t2 = MPI::Wtime();
     mpi_t = mpi_t2 - mpi_t1;
-    MPI_Reduce(&mpi_t, &mpi_t_g, 1, MPI_DOUBLE, MPI_MAX, 0, mpi_ct.comm);
+    mpi_ct.comm.Reduce(&mpi_t, &mpi_t_g, 1, MPI::DOUBLE, MPI::MAX, 0);
     if (mpi_ct.my_rank == 0)
       printf("Time to gather rs = %f secs, Max = %f secs\n", mpi_t, mpi_t_g);
   }
@@ -349,10 +353,10 @@ phm2rs_main (const int argc, char *const argv[])
   raysum_collect (rs_global, det, phm, 0, opt_trace, FALSE);
 #endif
   
-#ifndef MPI_CT
+#ifndef HAVE_MPI
   time_end = td_current_sec();
 #else
-  time_end = MPI_Wtime();
+  time_end = MPI::Wtime();
   if (mpi_ct.my_rank == 0) 
 #endif
     {
@@ -364,7 +368,7 @@ phm2rs_main (const int argc, char *const argv[])
       }
     }
 
-#ifdef MPI_CT
+#ifdef HAVE_MPI
   if (mpi_ct.my_rank == 0) 
 #endif
     {
@@ -386,7 +390,7 @@ phm2rs_main (const int argc, char *const argv[])
  *    Gather's raysums from all processes in rs_local in rs_global in process 0
  */
 
-#ifdef MPI_CT
+#ifdef HAVE_MPI
 void mpi_gather_rs (RAYSUM *rs_global, RAYSUM *rs_local, const int opt_debug)
 {
   int iproc;
@@ -395,9 +399,9 @@ void mpi_gather_rs (RAYSUM *rs_global, RAYSUM *rs_local, const int opt_debug)
 
   end_work_unit = mpi_ct.local_work_units[mpi_ct.my_rank] - 1;
   for (iw = 0; iw <= end_work_unit; iw++) {
-    MPI_Send(&rs_local->view[iw]->view_angle, 1, MPI_DOUBLE, 0, 0, mpi_ct.comm);
-    MPI_Send(&rs_local->view[iw]->ndet, 1, MPI_INT, 0, 0, mpi_ct.comm);
-    MPI_Send(rs_local->view[iw]->detval, rs_local->ndet, MPI_FLOAT, 0, 0, mpi_ct.comm);
+    mpi_ct.comm.Send(&rs_local->view[iw]->view_angle, 1, MPI::DOUBLE, 0, 0);
+    mpi_ct.comm.Send(&rs_local->view[iw]->ndet, 1, MPI::INT, 0, 0);
+    mpi_ct.comm.Send(rs_local->view[iw]->detval, rs_local->ndet, MPI::FLOAT, 0, 0);
   }
 
   if (mpi_ct.my_rank == 0) {
@@ -410,11 +414,11 @@ void mpi_gather_rs (RAYSUM *rs_global, RAYSUM *rs_local, const int opt_debug)
        fprintf(stdout, "Recv rs data from process %d\n", iproc);
 
       for (iw = mpi_ct.start_work_unit[iproc]; iw <= end_work_unit; iw++) {
-       MPI_Status status;
+       MPI::Status status;
 
-       MPI_Recv(&rs_global->view[iw]->view_angle, 1, MPI_DOUBLE, iproc, 0, mpi_ct.comm, &status);
-       MPI_Recv(&rs_global->view[iw]->ndet, 1, MPI_INT, iproc, 0, mpi_ct.comm, &status);
-       MPI_Recv(rs_global->view[iw]->detval, rs_global->ndet, MPI_FLOAT, iproc, 0, mpi_ct.comm, &status);
+       mpi_ct.comm.Recv(&rs_global->view[iw]->view_angle, 1, MPI::DOUBLE, iproc, 0, status);
+       mpi_ct.comm.Recv(&rs_global->view[iw]->ndet, 1, MPI::INT, iproc, 0, status);
+       mpi_ct.comm.Recv(rs_global->view[iw]->detval, rs_global->ndet, MPI::FLOAT, iproc, 0, status);
       }
     }
   }