From 7438260c07e4f3d71c7f43669678c3a912682e4c Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Wed, 7 Jun 2000 10:12:09 +0000 Subject: [PATCH] r87: Upgraded from MPI to MPI++ --- include/ct.h | 9 ++-- include/imagefile.h | 15 +++--- include/ir.h | 42 ++++++++-------- src/Makefile.am | 7 +-- src/Makefile.nt | 107 ++++++++++++++++++++-------------------- src/ctrec.cpp | 117 +++++++++++++++++++++++--------------------- src/phm2if.cpp | 85 ++++++++++++++++---------------- src/phm2rs.cpp | 94 ++++++++++++++++++----------------- 8 files changed, 246 insertions(+), 230 deletions(-) diff --git a/include/ct.h b/include/ct.h index 9aa3639..d43353d 100644 --- a/include/ct.h +++ b/include/ct.h @@ -2,8 +2,11 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ct.h,v 1.10 2000/06/07 07:43:39 kevin Exp $ +** $Id: ct.h,v 1.11 2000/06/07 10:12:09 kevin Exp $ ** $Log: ct.h,v $ +** Revision 1.11 2000/06/07 10:12:09 kevin +** Upgraded from MPI to MPI++ +** ** Revision 1.10 2000/06/07 07:43:39 kevin ** *** empty log message *** ** @@ -141,8 +144,8 @@ #include /* Standard ints on Linux */ #endif -#ifdef MPI_CT -#include "mpi.h" +#ifdef HAVE_MPI +#include "mpi++.h" #endif #include "kstddef.h" diff --git a/include/imagefile.h b/include/imagefile.h index 4660a92..3c1bb9a 100644 --- a/include/imagefile.h +++ b/include/imagefile.h @@ -3,6 +3,8 @@ #include #include "kstddef.h" +#include +#include #include using namespace std; @@ -633,20 +635,21 @@ public: kuint32 ny(void) const { return adf.ny(); } -#ifdef MPI_CT - MPI_Datatype getMPIDataType (void) const - { return MPI_FLOAT; } +#ifdef HAVE_MPI + MPI::Datatype getMPIDataType (void) const + { return MPI::FLOAT; } #endif }; + class F64Image { public: Array2dFile adf; -#ifdef MPI_CT - MPI_Datatype getMPIDataType (void) const - { return MPI_DOUBLE; } +#ifdef HAVE_MPI + MPI::Datatype getMPIDataType (void) const + { return MPI::DOUBLE; } #endif F64Image (const char* const fname, unsigned int nx, unsigned int ny) : adf (fname, nx, ny) diff --git a/include/ir.h b/include/ir.h index 7da06ff..e1661db 100644 --- a/include/ir.h +++ b/include/ir.h @@ -2,8 +2,11 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ir.h,v 1.22 2000/06/07 07:43:39 kevin Exp $ +** $Id: ir.h,v 1.23 2000/06/07 10:12:09 kevin Exp $ ** $Log: ir.h,v $ +** Revision 1.23 2000/06/07 10:12:09 kevin +** Upgraded from MPI to MPI++ +** ** Revision 1.22 2000/06/07 07:43:39 kevin ** *** empty log message *** ** @@ -352,17 +355,17 @@ const static int RAYSUM_TRACE_ROW_ATTEN=18; extern "C" { #endif /* __cplusplus */ -#ifdef MPI_CT -#define MPI_MAX_PROCESS 128 +#ifdef HAVE_MPI +#define CT_MPI_MAX_PROCESS 128 struct mpi_ct_st { int my_rank; int nproc; int base_local_work_units; int remainder_work_units; - int local_work_units[MPI_MAX_PROCESS]; - int start_work_unit[MPI_MAX_PROCESS]; - MPI_Comm comm; + int local_work_units [CT_MPI_MAX_PROCESS]; + int start_work_unit [CT_MPI_MAX_PROCESS]; + MPI::Intracomm comm; }; extern struct mpi_ct_st mpi_ct; @@ -370,25 +373,22 @@ void mpi_ct_calc_work_units(const unsigned int global_work_units); #endif -/* bspline.c */ -int bspline(int samples, int zoom_factor, int spline_order, double input[], double output[]); - /* convolve.c */ -double convolve(const double f1[], const double f2[], const double dx, const int n, const int np, const FunctionSymmetry func_type); -double convolve_both(const double f1[], const double f2[], const double dx, const int n, const int np); +double convolve (const double f1[], const double f2[], const double dx, const int n, const int np, const FunctionSymmetry func_type); +double convolve_both (const double f1[], const double f2[], const double dx, const int n, const int np); /* dialogs.c */ -int phm_add_pelm_kb(PHANTOM *phm); -PHANTOM *phm_select(void); -int interpolation_select(void); -int filter_select(double *filter_param); +int phm_add_pelm_kb (PHANTOM *phm); +PHANTOM *phm_select (void); +int interpolation_select (void); +int filter_select (double *filter_param); /* filter.c */ -double *filter_generate(const FilterType filt_type, double bw, double xmin, double xmax, int n, double param, const DomainType domain, int numint); -double filter_spatial_response_calc(int filt_type, double x, double bw, double param, int n); -double filter_spatial_response_analytic(int filt_type, double x, double bw, double param); -double filter_frequency_response(int filt_type, double u, double bw, double param); -double sinc(double x, double mult); +double *filter_generate (const FilterType filt_type, double bw, double xmin, double xmax, int n, double param, const DomainType domain, int numint); +double filter_spatial_response_calc (int filt_type, double x, double bw, double param, int n); +double filter_spatial_response_analytic (int filt_type, double x, double bw, double param); +double filter_frequency_response (int filt_type, double u, double bw, double param); +double sinc (double x, double mult); double integral_abscos(double u, double w); /* options.c */ @@ -439,7 +439,7 @@ int pelm_clip_line (const PELM *pelm, double *x1, double *y1, double *x2, double void raysum_trace_show_param (const char *label, const char *fmt, int row, int color, ...); /* scanner.c */ -DETECTOR *detector_create(const PHANTOM *phm, int geometry, int ndet, int nview, int nsample, const double rot_anglen); +DETECTOR *detector_create(const PHANTOM *phm, const ScannerGeometry geometry, int ndet, int nview, int nsample, const double rot_anglen); void detector_free(DETECTOR *det); /* rayio.c */ diff --git a/src/Makefile.am b/src/Makefile.am index ae39938..61ef42b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -32,15 +32,16 @@ phm2rs_lam_LDADD=@ctlamlibs@ if USE_LAM CC_LAM = $(lamdir)/bin/balky +LAM_EXTRA_SRC = ../libir/mpi_ct.cpp ctrec-lam: ctrec.cpp - $(CC_LAM) @DEFS@ $(CFLAGS) $(INCLUDES) -DMPI_CT ctrec.cpp -o ctrec-lam $(LDFLAGS) @ctlamlibs@ + $(CC_LAM) @DEFS@ $(CFLAGS) $(INCLUDES) -DHAVE_MPI ctrec.cpp -o ctrec-lam $(LDFLAGS) $(LAM_EXTRA_SRC) @ctlibs@ phm2rs-lam: phm2rs.cpp - $(CC_LAM) @DEFS@ $(CFLAGS) $(INCLUDES) -DMPI_CT phm2rs.cpp -o phm2rs-lam $(LDFLAGS) @ctlamlibs@ + $(CC_LAM) @DEFS@ $(CFLAGS) $(INCLUDES) -DHAVE_MPI phm2rs.cpp -o phm2rs-lam $(LDFLAGS) $(LAM_EXTRA_SRC) @ctlibs@ phm2if-lam: phm2if.cpp - $(CC_LAM) @DEFS@ $(CFLAGS) $(INCLUDES) -DMPI_CT phm2if.cpp -o phm2if-lam $(LDFLAGS) @ctlamlibs@ + $(CC_LAM) @DEFS@ $(CFLAGS) $(INCLUDES) -DHAVE_MPI phm2if.cpp -o phm2if-lam $(LDFLAGS) $(LAM_EXTRA_SRC) @ctlibs@ endif diff --git a/src/Makefile.nt b/src/Makefile.nt index cbfe390..8237a41 100644 --- a/src/Makefile.nt +++ b/src/Makefile.nt @@ -1,54 +1,53 @@ -# Makefile for libk - -!include - -CC=cl -LD=link -CFLAGS=-O -nologo -I..\include -I..\getopt -DHAVE_GETOPT_H -LDFLAGS=..\getopt\getopt.lib ..\libkmath\libkmath.lib ..\libcio\libcio.lib ..\libgraph\libgraph.lib ..\libezplot\libezplot.lib ..\libir\libir.lib ..\libk\libk.lib -O=.obj - -# variables -OBJ1 = ctrec$(O) phm2rs$(O) phm2sdf$(O) rs2sdf$(O) sdf-1$(O) sdf-2$(O) sdf2img$(O) sdfinfo$(O) - -all: ctrec.exe phm2rs.exe phm2sdf.exe rs2sdf.exe sdf-1.exe sdf-2.exe sdf2img.exe sdfinfo.exe - -.obj: .c - $(CC) -c $(cvarsdll) $(CFLAGS) $*.c - - -.obj: .cpp - $(CC) -c $(cvarsdll) $(CFLAGS) $*.cpp - - -ctrec.exe: ctrec.obj - link ctrec.obj $(LDFLAGS) - -phm2rs.exe: phm2rs.obj - link phm2rs.obj $(LDFLAGS) - -phm2sdf.exe: phm2sdf.obj - link phm2sdf.obj $(LDFLAGS) - -rs2sdf.exe: rs2sdf.obj - link rs2sdf.obj $(LDFLAGS) - -sdf-1.exe: sdf-1.obj - link sdf-1.obj $(LDFLAGS) - -sdf-2.exe: sdf-2.obj - link sdf-2.obj $(LDFLAGS) - -sdfinfo.exe: sdfinfo.obj - link sdfinfo.obj $(LDFLAGS) - -sdf2img.exe: sdf2img.obj - link sdf2img.obj $(LDFLAGS) - -clean: - echo dummy > a.obj - echo dummy > a.exe - echo dummy > a.lib - del *.obj - del *.exe - del *.lib +# Makefile for libk + +!include + +CC=cl +LD=link +CFLAGS=-O -nologo -I..\include -I..\getopt -DHAVE_GETOPT_H +LDFLAGS=..\getopt\getopt.lib ..\libkmath\libkmath.lib ..\libcio\libcio.lib ..\libgraph\libgraph.lib ..\libezplot\libezplot.lib ..\libir\libir.lib ..\libk\libk.lib +O=.obj + +# variables +OBJ1 = ctrec$(O) phm2rs$(O) phm2if$(O) rs2if$(O) if-1$(O) if-2$(O) if2img$(O) ifinfo$(O) + +all: ctrec.exe phm2rs.exe phm2if.exe rs2if.exe if-1.exe if-2.exe if2img.exe ifinfo.exe + +.obj: .c + $(CC) -c $(cvarsdll) $(CFLAGS) $*.c + +.obj: .cpp + $(CC) -c $(cvarsdll) $(CFLAGS) $*.cpp + + +ctrec.exe: ctrec.obj + link ctrec.obj $(LDFLAGS) + +phm2rs.exe: phm2rs.obj + link phm2rs.obj $(LDFLAGS) + +phm2if.exe: phm2if.obj + link phm2if.obj $(LDFLAGS) + +rs2if.exe: rs2if.obj + link rs2if.obj $(LDFLAGS) + +if-1.exe: if-1.obj + link if-1.obj $(LDFLAGS) + +if-2.exe: if-2.obj + link if-2.obj $(LDFLAGS) + +ifinfo.exe: ifinfo.obj + link ifinfo.obj $(LDFLAGS) + +if2img.exe: if2img.obj + link if2img.obj $(LDFLAGS) + +clean: + echo dummy > a.obj + echo dummy > a.exe + echo dummy > a.lib + del *.obj + del *.exe + del *.lib diff --git a/src/ctrec.cpp b/src/ctrec.cpp index a7b8ee5..6ed8bd9 100644 --- a/src/ctrec.cpp +++ b/src/ctrec.cpp @@ -2,8 +2,11 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ctrec.cpp,v 1.2 2000/06/07 07:43:19 kevin Exp $ +** $Id: ctrec.cpp,v 1.3 2000/06/07 10:12:05 kevin Exp $ ** $Log: ctrec.cpp,v $ +** Revision 1.3 2000/06/07 10:12:05 kevin +** Upgraded from MPI to MPI++ +** ** Revision 1.2 2000/06/07 07:43:19 kevin ** Converted to IF data files and C++ ** @@ -141,7 +144,7 @@ ctrec_usage (const char *program) } -#ifdef MPI_CT +#ifdef HAVE_MPI static void mpi_scatter_rs (RAYSUM *rs_global, RAYSUM *rs_local, const int debug); #endif @@ -166,7 +169,7 @@ ctrec_main (const int argc, char *const argv[]) int opt_interp_param = 1; BackprojType opt_backproj = O_BPROJ_DIFF2; int nx, ny; -#ifdef MPI_CT +#ifdef HAVE_MPI ImageFile *im_local; RAYSUM *rs_local; int mpi_argc = argc; @@ -175,25 +178,25 @@ ctrec_main (const int argc, char *const argv[]) double mpi_detinc, mpi_rotinc, mpi_phmlen; double mpi_t1, mpi_t2, 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) { + if (mpi_ct.nproc > CT_MPI_MAX_PROCESS) { sys_error(ERR_FATAL, "Number of mpi processes (%d) exceeds max processes (%d)", - mpi_ct.nproc, MPI_MAX_PROCESS); + mpi_ct.nproc, CT_MPI_MAX_PROCESS); exit(1); } #endif -#ifdef MPI_CT - time_start = MPI_Wtime(); +#ifdef HAVE_MPI + time_start = MPI::Wtime(); #else time_start = td_current_sec(); #endif -#ifdef MPI_CT +#ifdef HAVE_MPI if (mpi_ct.my_rank == 0) { #endif while (1) { @@ -281,11 +284,11 @@ ctrec_main (const int argc, char *const argv[]) if (opt_verbose) fprintf (stdout, "%s\n", remark); -#ifdef MPI_CT +#ifdef HAVE_MPI } #endif -#ifdef MPI_CT +#ifdef HAVE_MPI if (mpi_ct.my_rank == 0) { rs_global = raysum_open (rs_name); raysum_read (rs_global); @@ -299,26 +302,26 @@ ctrec_main (const int argc, char *const argv[]) mpi_rotinc = rs_global->rot_inc; } - mpi_t1 = MPI_Wtime(); - 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); - MPI_Bcast(&opt_filter, 1, MPI_INT, 0, mpi_ct.comm); - MPI_Bcast(&opt_interp, 1, MPI_INT, 0, mpi_ct.comm); - MPI_Bcast(&opt_filter_param, 1, MPI_DOUBLE, 0, mpi_ct.comm); - MPI_Bcast(&opt_interp_param, 1, MPI_INT, 0, mpi_ct.comm); - MPI_Bcast(&opt_backproj, 1, MPI_INT, 0, mpi_ct.comm); - MPI_Bcast(&mpi_ndet, 1, MPI_INT, 0, mpi_ct.comm); - MPI_Bcast(&mpi_nview, 1, MPI_INT, 0, mpi_ct.comm); - MPI_Bcast(&mpi_detinc, 1, MPI_DOUBLE, 0, mpi_ct.comm); - MPI_Bcast(&mpi_phmlen, 1, MPI_DOUBLE, 0, mpi_ct.comm); - MPI_Bcast(&mpi_rotinc, 1, MPI_DOUBLE, 0, mpi_ct.comm); - MPI_Bcast(&nx, 1, MPI_INT, 0, mpi_ct.comm); - MPI_Bcast(&ny, 1, MPI_INT, 0, mpi_ct.comm); + mpi_t1 = MPI::Wtime(); + 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); + mpi_ct.comm.Bcast (&opt_filter, 1, MPI::INT, 0); + mpi_ct.comm.Bcast (&opt_interp, 1, MPI::INT, 0); + mpi_ct.comm.Bcast (&opt_filter_param, 1, MPI::DOUBLE, 0); + mpi_ct.comm.Bcast (&opt_interp_param, 1, MPI::INT, 0); + mpi_ct.comm.Bcast (&opt_backproj, 1, MPI::INT, 0); + mpi_ct.comm.Bcast (&mpi_ndet, 1, MPI::INT, 0); + mpi_ct.comm.Bcast (&mpi_nview, 1, MPI::INT, 0); + mpi_ct.comm.Bcast (&mpi_detinc, 1, MPI::DOUBLE, 0); + mpi_ct.comm.Bcast (&mpi_phmlen, 1, MPI::DOUBLE, 0); + mpi_ct.comm.Bcast (&mpi_rotinc, 1, MPI::DOUBLE, 0); + mpi_ct.comm.Bcast (&nx, 1, MPI::INT, 0); + mpi_ct.comm.Bcast (&ny, 1, MPI::INT, 0); 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 Bcast vars = %f secs, Max time = %f\n", mpi_t, mpi_t_g); } @@ -334,12 +337,12 @@ ctrec_main (const int argc, char *const argv[]) rs_local->rot_inc = mpi_rotinc; if (opt_verbose) - mpi_t1 = MPI_Wtime(); + mpi_t1 = MPI::Wtime(); mpi_scatter_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 scatter rs = %f secs, Max time = %f sec\n", mpi_t, mpi_t_g); } @@ -361,13 +364,13 @@ ctrec_main (const int argc, char *const argv[]) #endif -#ifdef MPI_CT - mpi_t1 = MPI_Wtime(); +#ifdef HAVE_MPI + mpi_t1 = MPI::Wtime(); proj_reconst (*im_local, rs_local, opt_filter, opt_filter_param, opt_interp, opt_interp_param, opt_backproj, opt_trace); - 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 && opt_verbose) printf("Time to reconstruct = %f, Max time = %f\n", mpi_t, mpi_t_g); #else @@ -375,9 +378,9 @@ ctrec_main (const int argc, char *const argv[]) opt_interp, opt_interp_param, opt_backproj, opt_trace); #endif -#ifdef MPI_CT +#ifdef HAVE_MPI if (opt_verbose) - mpi_t1 = MPI_Wtime(); + mpi_t1 = MPI::Wtime(); int nxLocal = im_local->adf.nx(); int nyLocal = im_local->adf.ny(); @@ -389,25 +392,25 @@ ctrec_main (const int argc, char *const argv[]) if (mpi_ct.my_rank == 0) recvbuf = vGlobal[ix]; - MPI_Reduce(vLocal[ix], recvbuf, nyLocal, MPI_FLOAT, MPI_SUM, 0, mpi_ct.comm); + mpi_ct.comm.Reduce(vLocal[ix], recvbuf, nyLocal, MPI::FLOAT, MPI::SUM, 0); } 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 reduce image = %f secs, max time = %f\n", mpi_t, mpi_t_g); } if (mpi_ct.my_rank == 0) - time_end = MPI_Wtime(); + time_end = MPI::Wtime(); #else time_end = td_current_sec(); #endif -#ifdef MPI_CT +#ifdef HAVE_MPI if (mpi_ct.my_rank == 0) #endif { @@ -421,15 +424,15 @@ ctrec_main (const int argc, char *const argv[]) cout << "Time active = " << calctime << " sec" << endl; } -#ifdef MPI_CT - MPI_Finalize(); +#ifdef HAVE_MPI + MPI::Finalize(); #endif return (0); } -#ifdef MPI_CT +#ifdef HAVE_MPI static void mpi_scatter_rs (RAYSUM *rs_global, RAYSUM *rs_local, const int opt_debug) { int iproc; @@ -441,9 +444,9 @@ static void mpi_scatter_rs (RAYSUM *rs_global, RAYSUM *rs_local, const int opt_d end_work_unit = mpi_ct.start_work_unit[iproc] + mpi_ct.local_work_units[iproc] - 1; for (iw = mpi_ct.start_work_unit[iproc]; iw <= end_work_unit; iw++) { - MPI_Send(&rs_global->view[iw]->ndet, 1, MPI_INT, iproc, 0, mpi_ct.comm); - MPI_Send(&rs_global->view[iw]->view_angle, 1, MPI_DOUBLE, iproc, 0, mpi_ct.comm); - MPI_Send(rs_global->view[iw]->detval, rs_global->ndet, MPI_FLOAT, iproc, 0, mpi_ct.comm); + mpi_ct.comm.Send(&rs_global->view[iw]->ndet, 1, MPI::INT, iproc, 0); + mpi_ct.comm.Send(&rs_global->view[iw]->view_angle, 1, MPI::DOUBLE, iproc, 0); + mpi_ct.comm.Send(rs_global->view[iw]->detval, rs_global->ndet, MPI::FLOAT, iproc, 0); } } } @@ -453,15 +456,15 @@ static void mpi_scatter_rs (RAYSUM *rs_global, RAYSUM *rs_local, const int opt_d end_work_unit = mpi_ct.local_work_units[mpi_ct.my_rank] - 1; for (iw = 0; iw <= end_work_unit; iw++) { - MPI_Status status; + MPI::Status status; - MPI_Recv(&rs_local->view[iw]->ndet, 1, MPI_INT, 0, 0, mpi_ct.comm, &status); - MPI_Recv(&rs_local->view[iw]->view_angle, 1, MPI_DOUBLE, 0, 0, mpi_ct.comm, &status); - MPI_Recv(rs_local->view[iw]->detval, rs_local->ndet, MPI_FLOAT, 0, 0, mpi_ct.comm, &status); + mpi_ct.comm.Recv(&rs_local->view[iw]->ndet, 1, MPI::INT, 0, 0, status); + mpi_ct.comm.Recv(&rs_local->view[iw]->view_angle, 1, MPI::DOUBLE, 0, 0, status); + mpi_ct.comm.Recv(rs_local->view[iw]->detval, rs_local->ndet, MPI::FLOAT, 0, 0, status); } rs_local->nview = mpi_ct.local_work_units[mpi_ct.my_rank]; if (opt_debug) { - MPI_Barrier(MPI_COMM_WORLD); + mpi_ct.comm.Barrier(); fprintf(stdout, "Done with mpi_scatter_rs in process %2d\n", mpi_ct.my_rank); } } diff --git a/src/phm2if.cpp b/src/phm2if.cpp index 2afac40..0d1a09f 100644 --- a/src/phm2if.cpp +++ b/src/phm2if.cpp @@ -2,8 +2,11 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: phm2if.cpp,v 1.3 2000/06/07 07:43:19 kevin Exp $ +** $Id: phm2if.cpp,v 1.4 2000/06/07 10:12:05 kevin Exp $ ** $Log: phm2if.cpp,v $ +** Revision 1.4 2000/06/07 10:12:05 kevin +** Upgraded from MPI to MPI++ +** ** Revision 1.3 2000/06/07 07:43:19 kevin ** Converted to IF data files and C++ ** @@ -137,7 +140,7 @@ phm2sdf_usage (const char *program) fprintf(stdout," --help Print this help message\n"); } -#ifdef MPI_CT +#ifdef HAVE_MPI void mpi_gather_image (ImageFile& im_global, ImageFile& im_local, const int opt_debug); #endif @@ -161,30 +164,30 @@ phm2sdf_main (const int argc, char *const argv[]) int opt_trace = TRACE_NONE; int opt_verbose = 0; double time_start=0, time_end=0; -#ifdef MPI_CT +#ifdef HAVE_MPI ImageFile* im_local = NULL; int mpi_argc = argc; char **mpi_argv = (char **) argv; double mpi_t1, mpi_t2, 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) { + if (mpi_ct.nproc > CT_MPI_MAX_PROCESS) { sys_error(ERR_FATAL, "Number of mpi processes (%d) exceeds max processes (%d)", - mpi_ct.nproc, MPI_MAX_PROCESS); + mpi_ct.nproc, CT_MPI_MAX_PROCESS); } #endif -#ifdef MPI_CT - time_start = MPI_Wtime(); +#ifdef HAVE_MPI + time_start = MPI::Wtime(); #else time_start = td_current_sec(); #endif -#ifdef MPI_CT +#ifdef HAVE_MPI if (mpi_ct.my_rank == 0) { #endif @@ -208,7 +211,7 @@ phm2sdf_main (const int argc, char *const argv[]) case O_PHMFILE: strncpy(opt_phmfilename, optarg, sizeof(opt_phmfilename)); phm = phm_create_from_file(opt_phmfilename); -#ifdef MPI_CT +#ifdef HAVE_MPI if (mpi_ct.my_rank == 0) fprintf(stderr, "Can't use phantom from file in MPI mode\n"); return (1); @@ -333,28 +336,28 @@ phm2sdf_main (const int argc, char *const argv[]) if (opt_verbose) printf("Rasterize Phantom to Image\n\n"); -#ifdef MPI_CT +#ifdef HAVE_MPI } #endif -#ifdef MPI_CT - mpi_t1 = MPI_Wtime(); - 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); - MPI_Bcast(&opt_nx, 1, MPI_INT, 0, mpi_ct.comm); - MPI_Bcast(&opt_ny, 1, MPI_INT, 0, mpi_ct.comm); - MPI_Bcast(&opt_nsample, 1, MPI_INT, 0, mpi_ct.comm); - MPI_Bcast(&opt_phmnum, 1, MPI_INT, 0, mpi_ct.comm); - MPI_Bcast(&opt_filter, 1, MPI_INT, 0, mpi_ct.comm); - MPI_Bcast(&opt_filter_domain, 1, MPI_INT, 0, mpi_ct.comm); - MPI_Bcast(&opt_filter_param, 1, MPI_DOUBLE, 0, mpi_ct.comm); - MPI_Bcast(&opt_filter_bw, 1, MPI_DOUBLE, 0, mpi_ct.comm); +#ifdef HAVE_MPI + mpi_t1 = MPI::Wtime(); + 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); + mpi_ct.comm.Bcast (&opt_nx, 1, MPI::INT, 0); + mpi_ct.comm.Bcast (&opt_ny, 1, MPI::INT, 0); + mpi_ct.comm.Bcast (&opt_nsample, 1, MPI::INT, 0); + mpi_ct.comm.Bcast (&opt_phmnum, 1, MPI::INT, 0); + mpi_ct.comm.Bcast (&opt_filter, 1, MPI::INT, 0); + mpi_ct.comm.Bcast (&opt_filter_domain, 1, MPI::INT, 0); + mpi_ct.comm.Bcast (&opt_filter_param, 1, MPI::DOUBLE, 0); + mpi_ct.comm.Bcast (&opt_filter_bw, 1, MPI::DOUBLE, 0); 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 Bcast vars = %f secs, Max time = %f\n", mpi_t, mpi_t_g); } @@ -375,7 +378,7 @@ phm2sdf_main (const int argc, char *const argv[]) if (opt_phmnum >= 0) phm = phm_create (opt_phmnum); -#ifdef MPI_CT +#ifdef HAVE_MPI else { if (mpi_ct.my_rank == 0) fprintf(stderr, "phmnum < 0\n"); @@ -386,7 +389,7 @@ phm2sdf_main (const int argc, char *const argv[]) ImageFileArray v = im_global->getArray (); double calctime = 0; -#ifdef MPI_CT +#ifdef HAVE_MPI if (phm->type == P_UNIT_PULSE) { if (mpi_ct.my_rank == 0) { v[opt_nx/2][opt_ny/2] = 1.; @@ -399,12 +402,12 @@ phm2sdf_main (const int argc, char *const argv[]) } } else { if (opt_verbose) - mpi_t1 = MPI_Wtime(); + mpi_t1 = MPI::Wtime(); phm_to_imagefile (phm, *im_local, mpi_ct.start_work_unit[mpi_ct.my_rank], mpi_ct.local_work_units[mpi_ct.my_rank], opt_nsample, opt_trace); 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 compile phm = %f secs, Max time = %f\n", mpi_t, mpi_t_g); } @@ -426,13 +429,13 @@ phm2sdf_main (const int argc, char *const argv[]) } #endif -#ifdef MPI_CT - time_end = MPI_Wtime(); +#ifdef HAVE_MPI + time_end = MPI::Wtime(); #else time_end = td_current_sec(); #endif -#ifdef MPI_CT +#ifdef HAVE_MPI if (mpi_ct.my_rank == 0) #endif { @@ -462,7 +465,7 @@ phm2sdf_main (const int argc, char *const argv[]) -#ifdef MPI_CT +#ifdef HAVE_MPI void mpi_gather_image (ImageFile& im_global, ImageFile& im_local, const int opt_debug) { ImageFileArray vLocal = im_local.getArray(); @@ -472,7 +475,7 @@ void mpi_gather_image (ImageFile& im_global, ImageFile& im_local, const int opt_ int end_work_unit = mpi_ct.local_work_units[mpi_ct.my_rank] - 1; for (int iw = 0; iw <= end_work_unit; iw++) { - MPI_Send(vLocal[iw], nyLocal, im_local.getMPIDataType(), 0, 0, mpi_ct.comm); + mpi_ct.comm.Send(vLocal[iw], nyLocal, im_local.getMPIDataType(), 0, 0); } if (mpi_ct.my_rank == 0) { @@ -485,8 +488,8 @@ void mpi_gather_image (ImageFile& im_global, ImageFile& im_local, const int opt_ } for (int iw = mpi_ct.start_work_unit[iproc]; iw <= end_work_unit; iw++) { - MPI_Status status; - MPI_Recv(vGlobal[iw], nyGlobal, MPI_FLOAT, iproc, 0, mpi_ct.comm, &status); + MPI::Status status; + mpi_ct.comm.Recv(vGlobal[iw], nyGlobal, MPI::FLOAT, iproc, 0, status); } } } diff --git a/src/phm2rs.cpp b/src/phm2rs.cpp index 1e15883..78a9f5f 100644 --- a/src/phm2rs.cpp +++ b/src/phm2rs.cpp @@ -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); } } } -- 2.34.1