From 7dc8f33d444bfc8af9a35a9f3dcc6a719be7f064 Mon Sep 17 00:00:00 2001 From: James E McClure Date: Fri, 14 Apr 2017 14:06:13 -0400 Subject: [PATCH] Added support for multi-input domains in lbpm_segmented_decomp --- tests/lbpm_segmented_decomp.cpp | 540 ++++++++++++++++---------------- 1 file changed, 277 insertions(+), 263 deletions(-) diff --git a/tests/lbpm_segmented_decomp.cpp b/tests/lbpm_segmented_decomp.cpp index 99d6fe55..be0c5d65 100644 --- a/tests/lbpm_segmented_decomp.cpp +++ b/tests/lbpm_segmented_decomp.cpp @@ -18,294 +18,308 @@ int main(int argc, char **argv) // Initialize MPI int rank, nprocs; MPI_Init(&argc,&argv); - + MPI_Comm comm = MPI_COMM_WORLD; MPI_Comm_rank(comm,&rank); MPI_Comm_size(comm,&nprocs); { - - int SOLID=atoi(argv[1]); - int NWP=atoi(argv[2]); - //char NWP,SOLID; - //SOLID=argv[1][0]; - //NWP=argv[2][0]; - if (rank==0){ - printf("Solid Label: %i \n",SOLID); - printf("NWP Label: %i \n",NWP); - } - - //....................................................................... - // Reading the domain information file - //....................................................................... - int nprocx, nprocy, nprocz, nx, ny, nz, nspheres; - double Lx, Ly, Lz; - int Nx,Ny,Nz; - int i,j,k,n; - int BC=0; - char Filename[40]; - int xStart,yStart,zStart; - // char fluidValue,solidValue; - std::vector solidValues; - std::vector nwpValues; - std::string line; - if (rank==0){ - ifstream domain("Domain.in"); - domain >> nprocx; - domain >> nprocy; - domain >> nprocz; - domain >> nx; - domain >> ny; - domain >> nz; - domain >> nspheres; - domain >> Lx; - domain >> Ly; - domain >> Lz; + bool MULTINPUT=false; - ifstream image("Segmented.in"); - image >> Filename; // Name of data file containing segmented data - image >> Nx; // size of the binary file - image >> Ny; - image >> Nz; - image >> xStart; // offset for the starting voxel - image >> yStart; - image >> zStart; + int NWP,SOLID,rank_offset; + SOLID=atoi(argv[1]); + NWP=atoi(argv[2]); + //char NWP,SOLID; + //SOLID=argv[1][0]; + //NWP=argv[2][0]; + if (rank==0){ + printf("Solid Label: %i \n",SOLID); + printf("NWP Label: %i \n",NWP); + } + if (argc > 3){ + rank_offset = atoi(argv[3]); + } + else{ + MULTINPUT=true; + rank_offset=0; + } - } - MPI_Barrier(comm); - // Computational domain - //................................................. - 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_Bcast(&Ny,1,MPI_INT,0,comm); - MPI_Bcast(&Ny,1,MPI_INT,0,comm); - MPI_Bcast(&Nz,1,MPI_INT,0,comm); - MPI_Bcast(&xStart,1,MPI_INT,0,comm); - MPI_Bcast(&yStart,1,MPI_INT,0,comm); - MPI_Bcast(&zStart,1,MPI_INT,0,comm); - //................................................. - MPI_Barrier(comm); + //....................................................................... + // Reading the domain information file + //....................................................................... + int nprocx, nprocy, nprocz, nx, ny, nz, nspheres; + double Lx, Ly, Lz; + int Nx,Ny,Nz; + int i,j,k,n; + int BC=0; + char Filename[40]; + int xStart,yStart,zStart; + // char fluidValue,solidValue; - // Check that the number of processors >= the number of ranks - if ( rank==0 ) { - printf("Number of MPI ranks required: %i \n", nprocx*nprocy*nprocz); - printf("Number of MPI ranks used: %i \n", nprocs); - printf("Full domain size: %i x %i x %i \n",nx*nprocx,ny*nprocy,nz*nprocz); - } - if ( nprocs < nprocx*nprocy*nprocz ){ - ERROR("Insufficient number of processors"); - } - char *SegData = NULL; - // Rank=0 reads the entire segmented data and distributes to worker processes - if (rank==0){ - printf("Dimensions of segmented image: %i x %i x %i \n",Nx,Ny,Nz); - SegData = new char[Nx*Ny*Nz]; - FILE *SEGDAT = fopen(Filename,"rb"); - if (SEGDAT==NULL) ERROR("Error reading segmented data"); - size_t ReadSeg; - ReadSeg=fread(SegData,1,Nx*Ny*Nz,SEGDAT); - if (ReadSeg != size_t(Nx*Ny*Nz)) printf("lbpm_segmented_decomp: Error reading segmented data (rank=%i)\n",rank); - fclose(SEGDAT); - printf("Read segmented data from %s \n",Filename); - } - MPI_Barrier(comm); + std::vector solidValues; + std::vector nwpValues; + std::string line; - // Get the rank info - int N = (nx+2)*(ny+2)*(nz+2); - Domain Dm(nx,ny,nz,rank,nprocx,nprocy,nprocz,Lx,Ly,Lz,BC); - for (k=0;k> nprocx; + domain >> nprocy; + domain >> nprocz; + domain >> nx; + domain >> ny; + domain >> nz; + domain >> nspheres; + domain >> Lx; + domain >> Ly; + domain >> Lz; + + ifstream image("Segmented.in"); + image >> Filename; // Name of data file containing segmented data + image >> Nx; // size of the binary file + image >> Ny; + image >> Nz; + image >> xStart; // offset for the starting voxel + image >> yStart; + image >> zStart; + + } + MPI_Barrier(comm); + // Computational domain + //................................................. + 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_Bcast(&Ny,1,MPI_INT,0,comm); + MPI_Bcast(&Ny,1,MPI_INT,0,comm); + MPI_Bcast(&Nz,1,MPI_INT,0,comm); + MPI_Bcast(&xStart,1,MPI_INT,0,comm); + MPI_Bcast(&yStart,1,MPI_INT,0,comm); + MPI_Bcast(&zStart,1,MPI_INT,0,comm); + //................................................. + MPI_Barrier(comm); + + // Check that the number of processors >= the number of ranks + if ( rank==0 ) { + printf("Number of MPI ranks required: %i \n", nprocx*nprocy*nprocz); + printf("Number of MPI ranks used: %i \n", nprocs); + printf("Full domain size: %i x %i x %i \n",nx*nprocx,ny*nprocy,nz*nprocz); + } + if ( nprocs < nprocx*nprocy*nprocz ){ + ERROR("Insufficient number of processors"); + } + char *SegData = NULL; + // Rank=0 reads the entire segmented data and distributes to worker processes + if (rank==0){ + printf("Dimensions of segmented image: %i x %i x %i \n",Nx,Ny,Nz); + SegData = new char[Nx*Ny*Nz]; + FILE *SEGDAT = fopen(Filename,"rb"); + if (SEGDAT==NULL) ERROR("Error reading segmented data"); + size_t ReadSeg; + ReadSeg=fread(SegData,1,Nx*Ny*Nz,SEGDAT); + if (ReadSeg != size_t(Nx*Ny*Nz)) printf("lbpm_segmented_decomp: Error reading segmented data (rank=%i)\n",rank); + fclose(SEGDAT); + printf("Read segmented data from %s \n",Filename); + } + MPI_Barrier(comm); + + // Get the rank info + int N = (nx+2)*(ny+2)*(nz+2); + Domain Dm(nx,ny,nz,rank,nprocx,nprocy,nprocz,Lx,Ly,Lz,BC); + for (k=0;k