Fixing some compile warnings
This commit is contained in:
parent
adbd8d2937
commit
182a661fdf
@ -9,12 +9,12 @@
|
|||||||
|
|
||||||
inline float minmod(float &a, float &b)
|
inline float minmod(float &a, float &b)
|
||||||
{
|
{
|
||||||
float value = a;
|
float value = a;
|
||||||
if ( a*b < 0.0)
|
if ( a*b < 0.0)
|
||||||
value=0.0;
|
value=0.0;
|
||||||
else if (fabs(a) > fabs(b))
|
else if (fabs(a) > fabs(b))
|
||||||
value = b;
|
value = b;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -23,79 +23,79 @@ inline float minmod(float &a, float &b)
|
|||||||
******************************************************************/
|
******************************************************************/
|
||||||
inline float Eikonal3D( Array<float> &Distance, const Array<char> &ID, const Domain &Dm, const int timesteps)
|
inline float Eikonal3D( Array<float> &Distance, const Array<char> &ID, const Domain &Dm, const int timesteps)
|
||||||
{
|
{
|
||||||
PROFILE_START("Eikonal3D");
|
PROFILE_START("Eikonal3D");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This routine converts the data in the Distance array to a signed distance
|
* This routine converts the data in the Distance array to a signed distance
|
||||||
* by solving the equation df/dt = sign*(1-|grad f|), where Distance provides
|
* by solving the equation df/dt = sign*(1-|grad f|), where Distance provides
|
||||||
* the values of f on the mesh associated with domain Dm
|
* the values of f on the mesh associated with domain Dm
|
||||||
* It has been tested with segmented data initialized to values [-1,1]
|
* It has been tested with segmented data initialized to values [-1,1]
|
||||||
* and will converge toward the signed distance to the surface bounding the associated phases
|
* and will converge toward the signed distance to the surface bounding the associated phases
|
||||||
*
|
*
|
||||||
* Reference:
|
* Reference:
|
||||||
* Min C (2010) On reinitializing level set functions, Journal of Computational Physics 229
|
* Min C (2010) On reinitializing level set functions, Journal of Computational Physics 229
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int i,j,k;
|
int i,j,k;
|
||||||
float dt=0.1;
|
float dt=0.1;
|
||||||
float Dx,Dy,Dz;
|
float Dx,Dy,Dz;
|
||||||
float Dxp,Dxm,Dyp,Dym,Dzp,Dzm;
|
float Dxp,Dxm,Dyp,Dym,Dzp,Dzm;
|
||||||
float Dxxp,Dxxm,Dyyp,Dyym,Dzzp,Dzzm;
|
float Dxxp,Dxxm,Dyyp,Dyym,Dzzp,Dzzm;
|
||||||
float sign,norm;
|
float sign,norm;
|
||||||
float LocalVar,GlobalVar,LocalMax,GlobalMax;
|
float LocalVar,GlobalVar,LocalMax,GlobalMax;
|
||||||
|
|
||||||
int xdim,ydim,zdim;
|
int xdim,ydim,zdim;
|
||||||
xdim=Dm.Nx-2;
|
xdim=Dm.Nx-2;
|
||||||
ydim=Dm.Ny-2;
|
ydim=Dm.Ny-2;
|
||||||
zdim=Dm.Nz-2;
|
zdim=Dm.Nz-2;
|
||||||
fillHalo<float> fillData(Dm.Comm, Dm.rank_info,xdim,ydim,zdim,1,1,1,0,1);
|
fillHalo<float> fillData(Dm.Comm, Dm.rank_info,xdim,ydim,zdim,1,1,1,0,1);
|
||||||
|
|
||||||
// Arrays to store the second derivatives
|
// Arrays to store the second derivatives
|
||||||
Array<float> Dxx(Dm.Nx,Dm.Ny,Dm.Nz);
|
Array<float> Dxx(Dm.Nx,Dm.Ny,Dm.Nz);
|
||||||
Array<float> Dyy(Dm.Nx,Dm.Ny,Dm.Nz);
|
Array<float> Dyy(Dm.Nx,Dm.Ny,Dm.Nz);
|
||||||
Array<float> Dzz(Dm.Nx,Dm.Ny,Dm.Nz);
|
Array<float> Dzz(Dm.Nx,Dm.Ny,Dm.Nz);
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
while (count < timesteps){
|
while (count < timesteps){
|
||||||
|
|
||||||
// Communicate the halo of values
|
// Communicate the halo of values
|
||||||
fillData.fill(Distance);
|
fillData.fill(Distance);
|
||||||
|
|
||||||
// Compute second order derivatives
|
// Compute second order derivatives
|
||||||
for (k=1;k<Dm.Nz-1;k++){
|
for (k=1;k<Dm.Nz-1;k++){
|
||||||
for (j=1;j<Dm.Ny-1;j++){
|
for (j=1;j<Dm.Ny-1;j++){
|
||||||
for (i=1;i<Dm.Nx-1;i++){
|
for (i=1;i<Dm.Nx-1;i++){
|
||||||
Dxx(i,j,k) = Distance(i+1,j,k) + Distance(i-1,j,k) - 2*Distance(i,j,k);
|
Dxx(i,j,k) = Distance(i+1,j,k) + Distance(i-1,j,k) - 2*Distance(i,j,k);
|
||||||
Dyy(i,j,k) = Distance(i,j+1,k) + Distance(i,j-1,k) - 2*Distance(i,j,k);
|
Dyy(i,j,k) = Distance(i,j+1,k) + Distance(i,j-1,k) - 2*Distance(i,j,k);
|
||||||
Dzz(i,j,k) = Distance(i,j,k+1) + Distance(i,j,k-1) - 2*Distance(i,j,k);
|
Dzz(i,j,k) = Distance(i,j,k+1) + Distance(i,j,k-1) - 2*Distance(i,j,k);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fillData.fill(Dxx);
|
fillData.fill(Dxx);
|
||||||
fillData.fill(Dyy);
|
fillData.fill(Dyy);
|
||||||
fillData.fill(Dzz);
|
fillData.fill(Dzz);
|
||||||
|
|
||||||
LocalMax=LocalVar=0.0;
|
LocalMax=LocalVar=0.0;
|
||||||
// Execute the next timestep
|
// Execute the next timestep
|
||||||
// f(n+1) = f(n) + dt*sign(1-|grad f|)
|
// f(n+1) = f(n) + dt*sign(1-|grad f|)
|
||||||
for (k=1;k<Dm.Nz-1;k++){
|
for (k=1;k<Dm.Nz-1;k++){
|
||||||
for (j=1;j<Dm.Ny-1;j++){
|
for (j=1;j<Dm.Ny-1;j++){
|
||||||
for (i=1;i<Dm.Nx-1;i++){
|
for (i=1;i<Dm.Nx-1;i++){
|
||||||
|
|
||||||
int n = k*Dm.Nx*Dm.Ny + j*Dm.Nx + i;
|
int n = k*Dm.Nx*Dm.Ny + j*Dm.Nx + i;
|
||||||
|
|
||||||
sign = -1;
|
sign = -1;
|
||||||
if (ID(i,j,k) == 1) sign = 1;
|
if (ID(i,j,k) == 1) sign = 1;
|
||||||
|
|
||||||
// local second derivative terms
|
// local second derivative terms
|
||||||
Dxxp = minmod(Dxx(i,j,k),Dxx(i+1,j,k));
|
Dxxp = minmod(Dxx(i,j,k),Dxx(i+1,j,k));
|
||||||
Dyyp = minmod(Dyy(i,j,k),Dyy(i,j+1,k));
|
Dyyp = minmod(Dyy(i,j,k),Dyy(i,j+1,k));
|
||||||
Dzzp = minmod(Dzz(i,j,k),Dzz(i,j,k+1));
|
Dzzp = minmod(Dzz(i,j,k),Dzz(i,j,k+1));
|
||||||
Dxxm = minmod(Dxx(i,j,k),Dxx(i-1,j,k));
|
Dxxm = minmod(Dxx(i,j,k),Dxx(i-1,j,k));
|
||||||
Dyym = minmod(Dyy(i,j,k),Dyy(i,j-1,k));
|
Dyym = minmod(Dyy(i,j,k),Dyy(i,j-1,k));
|
||||||
Dzzm = minmod(Dzz(i,j,k),Dzz(i,j,k-1));
|
Dzzm = minmod(Dzz(i,j,k),Dzz(i,j,k-1));
|
||||||
|
|
||||||
/* //............Compute upwind derivatives ...................
|
/* //............Compute upwind derivatives ...................
|
||||||
Dxp = Distance(i+1,j,k) - Distance(i,j,k) + 0.5*Dxxp;
|
Dxp = Distance(i+1,j,k) - Distance(i,j,k) + 0.5*Dxxp;
|
||||||
Dyp = Distance(i,j+1,k) - Distance(i,j,k) + 0.5*Dyyp;
|
Dyp = Distance(i,j+1,k) - Distance(i,j,k) + 0.5*Dyyp;
|
||||||
Dzp = Distance(i,j,k+1) - Distance(i,j,k) + 0.5*Dzzp;
|
Dzp = Distance(i,j,k+1) - Distance(i,j,k) + 0.5*Dzzp;
|
||||||
@ -103,64 +103,64 @@ inline float Eikonal3D( Array<float> &Distance, const Array<char> &ID, const Dom
|
|||||||
Dxm = Distance(i,j,k) - Distance(i-1,j,k) + 0.5*Dxxm;
|
Dxm = Distance(i,j,k) - Distance(i-1,j,k) + 0.5*Dxxm;
|
||||||
Dym = Distance(i,j,k) - Distance(i,j-1,k) + 0.5*Dyym;
|
Dym = Distance(i,j,k) - Distance(i,j-1,k) + 0.5*Dyym;
|
||||||
Dzm = Distance(i,j,k) - Distance(i,j,k-1) + 0.5*Dzzm;
|
Dzm = Distance(i,j,k) - Distance(i,j,k-1) + 0.5*Dzzm;
|
||||||
*/
|
*/
|
||||||
Dxp = Distance(i+1,j,k);
|
Dxp = Distance(i+1,j,k);
|
||||||
Dyp = Distance(i,j+1,k);
|
Dyp = Distance(i,j+1,k);
|
||||||
Dzp = Distance(i,j,k+1);
|
Dzp = Distance(i,j,k+1);
|
||||||
|
|
||||||
Dxm = Distance(i-1,j,k);
|
Dxm = Distance(i-1,j,k);
|
||||||
Dym = Distance(i,j-1,k);
|
Dym = Distance(i,j-1,k);
|
||||||
Dzm = Distance(i,j,k-1);
|
Dzm = Distance(i,j,k-1);
|
||||||
|
|
||||||
// Compute upwind derivatives for Godunov Hamiltonian
|
// Compute upwind derivatives for Godunov Hamiltonian
|
||||||
if (sign < 0.0){
|
if (sign < 0.0){
|
||||||
if (Dxp > Dxm) Dx = Dxp - Distance(i,j,k) + 0.5*Dxxp;
|
if (Dxp > Dxm) Dx = Dxp - Distance(i,j,k) + 0.5*Dxxp;
|
||||||
else Dx = Distance(i,j,k) - Dxm + 0.5*Dxxm;
|
else Dx = Distance(i,j,k) - Dxm + 0.5*Dxxm;
|
||||||
|
|
||||||
if (Dyp > Dym) Dy = Dyp - Distance(i,j,k) + 0.5*Dyyp;
|
if (Dyp > Dym) Dy = Dyp - Distance(i,j,k) + 0.5*Dyyp;
|
||||||
else Dy = Distance(i,j,k) - Dym + 0.5*Dyym;
|
else Dy = Distance(i,j,k) - Dym + 0.5*Dyym;
|
||||||
|
|
||||||
if (Dzp > Dzm) Dz = Dzp - Distance(i,j,k) + 0.5*Dzzp;
|
if (Dzp > Dzm) Dz = Dzp - Distance(i,j,k) + 0.5*Dzzp;
|
||||||
else Dz = Distance(i,j,k) - Dzm + 0.5*Dzzm;
|
else Dz = Distance(i,j,k) - Dzm + 0.5*Dzzm;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if (Dxp < Dxm) Dx = Dxp - Distance(i,j,k) + 0.5*Dxxp;
|
if (Dxp < Dxm) Dx = Dxp - Distance(i,j,k) + 0.5*Dxxp;
|
||||||
else Dx = Distance(i,j,k) - Dxm + 0.5*Dxxm;
|
else Dx = Distance(i,j,k) - Dxm + 0.5*Dxxm;
|
||||||
|
|
||||||
if (Dyp < Dym) Dy = Dyp - Distance(i,j,k) + 0.5*Dyyp;
|
if (Dyp < Dym) Dy = Dyp - Distance(i,j,k) + 0.5*Dyyp;
|
||||||
else Dy = Distance(i,j,k) - Dym + 0.5*Dyym;
|
else Dy = Distance(i,j,k) - Dym + 0.5*Dyym;
|
||||||
|
|
||||||
if (Dzp < Dzm) Dz = Dzp - Distance(i,j,k) + 0.5*Dzzp;
|
if (Dzp < Dzm) Dz = Dzp - Distance(i,j,k) + 0.5*Dzzp;
|
||||||
else Dz = Distance(i,j,k) - Dzm + 0.5*Dzzm;
|
else Dz = Distance(i,j,k) - Dzm + 0.5*Dzzm;
|
||||||
}
|
}
|
||||||
|
|
||||||
norm=sqrt(Dx*Dx+Dy*Dy+Dz*Dz);
|
norm=sqrt(Dx*Dx+Dy*Dy+Dz*Dz);
|
||||||
if (norm > 1.0) norm=1.0;
|
if (norm > 1.0) norm=1.0;
|
||||||
|
|
||||||
Distance(i,j,k) += dt*sign*(1.0 - norm);
|
Distance(i,j,k) += dt*sign*(1.0 - norm);
|
||||||
LocalVar += dt*sign*(1.0 - norm);
|
LocalVar += dt*sign*(1.0 - norm);
|
||||||
|
|
||||||
if (fabs(dt*sign*(1.0 - norm)) > LocalMax)
|
if (fabs(dt*sign*(1.0 - norm)) > LocalMax)
|
||||||
LocalMax = fabs(dt*sign*(1.0 - norm));
|
LocalMax = fabs(dt*sign*(1.0 - norm));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MPI_Allreduce(&LocalVar,&GlobalVar,1,MPI_FLOAT,MPI_SUM,Dm.Comm);
|
MPI_Allreduce(&LocalVar,&GlobalVar,1,MPI_FLOAT,MPI_SUM,Dm.Comm);
|
||||||
MPI_Allreduce(&LocalMax,&GlobalMax,1,MPI_FLOAT,MPI_MAX,Dm.Comm);
|
MPI_Allreduce(&LocalMax,&GlobalMax,1,MPI_FLOAT,MPI_MAX,Dm.Comm);
|
||||||
GlobalVar /= (Dm.Nx-2)*(Dm.Ny-2)*(Dm.Nz-2)*Dm.nprocx*Dm.nprocy*Dm.nprocz;
|
GlobalVar /= (Dm.Nx-2)*(Dm.Ny-2)*(Dm.Nz-2)*Dm.nprocx*Dm.nprocy*Dm.nprocz;
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
if (count%50 == 0 && Dm.rank==0 )
|
if (count%50 == 0 && Dm.rank==0 )
|
||||||
printf(" Time=%i, Max variation=%f, Global variation=%f \n",count,GlobalMax,GlobalVar);
|
printf(" Time=%i, Max variation=%f, Global variation=%f \n",count,GlobalMax,GlobalVar);
|
||||||
|
|
||||||
if (fabs(GlobalMax) < 1e-5){
|
if (fabs(GlobalMax) < 1e-5){
|
||||||
if (Dm.rank==0) printf(" Exiting with max tolerance of 1e-5 \n");
|
if (Dm.rank==0) printf(" Exiting with max tolerance of 1e-5 \n");
|
||||||
count=timesteps;
|
count=timesteps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PROFILE_STOP("Eikonal3D");
|
PROFILE_STOP("Eikonal3D");
|
||||||
return GlobalVar;
|
return GlobalVar;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +210,7 @@ inline bool CalcDist3DIteration( Array<float> &Distance, const Domain &Dm )
|
|||||||
}
|
}
|
||||||
inline void CalcDist3D( Array<float> &Distance, const Array<char> &ID, const Domain &Dm )
|
inline void CalcDist3D( Array<float> &Distance, const Array<char> &ID, const Domain &Dm )
|
||||||
{
|
{
|
||||||
PROFILE_START("Calc Distance");
|
PROFILE_START("Calc Distance");
|
||||||
// Initialize the distance to be 0 fore the cells adjacent to the interface
|
// Initialize the distance to be 0 fore the cells adjacent to the interface
|
||||||
Distance.fill(1e100);
|
Distance.fill(1e100);
|
||||||
for (size_t k=1; k<ID.size(2)-1; k++) {
|
for (size_t k=1; k<ID.size(2)-1; k++) {
|
||||||
@ -223,10 +223,10 @@ inline void CalcDist3D( Array<float> &Distance, const Array<char> &ID, const Dom
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Compute the distance everywhere
|
// Compute the distance everywhere
|
||||||
fillHalo<float> fillData(Dm.Comm, Dm.rank_info,Dm.Nx,Dm.Ny,Dm.Nz,1,1,1,0,1);
|
fillHalo<float> fillData(Dm.Comm, Dm.rank_info,Dm.Nx,Dm.Ny,Dm.Nz,1,1,1,0,1);
|
||||||
while ( true ) {
|
while ( true ) {
|
||||||
// Communicate the halo of values
|
// Communicate the halo of values
|
||||||
fillData.fill(Distance);
|
fillData.fill(Distance);
|
||||||
// The distance of the cell is the minimum of the distance of the neighbors plus the distance to that node
|
// The distance of the cell is the minimum of the distance of the neighbors plus the distance to that node
|
||||||
bool changed = CalcDist3DIteration( Distance, Dm );
|
bool changed = CalcDist3DIteration( Distance, Dm );
|
||||||
changed = sumReduce(Dm.Comm,changed);
|
changed = sumReduce(Dm.Comm,changed);
|
||||||
@ -236,7 +236,7 @@ inline void CalcDist3D( Array<float> &Distance, const Array<char> &ID, const Dom
|
|||||||
// Update the sign of the distance
|
// Update the sign of the distance
|
||||||
for (size_t i=0; i<ID.length(); i++)
|
for (size_t i=0; i<ID.length(); i++)
|
||||||
Distance(i) *= ID(i)>0 ? 1:-1;
|
Distance(i) *= ID(i)>0 ? 1:-1;
|
||||||
PROFILE_STOP("Calc Distance");
|
PROFILE_STOP("Calc Distance");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -268,29 +268,29 @@ inline void CalcDistMultiLevelHelper( Array<float> &Distance, const Domain &Dm )
|
|||||||
int Ny = Dm.Ny-2;
|
int Ny = Dm.Ny-2;
|
||||||
int Nz = Dm.Nz-2;
|
int Nz = Dm.Nz-2;
|
||||||
ASSERT(int(Distance.size(0))==Nx+2&&int(Distance.size(1))==Ny+2&&int(Distance.size(2))==Nz+2);
|
ASSERT(int(Distance.size(0))==Nx+2&&int(Distance.size(1))==Ny+2&&int(Distance.size(2))==Nz+2);
|
||||||
fillHalo<float> fillData(Dm.Comm,Dm.rank_info,Nx,Ny,Nz,1,1,1,0,1);
|
fillHalo<float> fillData(Dm.Comm,Dm.rank_info,Nx,Ny,Nz,1,1,1,0,1);
|
||||||
if ( Nx%ratio==0 && Nx>8 && Ny%ratio==0 && Ny>8 && Nz%ratio==0 && Nz>8 ) {
|
if ( Nx%ratio==0 && Nx>8 && Ny%ratio==0 && Ny>8 && Nz%ratio==0 && Nz>8 ) {
|
||||||
// Use recursive version
|
// Use recursive version
|
||||||
int Nr = std::max(std::max(ratio,ratio),ratio);
|
int Nr = std::max(std::max(ratio,ratio),ratio);
|
||||||
// Run Nr iterations, communicate, run Nr iterations
|
// Run Nr iterations, communicate, run Nr iterations
|
||||||
for (int i=0; i<Nr; i++)
|
for (int i=0; i<Nr; i++)
|
||||||
CalcDist3DIteration( Distance, Dm );
|
CalcDist3DIteration( Distance, Dm );
|
||||||
/*fillData.fill(Distance);
|
/*fillData.fill(Distance);
|
||||||
for (int i=0; i<Nr; i++)
|
for (int i=0; i<Nr; i++)
|
||||||
CalcDist3DIteration( Distance, Dm );*/
|
CalcDist3DIteration( Distance, Dm );*/
|
||||||
// Coarsen
|
// Coarsen
|
||||||
Array<float> dist(Nx,Ny,Nz);
|
Array<float> dist(Nx,Ny,Nz);
|
||||||
fillData.copy(Distance,dist);
|
fillData.copy(Distance,dist);
|
||||||
Domain Dm2(Nx/ratio,Ny/ratio,Nz/ratio,Dm.rank,Dm.nprocx,Dm.nprocy,Dm.nprocz,Dm.Lx,Dm.Ly,Dm.Lz,0);
|
Domain Dm2(Nx/ratio,Ny/ratio,Nz/ratio,Dm.rank,Dm.nprocx,Dm.nprocy,Dm.nprocz,Dm.Lx,Dm.Ly,Dm.Lz,0);
|
||||||
Dm2.CommInit(Dm.Comm);
|
Dm2.CommInit(Dm.Comm);
|
||||||
fillHalo<float> fillData2(Dm2.Comm,Dm2.rank_info,Nx/ratio,Ny/ratio,Nz/ratio,1,1,1,0,1);
|
fillHalo<float> fillData2(Dm2.Comm,Dm2.rank_info,Nx/ratio,Ny/ratio,Nz/ratio,1,1,1,0,1);
|
||||||
auto dist2 = dist.coarsen( {ratio,ratio,ratio}, coarsen );
|
auto dist2 = dist.coarsen( {ratio,ratio,ratio}, coarsen );
|
||||||
Array<float> Distance2(Nx/ratio+2,Ny/ratio+2,Nz/ratio+2);
|
Array<float> Distance2(Nx/ratio+2,Ny/ratio+2,Nz/ratio+2);
|
||||||
fillData2.copy(dist2,Distance2);
|
fillData2.copy(dist2,Distance2);
|
||||||
// Solve
|
// Solve
|
||||||
CalcDistMultiLevelHelper( Distance2, Dm2 );
|
CalcDistMultiLevelHelper( Distance2, Dm2 );
|
||||||
// Interpolate the coarse grid to the fine grid
|
// Interpolate the coarse grid to the fine grid
|
||||||
fillData2.copy(Distance2,dist2);
|
fillData2.copy(Distance2,dist2);
|
||||||
for (int k=0; k<Nz; k++) {
|
for (int k=0; k<Nz; k++) {
|
||||||
int k2 = k/ratio;
|
int k2 = k/ratio;
|
||||||
float z = (k-k2*ratio)-0.5*(ratio-1);
|
float z = (k-k2*ratio)-0.5*(ratio-1);
|
||||||
@ -304,18 +304,18 @@ inline void CalcDistMultiLevelHelper( Array<float> &Distance, const Domain &Dm )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fillData.copy(dist,Distance);
|
fillData.copy(dist,Distance);
|
||||||
// Run Nr iterations, communicate, run Nr iterations
|
// Run Nr iterations, communicate, run Nr iterations
|
||||||
for (int i=0; i<Nr; i++)
|
for (int i=0; i<Nr; i++)
|
||||||
CalcDist3DIteration( Distance, Dm );
|
CalcDist3DIteration( Distance, Dm );
|
||||||
fillData.fill(Distance);
|
fillData.fill(Distance);
|
||||||
for (int i=0; i<Nr; i++)
|
for (int i=0; i<Nr; i++)
|
||||||
CalcDist3DIteration( Distance, Dm );
|
CalcDist3DIteration( Distance, Dm );
|
||||||
} else {
|
} else {
|
||||||
// Use coarse-grid version
|
// Use coarse-grid version
|
||||||
while ( true ) {
|
while ( true ) {
|
||||||
// Communicate the halo of values
|
// Communicate the halo of values
|
||||||
fillData.fill(Distance);
|
fillData.fill(Distance);
|
||||||
// The distance of the cell is the minimum of the distance of the neighbors plus the distance to that node
|
// The distance of the cell is the minimum of the distance of the neighbors plus the distance to that node
|
||||||
bool changed = CalcDist3DIteration( Distance, Dm );
|
bool changed = CalcDist3DIteration( Distance, Dm );
|
||||||
changed = sumReduce(Dm.Comm,changed);
|
changed = sumReduce(Dm.Comm,changed);
|
||||||
@ -326,12 +326,12 @@ inline void CalcDistMultiLevelHelper( Array<float> &Distance, const Domain &Dm )
|
|||||||
}
|
}
|
||||||
inline void CalcDistMultiLevel( Array<float> &Distance, const Array<char> &ID, const Domain &Dm )
|
inline void CalcDistMultiLevel( Array<float> &Distance, const Array<char> &ID, const Domain &Dm )
|
||||||
{
|
{
|
||||||
PROFILE_START("Calc Distance Multilevel");
|
PROFILE_START("Calc Distance Multilevel");
|
||||||
int Nx = Dm.Nx-2;
|
int Nx = Dm.Nx-2;
|
||||||
int Ny = Dm.Ny-2;
|
int Ny = Dm.Ny-2;
|
||||||
int Nz = Dm.Nz-2;
|
int Nz = Dm.Nz-2;
|
||||||
ASSERT(int(Distance.size(0))==Nx+2&&int(Distance.size(1))==Ny+2&&int(Distance.size(2))==Nz+2);
|
ASSERT(int(Distance.size(0))==Nx+2&&int(Distance.size(1))==Ny+2&&int(Distance.size(2))==Nz+2);
|
||||||
fillHalo<float> fillData(Dm.Comm,Dm.rank_info,Nx,Ny,Nz,1,1,1,0,1);
|
fillHalo<float> fillData(Dm.Comm,Dm.rank_info,Nx,Ny,Nz,1,1,1,0,1);
|
||||||
// Initialize the distance to be 0 fore the cells adjacent to the interface
|
// Initialize the distance to be 0 fore the cells adjacent to the interface
|
||||||
Distance.fill(1e100);
|
Distance.fill(1e100);
|
||||||
for (size_t k=1; k<ID.size(2)-1; k++) {
|
for (size_t k=1; k<ID.size(2)-1; k++) {
|
||||||
@ -348,13 +348,13 @@ inline void CalcDistMultiLevel( Array<float> &Distance, const Array<char> &ID, c
|
|||||||
// Update the sign of the distance
|
// Update the sign of the distance
|
||||||
for (size_t i=0; i<ID.length(); i++)
|
for (size_t i=0; i<ID.length(); i++)
|
||||||
Distance(i) *= ID(i)>0 ? 1:-1;
|
Distance(i) *= ID(i)>0 ? 1:-1;
|
||||||
fillData.fill(Distance);
|
fillData.fill(Distance);
|
||||||
// Run a quick filter to smooth the data
|
// Run a quick filter to smooth the data
|
||||||
float sigma = 0.6;
|
float sigma = 0.6;
|
||||||
Array<float> H = imfilter::create_filter<float>( { 1 }, "gaussian", &sigma );
|
Array<float> H = imfilter::create_filter<float>( { 1 }, "gaussian", &sigma );
|
||||||
std::vector<imfilter::BC> BC(3,imfilter::BC::replicate);
|
std::vector<imfilter::BC> BC(3,imfilter::BC::replicate);
|
||||||
Distance = imfilter::imfilter_separable<float>( Distance, {H,H,H}, BC );
|
Distance = imfilter::imfilter_separable<float>( Distance, {H,H,H}, BC );
|
||||||
PROFILE_STOP("Calc Distance Multilevel");
|
PROFILE_STOP("Calc Distance Multilevel");
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -41,11 +41,11 @@ int main(int argc, char **argv)
|
|||||||
//.......................................................................
|
//.......................................................................
|
||||||
int nprocs, nprocx, nprocy, nprocz, nx, ny, nz, nspheres;
|
int nprocs, nprocx, nprocy, nprocz, nx, ny, nz, nspheres;
|
||||||
double Lx, Ly, Lz;
|
double Lx, Ly, Lz;
|
||||||
uint64_t Nx,Ny,Nz;
|
int64_t Nx,Ny,Nz;
|
||||||
uint64_t i,j,k,n;
|
int64_t i,j,k,n;
|
||||||
int BC=0;
|
int BC=0;
|
||||||
char Filename[40];
|
char Filename[40];
|
||||||
uint64_t xStart,yStart,zStart;
|
int64_t xStart,yStart,zStart;
|
||||||
// char fluidValue,solidValue;
|
// char fluidValue,solidValue;
|
||||||
|
|
||||||
std::vector<char> solidValues;
|
std::vector<char> solidValues;
|
||||||
@ -80,8 +80,8 @@ int main(int argc, char **argv)
|
|||||||
char *SegData = NULL;
|
char *SegData = NULL;
|
||||||
// Rank=0 reads the entire segmented data and distributes to worker processes
|
// Rank=0 reads the entire segmented data and distributes to worker processes
|
||||||
if (rank==0){
|
if (rank==0){
|
||||||
printf("Dimensions of segmented image: %i x %i x %i \n",Nx,Ny,Nz);
|
printf("Dimensions of segmented image: %ld x %ld x %ld \n",Nx,Ny,Nz);
|
||||||
uint64_t SIZE = Nx*Ny*Nz;
|
int64_t SIZE = Nx*Ny*Nz;
|
||||||
SegData = new char[SIZE];
|
SegData = new char[SIZE];
|
||||||
FILE *SEGDAT = fopen(Filename,"rb");
|
FILE *SEGDAT = fopen(Filename,"rb");
|
||||||
if (SEGDAT==NULL) ERROR("Error reading segmented data");
|
if (SEGDAT==NULL) ERROR("Error reading segmented data");
|
||||||
@ -93,10 +93,10 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the rank info
|
// Get the rank info
|
||||||
uint64_t N = (nx+2)*(ny+2)*(nz+2);
|
int64_t N = (nx+2)*(ny+2)*(nz+2);
|
||||||
|
|
||||||
// number of sites to use for periodic boundary condition transition zone
|
// number of sites to use for periodic boundary condition transition zone
|
||||||
uint64_t z_transition_size = (nprocz*nz - (Nz - zStart))/2;
|
int64_t z_transition_size = (nprocz*nz - (Nz - zStart))/2;
|
||||||
if (z_transition_size < 0) z_transition_size=0;
|
if (z_transition_size < 0) z_transition_size=0;
|
||||||
|
|
||||||
char LocalRankFilename[40];
|
char LocalRankFilename[40];
|
||||||
@ -108,7 +108,7 @@ int main(int argc, char **argv)
|
|||||||
printf("Distributing subdomains across %i processors \n",nprocs);
|
printf("Distributing subdomains across %i processors \n",nprocs);
|
||||||
printf("Process grid: %i x %i x %i \n",nprocx,nprocy,nprocz);
|
printf("Process grid: %i x %i x %i \n",nprocx,nprocy,nprocz);
|
||||||
printf("Subdomain size: %i x %i x %i \n",nx,ny,nz);
|
printf("Subdomain size: %i x %i x %i \n",nx,ny,nz);
|
||||||
printf("Size of transition region: %i \n", z_transition_size);
|
printf("Size of transition region: %ld \n", z_transition_size);
|
||||||
|
|
||||||
for (int kp=0; kp<nprocz; kp++){
|
for (int kp=0; kp<nprocz; kp++){
|
||||||
for (int jp=0; jp<nprocy; jp++){
|
for (int jp=0; jp<nprocy; jp++){
|
||||||
@ -119,14 +119,14 @@ int main(int argc, char **argv)
|
|||||||
for (k=0;k<nz+2;k++){
|
for (k=0;k<nz+2;k++){
|
||||||
for (j=0;j<ny+2;j++){
|
for (j=0;j<ny+2;j++){
|
||||||
for (i=0;i<nx+2;i++){
|
for (i=0;i<nx+2;i++){
|
||||||
uint64_t x = xStart + ip*nx + i-1;
|
int64_t x = xStart + ip*nx + i-1;
|
||||||
uint64_t y = yStart + jp*ny + j-1;
|
int64_t y = yStart + jp*ny + j-1;
|
||||||
// uint64_t z = zStart + kp*nz + k-1;
|
// int64_t z = zStart + kp*nz + k-1;
|
||||||
uint64_t z = zStart + kp*nz + k-1 - z_transition_size;
|
int64_t z = zStart + kp*nz + k-1 - z_transition_size;
|
||||||
if (z<zStart) z=zStart;
|
if (z<zStart) z=zStart;
|
||||||
if (!(z<Nz)) z=Nz-1;
|
if (!(z<Nz)) z=Nz-1;
|
||||||
uint64_t nlocal = k*(nx+2)*(ny+2) + j*(nx+2) + i;
|
int64_t nlocal = k*(nx+2)*(ny+2) + j*(nx+2) + i;
|
||||||
uint64_t nglobal = z*Nx*Ny+y*Nx+x;
|
int64_t nglobal = z*Nx*Ny+y*Nx+x;
|
||||||
loc_id[nlocal] = SegData[nglobal];
|
loc_id[nlocal] = SegData[nglobal];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -544,9 +544,8 @@ void ThreadPool::check_startup( size_t size0 )
|
|||||||
id2.reset( 3, d_id_assign, nullptr );
|
id2.reset( 3, d_id_assign, nullptr );
|
||||||
if ( isValid( id ) || !isValid( id2 ) )
|
if ( isValid( id ) || !isValid( id2 ) )
|
||||||
pass = false;
|
pass = false;
|
||||||
if ( !pass ) {
|
if ( !pass )
|
||||||
throw std::logic_error( "Thread pool failed to initialize" );
|
throw std::logic_error( "Thread pool failed to initialize" );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -584,8 +583,10 @@ void ThreadPool::initialize( const int N, const char *affinity, int N_procs, con
|
|||||||
******************************************************************/
|
******************************************************************/
|
||||||
ThreadPool::~ThreadPool()
|
ThreadPool::~ThreadPool()
|
||||||
{
|
{
|
||||||
if ( !is_valid( this ) )
|
if ( !is_valid( this ) ) {
|
||||||
throw std::logic_error( "Thread pool is not valid" );
|
std::cerr << "Thread pool is not valid\n";
|
||||||
|
std::terminate();
|
||||||
|
}
|
||||||
// Destroy the threads
|
// Destroy the threads
|
||||||
setNumThreads( 0 );
|
setNumThreads( 0 );
|
||||||
// Delete all remaining data
|
// Delete all remaining data
|
||||||
@ -593,8 +594,8 @@ ThreadPool::~ThreadPool()
|
|||||||
d_NULL_HEAD = 0;
|
d_NULL_HEAD = 0;
|
||||||
d_NULL_TAIL = 0;
|
d_NULL_TAIL = 0;
|
||||||
delete d_wait_last;
|
delete d_wait_last;
|
||||||
// Print the performance metrics
|
|
||||||
#if MONITOR_THREADPOOL_PERFORMANCE == 1
|
#if MONITOR_THREADPOOL_PERFORMANCE == 1
|
||||||
|
// Print the performance metrics
|
||||||
printp( "ThreadPool Performance:\n" );
|
printp( "ThreadPool Performance:\n" );
|
||||||
printp( "add_work: %lu us, %lu us, %lu us, %lu us, %lu us\n",
|
printp( "add_work: %lu us, %lu us, %lu us, %lu us, %lu us\n",
|
||||||
total_add_work_time[0]/1000, total_add_work_time[1]/1000,
|
total_add_work_time[0]/1000, total_add_work_time[1]/1000,
|
||||||
|
Loading…
Reference in New Issue
Block a user