Skip to content

Commit

Permalink
Merge branch 'development' into particle_refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
atmyers committed Mar 5, 2017
2 parents 23b4c68 + e1dc6e2 commit da72b07
Show file tree
Hide file tree
Showing 94 changed files with 18,620 additions and 743 deletions.
72 changes: 39 additions & 33 deletions Src/Base/AMReX_BaseFab.H
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace amrex
long TotalCellsAllocatedInFabs();
long TotalCellsAllocatedInFabsHWM();
void ResetTotalBytesAllocatedInFabsHWM();
void update_fab_stats (long n, long s, size_t szt);
void update_fab_stats (long n, long s, std::size_t szt);

/**
* \brief A Fortran Array-like Object
Expand Down Expand Up @@ -133,7 +133,11 @@ public:
void clear ();

//! Returns how many bytes used
size_t nBytes () const { return truesize*sizeof(T); }
std::size_t nBytes () const { return truesize*sizeof(T); }

//! Returns bytes used in the Box for those components
std::size_t nBytes (const Box& bx, int start_comp, int ncomps) const
{ return bx.numPts() * sizeof(T) * ncomps; }

//! Returns the number of components
int nComp () const { return nvar; }
Expand Down Expand Up @@ -328,24 +332,16 @@ public:
*/
BaseFab<T>& copy (const BaseFab<T>& src);

