From b03fa6dc16231995643797d0d556beb27377d0b2 Mon Sep 17 00:00:00 2001 From: James E McClure Date: Fri, 8 Jan 2016 12:57:42 -0500 Subject: [PATCH] Updated TestCommD3Q19 to ensure clean MPI exit --- tests/TestCommD3Q19.cpp | 549 ++++++++++++++++++++-------------------- 1 file changed, 275 insertions(+), 274 deletions(-) diff --git a/tests/TestCommD3Q19.cpp b/tests/TestCommD3Q19.cpp index 943c9c26..6817b479 100644 --- a/tests/TestCommD3Q19.cpp +++ b/tests/TestCommD3Q19.cpp @@ -158,232 +158,233 @@ int main(int argc, char **argv) // Initialize MPI int rank,nprocs; MPI_Init(&argc,&argv); - MPI_Comm comm = MPI_COMM_WORLD; + MPI_Comm comm = MPI_COMM_WORLD; MPI_Comm_rank(comm,&rank); MPI_Comm_size(comm,&nprocs); - // parallel domain size (# of sub-domains) - int nprocx,nprocy,nprocz; - int iproc,jproc,kproc; - //***************************************** - // MPI ranks for all 18 neighbors - //********************************** - int rank_x,rank_y,rank_z,rank_X,rank_Y,rank_Z; - int rank_xy,rank_XY,rank_xY,rank_Xy; - int rank_xz,rank_XZ,rank_xZ,rank_Xz; - int rank_yz,rank_YZ,rank_yZ,rank_Yz; - //********************************** - MPI_Request req1[18],req2[18]; - MPI_Status stat1[18],stat2[18]; + { + // parallel domain size (# of sub-domains) + int nprocx,nprocy,nprocz; + int iproc,jproc,kproc; + //***************************************** + // MPI ranks for all 18 neighbors + //********************************** + int rank_x,rank_y,rank_z,rank_X,rank_Y,rank_Z; + int rank_xy,rank_XY,rank_xY,rank_Xy; + int rank_xz,rank_XZ,rank_xZ,rank_Xz; + int rank_yz,rank_YZ,rank_yZ,rank_Yz; + //********************************** + MPI_Request req1[18],req2[18]; + MPI_Status stat1[18],stat2[18]; - if (rank == 0){ - printf("********************************************************\n"); - printf("Running Unit Test for D3Q19 MPI Communication \n"); - printf("********************************************************\n"); - } + if (rank == 0){ + printf("********************************************************\n"); + printf("Running Unit Test for D3Q19 MPI Communication \n"); + printf("********************************************************\n"); + } - // BGK Model parameters - string FILENAME; - unsigned int nBlocks, nthreads; - int timestepMax, interval; - double tau,Fx,Fy,Fz,tol; - // Domain variables - double Lx,Ly,Lz; - int nspheres; - int Nx,Ny,Nz; - int i,j,k,n; + // BGK Model parameters + string FILENAME; + unsigned int nBlocks, nthreads; + int timestepMax, interval; + double tau,Fx,Fy,Fz,tol; + // Domain variables + double Lx,Ly,Lz; + int nspheres; + int Nx,Ny,Nz; + int i,j,k,n; + + if (rank==0){ + //....................................................................... + // Reading the domain information file + //....................................................................... + ifstream domain("Domain.in"); + if (domain.good()){ + domain >> nprocx; + domain >> nprocy; + domain >> nprocz; + domain >> Nx; + domain >> Ny; + domain >> Nz; + domain >> nspheres; + domain >> Lx; + domain >> Ly; + domain >> Lz; + } + else if (nprocs==1){ + nprocx=nprocy=nprocz=1; + Nx=Ny=Nz=50; + nspheres=0; + Lx=Ly=Lz=1; + } + else if (nprocs==2){ + nprocx=nprocy=1; + nprocz=2; + Nx=Ny=Nz=50; + nspheres=0; + Lx=Ly=Lz=1; + } + else if (nprocs==4){ + nprocx=nprocy=2; + nprocz=1; + Nx=Ny=Nz=50; + nspheres=0; + Lx=Ly=Lz=1; + } + else if (nprocs==8){ + nprocx=nprocy=nprocz=2; + Nx=Ny=Nz=50; + nspheres=0; + Lx=Ly=Lz=1; + } + //....................................................................... + } + // ************************************************************** + // Broadcast simulation parameters from rank 0 to all other procs + MPI_Barrier(comm); + //................................................. + MPI_Bcast(&Nx,1,MPI_INT,0,comm); + MPI_Bcast(&Ny,1,MPI_INT,0,comm); + MPI_Bcast(&Nz,1,MPI_INT,0,comm); + MPI_Bcast(&nBlocks,1,MPI_INT,0,comm); + MPI_Bcast(&nthreads,1,MPI_INT,0,comm); + MPI_Bcast(×tepMax,1,MPI_INT,0,comm); + + MPI_Bcast(&Nx,1,MPI_INT,0,comm); + MPI_Bcast(&Ny,1,MPI_INT,0,comm); + MPI_Bcast(&Nz,1,MPI_INT,0,comm); + MPI_Bcast(&nprocx,1,MPI_INT,0,comm); + MPI_Bcast(&nprocy,1,MPI_INT,0,comm); + MPI_Bcast(&nprocz,1,MPI_INT,0,comm); + MPI_Bcast(&nspheres,1,MPI_INT,0,comm); + MPI_Bcast(&Lx,1,MPI_DOUBLE,0,comm); + MPI_Bcast(&Ly,1,MPI_DOUBLE,0,comm); + MPI_Bcast(&Lz,1,MPI_DOUBLE,0,comm); + //................................................. + MPI_Barrier(comm); + // ************************************************************** + // ************************************************************** + + if (nprocs != nprocx*nprocy*nprocz){ + printf("nprocx = %i \n",nprocx); + printf("nprocy = %i \n",nprocy); + printf("nprocz = %i \n",nprocz); + INSIST(nprocs == nprocx*nprocy*nprocz,"Fatal error in processor count!"); + } + + if (rank==0){ + printf("********************************************************\n"); + printf("Sub-domain size = %i x %i x %i\n",Nz,Nz,Nz); + printf("Parallel domain size = %i x %i x %i\n",nprocx,nprocy,nprocz); + printf("********************************************************\n"); + } + + MPI_Barrier(comm); + kproc = rank/(nprocx*nprocy); + jproc = (rank-nprocx*nprocy*kproc)/nprocx; + iproc = rank-nprocx*nprocy*kproc-nprocz*jproc; + + double iVol_global = 1.0/Nx/Ny/Nz/nprocx/nprocy/nprocz; + int BoundaryCondition=0; + Domain Dm(Nx,Ny,Nz,rank,nprocx,nprocy,nprocz,Lx,Ly,Lz,BoundaryCondition); + + InitializeRanks( rank, nprocx, nprocy, nprocz, iproc, jproc, kproc, + rank_x, rank_y, rank_z, rank_X, rank_Y, rank_Z, + rank_xy, rank_XY, rank_xY, rank_Xy, rank_xz, rank_XZ, rank_xZ, rank_Xz, + rank_yz, rank_YZ, rank_yZ, rank_Yz ); + + Nx += 2; + Ny += 2; + Nz += 2; + int N = Nx*Ny*Nz; + int dist_mem_size = N*sizeof(double); - if (rank==0){ //....................................................................... - // Reading the domain information file + // Assign the phase ID field //....................................................................... - ifstream domain("Domain.in"); - if (domain.good()){ - domain >> nprocx; - domain >> nprocy; - domain >> nprocz; - domain >> Nx; - domain >> Ny; - domain >> Nz; - domain >> nspheres; - domain >> Lx; - domain >> Ly; - domain >> Lz; - } - else if (nprocs==1){ - nprocx=nprocy=nprocz=1; - Nx=Ny=Nz=50; - nspheres=0; - Lx=Ly=Lz=1; - } - else if (nprocs==2){ - nprocx=nprocy=1; - nprocz=2; - Nx=Ny=Nz=50; - nspheres=0; - Lx=Ly=Lz=1; - } - else if (nprocs==4){ - nprocx=nprocy=2; - nprocz=1; - Nx=Ny=Nz=50; - nspheres=0; - Lx=Ly=Lz=1; - } - else if (nprocs==8){ - nprocx=nprocy=nprocz=2; - Nx=Ny=Nz=50; - nspheres=0; - Lx=Ly=Lz=1; - } - //....................................................................... - } - // ************************************************************** - // Broadcast simulation parameters from rank 0 to all other procs - MPI_Barrier(comm); - //................................................. - MPI_Bcast(&Nx,1,MPI_INT,0,comm); - MPI_Bcast(&Ny,1,MPI_INT,0,comm); - MPI_Bcast(&Nz,1,MPI_INT,0,comm); - MPI_Bcast(&nBlocks,1,MPI_INT,0,comm); - MPI_Bcast(&nthreads,1,MPI_INT,0,comm); - MPI_Bcast(×tepMax,1,MPI_INT,0,comm); + char LocalRankString[8]; + sprintf(LocalRankString,"%05d",rank); + char LocalRankFilename[40]; + sprintf(LocalRankFilename,"ID.%05i",rank); - MPI_Bcast(&Nx,1,MPI_INT,0,comm); - MPI_Bcast(&Ny,1,MPI_INT,0,comm); - MPI_Bcast(&Nz,1,MPI_INT,0,comm); - MPI_Bcast(&nprocx,1,MPI_INT,0,comm); - MPI_Bcast(&nprocy,1,MPI_INT,0,comm); - MPI_Bcast(&nprocz,1,MPI_INT,0,comm); - MPI_Bcast(&nspheres,1,MPI_INT,0,comm); - MPI_Bcast(&Lx,1,MPI_DOUBLE,0,comm); - MPI_Bcast(&Ly,1,MPI_DOUBLE,0,comm); - MPI_Bcast(&Lz,1,MPI_DOUBLE,0,comm); - //................................................. - MPI_Barrier(comm); - // ************************************************************** - // ************************************************************** + char *id; + id = new char[Nx*Ny*Nz]; - if (nprocs != nprocx*nprocy*nprocz){ - printf("nprocx = %i \n",nprocx); - printf("nprocy = %i \n",nprocy); - printf("nprocz = %i \n",nprocz); - INSIST(nprocs == nprocx*nprocy*nprocz,"Fatal error in processor count!"); - } - - if (rank==0){ - printf("********************************************************\n"); - printf("Sub-domain size = %i x %i x %i\n",Nz,Nz,Nz); - printf("Parallel domain size = %i x %i x %i\n",nprocx,nprocy,nprocz); - printf("********************************************************\n"); - } - - MPI_Barrier(comm); - kproc = rank/(nprocx*nprocy); - jproc = (rank-nprocx*nprocy*kproc)/nprocx; - iproc = rank-nprocx*nprocy*kproc-nprocz*jproc; - - double iVol_global = 1.0/Nx/Ny/Nz/nprocx/nprocy/nprocz; - int BoundaryCondition=0; - Domain Dm(Nx,Ny,Nz,rank,nprocx,nprocy,nprocz,Lx,Ly,Lz,BoundaryCondition); - - InitializeRanks( rank, nprocx, nprocy, nprocz, iproc, jproc, kproc, - rank_x, rank_y, rank_z, rank_X, rank_Y, rank_Z, - rank_xy, rank_XY, rank_xY, rank_Xy, rank_xz, rank_XZ, rank_xZ, rank_Xz, - rank_yz, rank_YZ, rank_yZ, rank_Yz ); - - Nx += 2; - Ny += 2; - Nz += 2; - int N = Nx*Ny*Nz; - int dist_mem_size = N*sizeof(double); - - //....................................................................... - // Assign the phase ID field - //....................................................................... - char LocalRankString[8]; - sprintf(LocalRankString,"%05d",rank); - char LocalRankFilename[40]; - sprintf(LocalRankFilename,"ID.%05i",rank); - - char *id; - id = new char[Nx*Ny*Nz]; - -/* - * if (rank==0) printf("Assigning phase ID from file \n"); - * if (rank==0) printf("Initialize from segmented data: solid=0, NWP=1, WP=2 \n"); + /* + * if (rank==0) printf("Assigning phase ID from file \n"); + * if (rank==0) printf("Initialize from segmented data: solid=0, NWP=1, WP=2 \n"); FILE *IDFILE = fopen(LocalRankFilename,"rb"); if (IDFILE==NULL) ERROR("Error opening file: ID.xxxxx"); fread(id,1,N,IDFILE); fclose(IDFILE); - */ - // Setup the domain - for (k=0;k