/**
* \brief A specialized version of copy() that copies from a FAB to a raw memory
* destination. Basically a memcpy() that works with a FAB as source.
* It is the user's responsibility to ensure that dest has enough space
* to hold the copy.
*/
void copyToMem (const Box& srcbox,
int srccomp,
int numcomp,
T* dst) const;
/**
* \brief A specialized version of copy() that copies from raw memory to a FAB.
* Basically a memcpy() that works with a FAB as destination.
*/
void copyFromMem (const Box& dstbox,
int dstcomp,
int numcomp,
const T* src);
//! Copy from the srcbox of this Fab to raw memory and return the number of bytes copied
std::size_t copyToMem (const Box& srcbox,
int srccomp,
int numcomp,
void* dst) const;
//! Copy from raw memory to the dstbox of this Fab and return the number of bytes copied
std::size_t copyFromMem (const Box& dstbox,
int dstcomp,
int numcomp,
const void* src);
/**
* \brief Perform shifts upon the domain of the BaseFab. They are
* completely analogous to the corresponding Box functions.
Expand Down Expand Up @@ -1407,11 +1403,11 @@ BaseFab<T>::performSetVal (T val,
}

template <class T>
void
std::size_t
BaseFab<T>::copyToMem (const Box& srcbox,
int srccomp,
int numcomp,
T* dst) const
void* dst) const
{
BL_ASSERT(box().contains(srcbox));
BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= nComp());
Expand All @@ -1423,7 +1419,7 @@ BaseFab<T>::copyToMem (const Box& srcbox,
IntVect _subbox_length = srcbox.size();
const int* _subbox_len = _subbox_length.getVect();
const int* _bx_lo = (srcbox).loVect();
T* _th_p = dst;
T* _th_p = static_cast<T*>(dst);
const T* _x_p = dataPtr(srccomp);

#if (BL_SPACEDIM == 1)
Expand Down Expand Up @@ -1478,15 +1474,20 @@ BaseFab<T>::copyToMem (const Box& srcbox,
}
}
#endif
return sizeof(T)*numcomp*srcbox.numPts();
}
else
{
return 0;
}
}

template <class T>
void
BaseFab<T>::copyFromMem (const Box& dstbox,
int dstcomp,
int numcomp,
const T* src)
std::size_t
BaseFab<T>::copyFromMem (const Box& dstbox,
int dstcomp,
int numcomp,
const void* src)
{
BL_ASSERT(box().contains(dstbox));
BL_ASSERT(dstcomp >= 0 && dstcomp+numcomp <= nComp());
Expand All @@ -1498,7 +1499,7 @@ BaseFab<T>::copyFromMem (const Box& dstbox,
IntVect _subbox_length = dstbox.size();
const int* _subbox_len = _subbox_length.getVect();
const int* _bx_lo = (dstbox).loVect();
const T* _th_p = src;
const T* _th_p = static_cast<const T*>(src);
T* _x_p = dataPtr(dstcomp);

#if (BL_SPACEDIM == 1)
Expand Down Expand Up @@ -1549,6 +1550,11 @@ BaseFab<T>::copyFromMem (const Box& dstbox,
}
}
#endif
return sizeof(T)*numcomp*dstbox.numPts();
}
else
{
return 0;
}
}

Expand All @@ -1572,17 +1578,17 @@ BaseFab<Real>::performCopy (const BaseFab<Real>& src,
int destcomp,
int numcomp);
template <>
void
std::size_t
BaseFab<Real>::copyToMem (const Box& srcbox,
int srccomp,
int numcomp,
Real* dst) const;
void* dst) const;
template <>
void
std::size_t
BaseFab<Real>::copyFromMem (const Box& dstbox,
int dstcomp,
int numcomp,
const Real* src);
const void* src);
template <>
void
BaseFab<Real>::performSetVal (Real val,
Expand Down
32 changes: 21 additions & 11 deletions Src/Base/AMReX_BaseFab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,39 +187,49 @@ BaseFab<Real>::performCopy (const BaseFab<Real>& src,
}

template <>
void
std::size_t
BaseFab<Real>::copyToMem (const Box& srcbox,
int srccomp,
int numcomp,
Real* dst) const
void* dst) const
{
BL_ASSERT(box().contains(srcbox));
BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= nComp());

if (srcbox.ok())
{
fort_fab_copytomem(ARLIM_3D(srcbox.loVect()), ARLIM_3D(srcbox.hiVect()),
dst,
BL_TO_FORTRAN_N_3D(*this,srccomp),
&numcomp);
long nreal = fort_fab_copytomem(ARLIM_3D(srcbox.loVect()), ARLIM_3D(srcbox.hiVect()),
static_cast<Real*>(dst),
BL_TO_FORTRAN_N_3D(*this,srccomp),
&numcomp);
return sizeof(Real) * nreal;
}
else
{
return 0;
}
}

template <>
void
std::size_t
BaseFab<Real>::copyFromMem (const Box& dstbox,
int dstcomp,
int numcomp,
const Real* src)
const void* src)
{
BL_ASSERT(box().contains(dstbox));
BL_ASSERT(dstcomp >= 0 && dstcomp+numcomp <= nComp());

if (dstbox.ok())
{
fort_fab_copyfrommem(ARLIM_3D(dstbox.loVect()), ARLIM_3D(dstbox.hiVect()),
BL_TO_FORTRAN_N_3D(*this,dstcomp), &numcomp,
src);
long nreal = fort_fab_copyfrommem(ARLIM_3D(dstbox.loVect()), ARLIM_3D(dstbox.hiVect()),
BL_TO_FORTRAN_N_3D(*this,dstcomp), &numcomp,
static_cast<const Real*>(src));
return sizeof(Real) * nreal;
}
else
{
return 0;
}
}

Expand Down
16 changes: 8 additions & 8 deletions Src/Base/AMReX_BaseFab_f.H
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ extern "C"
const amrex::Real* src, const int* slo, const int* shi, const int* sblo,
const int* ncomp);

void fort_fab_copytomem (const int* lo, const int* hi,
amrex::Real* dst,
const amrex::Real* src, const int* slo, const int* shi,
const int* ncomp);

void fort_fab_copyfrommem (const int* lo, const int* hi,
const amrex::Real* dst, const int* dlo, const int* dhi, const int* ncomp,
const amrex::Real* src);
long fort_fab_copytomem (const int* lo, const int* hi,
amrex::Real* dst,
const amrex::Real* src, const int* slo, const int* shi,
const int* ncomp);

long fort_fab_copyfrommem (const int* lo, const int* hi,
const amrex::Real* dst, const int* dlo, const int* dhi, const int* ncomp,
const amrex::Real* src);

void fort_fab_setval (const int* lo, const int* hi,
const amrex::Real* dst, const int* dlo, const int* dhi, const int* ncomp,
Expand Down
23 changes: 17 additions & 6 deletions Src/Base/AMReX_BaseFab_nd.f90
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ end subroutine fort_fab_copy


! copy from multi-d array to 1d array
subroutine fort_fab_copytomem (lo, hi, dst, src, slo, shi, ncomp) &
function fort_fab_copytomem (lo, hi, dst, src, slo, shi, ncomp) result(nelems) &
bind(c,name='fort_fab_copytomem')
use iso_c_binding, only : c_long
integer(c_long) :: nelems
integer, intent(in) :: lo(3), hi(3), slo(3), shi(3), ncomp
real(amrex_real) :: dst(*)
real(amrex_real), intent(in) :: src(slo(1):shi(1),slo(2):shi(2),slo(3):shi(3),ncomp)

integer :: i, j, k, n, nx, offset
integer :: i, j, k, n, nx
integer(c_long) :: offset

nx = hi(1)-lo(1)+1
offset = 1-lo(1)
Expand All @@ -50,17 +53,22 @@ subroutine fort_fab_copytomem (lo, hi, dst, src, slo, shi, ncomp) &
end do
end do
end do
end subroutine fort_fab_copytomem

nelems = offset - (1-lo(1))
end function fort_fab_copytomem


! copy from 1d array to multi-d array
subroutine fort_fab_copyfrommem (lo, hi, dst, dlo, dhi, ncomp, src) &
function fort_fab_copyfrommem (lo, hi, dst, dlo, dhi, ncomp, src) result(nelems) &
bind(c,name='fort_fab_copyfrommem')
use iso_c_binding, only : c_long
integer(c_long) :: nelems
integer, intent(in) :: lo(3), hi(3), dlo(3), dhi(3), ncomp
real(amrex_real), intent(in ) :: src(*)
real(amrex_real), intent(inout) :: dst(dlo(1):dhi(1),dlo(2):dhi(2),dlo(3):dhi(3),ncomp)

integer :: i, j, k, n, nx, offset
integer :: i, j, k, n, nx
integer(c_long) :: offset

nx = hi(1)-lo(1)+1
offset = 1-lo(1)
Expand All @@ -74,7 +82,10 @@ subroutine fort_fab_copyfrommem (lo, hi, dst, dlo, dhi, ncomp, src) &
end do
end do
end do
end subroutine fort_fab_copyfrommem

nelems = offset - (1-lo(1))
end function fort_fab_copyfrommem



subroutine fort_fab_setval(lo, hi, dst, dlo, dhi, ncomp, val) &
Expand Down
3 changes: 2 additions & 1 deletion Src/Base/AMReX_DistributionMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2585,7 +2585,8 @@ Array<int>
DistributionMapping::TranslateProcMap(const Array<int> &pm_old, const MPI_Group group_new, const MPI_Group group_old)
{
Array<int> pm_new(pm_old.size());
BL_MPI_REQUIRE( MPI_Group_translate_ranks(group_old, pm_old.size(), pm_old.dataPtr(), group_new, pm_new.dataPtr()) );
int* castptr = (int *) pm_old.dataPtr();
BL_MPI_REQUIRE( MPI_Group_translate_ranks(group_old, pm_old.size(), castptr, group_new, pm_new.dataPtr()) );
return pm_new;
}
#endif
Expand Down
Loading

0 comments on commit da72b07

Please sign in to comment.