Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/KOKKOS/pair_mliap_kokkos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ int PairMLIAPKokkos<DeviceType>::pack_forward_comm_kokkos(
const int i = start/nf;
const int gstart=idx(i)*nf;
const int j = start%nf;
val(start+j) = static_cast<double>(to[gstart+j]);
val(start) = static_cast<double>(to[gstart+j]);
}
);
return nv*nf;
Expand Down Expand Up @@ -500,7 +500,7 @@ void PairMLIAPKokkos<DeviceType>::unpack_forward_comm_kokkos(
const int i=start/nf;
const int gstart=(first_up+i)*nf;
const int j=start%nf;
to[gstart+j] = static_cast<CommType>(val(start+j));
to[gstart+j] = static_cast<CommType>(val(start));
}
);
}
Expand Down Expand Up @@ -563,7 +563,7 @@ int PairMLIAPKokkos<DeviceType>::pack_reverse_comm_kokkos(int nv, int first_up,
const int i = start/nf;
const int gstart=(first_up+i)*nf;
const int j = start%nf;
val(start+j) = static_cast<double>(to[gstart+j]);
val(start) = static_cast<double>(to[gstart+j]);
}
);
return nv*nf;
Expand Down Expand Up @@ -630,8 +630,8 @@ void PairMLIAPKokkos<DeviceType>::unpack_reverse_comm_kokkos(int nv, DAT::tdual_
Kokkos::parallel_for(nv*nf, KOKKOS_LAMBDA (int start) {
const int i = start/nf;
const int gstart=idx(i)*nf;
const int j=i%nf;
to[gstart+j] += static_cast<CommType>(val(start+j));
const int j=start%nf;
to[gstart+j] += static_cast<CommType>(val(start));
}
);
}
Expand Down
134 changes: 61 additions & 73 deletions src/KSPACE/remap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <cstdlib>
#include <cstring>
#include <exception>
#include <set>

#define PACK_DATA FFT_SCALAR
Expand Down Expand Up @@ -226,13 +227,11 @@ struct remap_plan_3d *remap_3d_create_plan(

// allocate memory for plan data struct

plan = (struct remap_plan_3d *) malloc(sizeof(struct remap_plan_3d));
if (plan == nullptr) return nullptr;

// zero out entire plan data structure including all pointers and set flags
memset(plan, 0, sizeof(struct remap_plan_3d));
plan->usecollective = usecollective;
plan->usenonblocking = usenonblocking;
try {
plan = new remap_plan_3d(usecollective, usenonblocking);
} catch (std::bad_alloc &) {
return nullptr;
}

// store parameters in local data structs

Expand Down Expand Up @@ -264,14 +263,14 @@ struct remap_plan_3d *remap_3d_create_plan(

inarray = (struct extent_3d *) malloc(nprocs*sizeof(struct extent_3d));
if (inarray == nullptr) {
free(plan);
delete plan;
return nullptr;
}

outarray = (struct extent_3d *) malloc(nprocs*sizeof(struct extent_3d));
if (outarray == nullptr) {
free(inarray);
free(plan);
delete plan;
return nullptr;
}

Expand Down Expand Up @@ -310,12 +309,7 @@ struct remap_plan_3d *remap_3d_create_plan(
if (plan->send_offset == nullptr || plan->send_size == nullptr ||
plan->send_proc == nullptr || plan->packplan == nullptr ||
(plan->usenonblocking && (plan->isend_reqs == nullptr)) || plan->send_bufloc == nullptr) {
if (plan->send_offset) free(plan->send_offset);
if (plan->send_size) free(plan->send_size);
if (plan->packplan) free(plan->packplan);
if (plan->isend_reqs) free(plan->isend_reqs);
if (plan->send_proc) free(plan->send_bufloc);
free(plan);
delete plan;
return nullptr;
}
}
Expand Down Expand Up @@ -350,17 +344,7 @@ struct remap_plan_3d *remap_3d_create_plan(
if (plan->recv_offset == nullptr || plan->recv_size == nullptr ||
plan->recv_proc == nullptr || plan->recv_bufloc == nullptr ||
plan->request == nullptr || plan->unpackplan == nullptr) {
if (plan->send_offset) free(plan->send_offset);
if (plan->send_size) free(plan->send_size);
if (plan->packplan) free(plan->packplan);
if (plan->isend_reqs) free(plan->isend_reqs);
if (plan->send_proc) free(plan->send_bufloc);
if (plan->recv_offset) free(plan->recv_offset);
if (plan->recv_size) free(plan->recv_size);
if (plan->recv_proc) free(plan->recv_proc);
if (plan->request) free(plan->request);
if (plan->unpackplan) free(plan->unpackplan);
free(plan);
delete plan;
return nullptr;
}
}
Expand Down Expand Up @@ -478,7 +462,7 @@ struct remap_plan_3d *remap_3d_create_plan(
if (size) {
plan->sendbuf = (FFT_SCALAR*) malloc(sizeof(FFT_SCALAR) * size);
if (plan->sendbuf == nullptr) {
free(plan);
delete plan;
return nullptr;
}
}
Expand All @@ -490,8 +474,7 @@ struct remap_plan_3d *remap_3d_create_plan(
if (nrecv > 0) {
plan->scratch = (FFT_SCALAR*) malloc(sizeof(FFT_SCALAR) * nqty*out.isize*out.jsize*out.ksize);
if (plan->scratch == nullptr) {
if (plan->sendbuf) free(plan->sendbuf);
free(plan);
delete plan;
return nullptr;
}
}
Expand Down Expand Up @@ -584,12 +567,7 @@ struct remap_plan_3d *remap_3d_create_plan(
if (plan->send_offset == nullptr || plan->send_size == nullptr ||
plan->sendcnts == nullptr || plan->sdispls == nullptr ||
plan->packplan == nullptr) {
if (plan->send_offset) free(plan->send_offset);
if (plan->send_size) free(plan->send_size);
if (plan->sendcnts) free(plan->sendcnts);
if (plan->sdispls) free(plan->sdispls);
if (plan->packplan) free(plan->packplan);
free(plan);
delete plan;
return nullptr;
}

Expand Down Expand Up @@ -630,17 +608,7 @@ struct remap_plan_3d *remap_3d_create_plan(
if (plan->recv_offset == nullptr || plan->recv_size == nullptr ||
plan->rcvcnts == nullptr || plan->rdispls == nullptr ||
plan->unpackplan == nullptr) {
if (plan->send_offset) free(plan->send_offset);
if (plan->send_size) free(plan->send_size);
if (plan->sendcnts) free(plan->sendcnts);
if (plan->sdispls) free(plan->sdispls);
if (plan->packplan) free(plan->packplan);
if (plan->recv_offset) free(plan->recv_offset);
if (plan->recv_size) free(plan->recv_size);
if (plan->rcvcnts) free(plan->rcvcnts);
if (plan->rdispls) free(plan->rdispls);
if (plan->unpackplan) free(plan->unpackplan);
free(plan);
delete plan;
return nullptr;
}
}
Expand Down Expand Up @@ -748,7 +716,7 @@ struct remap_plan_3d *remap_3d_create_plan(
if (nrecv > 0) {
plan->scratch = (FFT_SCALAR*) malloc(nqty*out.isize*out.jsize*out.ksize*sizeof(FFT_SCALAR));
if (plan->scratch == nullptr) {
free(plan);
delete plan;
return nullptr;
}
}
Expand Down Expand Up @@ -796,34 +764,9 @@ void remap_3d_destroy_plan(struct remap_plan_3d *plan)
if (!((plan->usecollective) && (plan->commringlen == 0)))
MPI_Comm_free(&plan->comm);

// free allocated buffers
#define SAFE_FREE(ptr) if (ptr) free(ptr)

SAFE_FREE(plan->commringlist);
SAFE_FREE(plan->isend_reqs);
SAFE_FREE(plan->packplan);
SAFE_FREE(plan->rcvcnts);
SAFE_FREE(plan->rdispls);
SAFE_FREE(plan->recv_bufloc);
SAFE_FREE(plan->recv_offset);
SAFE_FREE(plan->recv_proc);
SAFE_FREE(plan->recv_size);
SAFE_FREE(plan->request);
SAFE_FREE(plan->scratch);
SAFE_FREE(plan->sdispls);
SAFE_FREE(plan->send_bufloc);
SAFE_FREE(plan->send_offset);
SAFE_FREE(plan->send_proc);
SAFE_FREE(plan->send_size);
SAFE_FREE(plan->sendbuf);
SAFE_FREE(plan->sendcnts);
SAFE_FREE(plan->unpackplan);

#undef SAFE_FREE

// free the plan itself

free(plan);
delete plan;
}

/* ----------------------------------------------------------------------
Expand Down Expand Up @@ -854,3 +797,48 @@ int remap_3d_collide(struct extent_3d *block1, struct extent_3d *block2,

return 1;
}

// clang-format on
/* 3d remap plan custom constructor. must make certain all pointers are initialized to null */

remap_plan_3d::remap_plan_3d(int _usecollective, int _usenonblocking) :
sendbuf(nullptr), scratch(nullptr), pack(nullptr), unpack(nullptr), send_offset(nullptr),
send_size(nullptr), send_proc(nullptr), send_bufloc(nullptr), isend_reqs(nullptr),
packplan(nullptr), recv_offset(nullptr), recv_size(nullptr), recv_proc(nullptr),
recv_bufloc(nullptr), request(nullptr), unpackplan(nullptr), commringlist(nullptr),
sendcnts(nullptr), rcvcnts(nullptr), sdispls(nullptr), rdispls(nullptr)
{
usecollective = _usecollective;
usenonblocking = _usenonblocking;
nrecv = nsend = self = memory = usecollective = usenonblocking = commringlen = 0;
comm = MPI_COMM_NULL;
}

/* 3d remap plan destructor. free all allocated storage */
remap_plan_3d::~remap_plan_3d()
{
// free any allocated (= non-null) buffers
#define SAFE_FREE(ptr) \
if (ptr) free(ptr)

SAFE_FREE(sendbuf);
SAFE_FREE(scratch);
SAFE_FREE(send_offset);
SAFE_FREE(send_size);
SAFE_FREE(send_proc);
SAFE_FREE(send_bufloc);
SAFE_FREE(isend_reqs);
SAFE_FREE(packplan);
SAFE_FREE(recv_offset);
SAFE_FREE(recv_size);
SAFE_FREE(recv_proc);
SAFE_FREE(recv_bufloc);
SAFE_FREE(request);
SAFE_FREE(unpackplan);
SAFE_FREE(commringlist);
SAFE_FREE(sendcnts);
SAFE_FREE(rcvcnts);
SAFE_FREE(rdispls);
SAFE_FREE(sdispls);
#undef SAFE_FREE
}
17 changes: 13 additions & 4 deletions src/KSPACE/remap.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
// details of how to do a 3d remap

struct remap_plan_3d {
remap_plan_3d(int, int);
~remap_plan_3d();

remap_plan_3d() = delete;
remap_plan_3d(const remap_plan_3d &) = delete;
remap_plan_3d(remap_plan_3d &&) = delete;
remap_plan_3d &operator=(const remap_plan_3d &) = delete;
remap_plan_3d &operator=(remap_plan_3d &&) = delete;

FFT_SCALAR *sendbuf; // buffer for MPI sends
FFT_SCALAR *scratch; // scratch buffer for MPI recvs
void (*pack)(FFT_SCALAR *, FFT_SCALAR *, struct pack_plan_3d *);
Expand Down Expand Up @@ -45,10 +54,10 @@ struct remap_plan_3d {
int usenonblocking; // if using point-to-point MPI, use MPI_Isend
int commringlen; // length of commringlist
int *commringlist; // ranks on communication ring of this plan
int *sendcnts; // # of elements in send buffer for each rank
int *rcvcnts; // # of elements in recv buffer for each rank
int *sdispls; // extraction location in send buffer for each rank
int *rdispls; // extraction location in recv buffer for each rank
int *sendcnts; // # of elements in send buffer for each rank
int *rcvcnts; // # of elements in recv buffer for each rank
int *sdispls; // extraction location in send buffer for each rank
int *rdispls; // extraction location in recv buffer for each rank
};

// collision between 2 regions
Expand Down
6 changes: 3 additions & 3 deletions src/pointers.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ class Pointers {
Pointers() = delete;
Pointers(const Pointers &) = default;
Pointers(Pointers &&) = delete;
Pointers & operator=(const Pointers&) = delete;
Pointers & operator=(Pointers&&) = delete;
Pointers &operator=(const Pointers &) = delete;
Pointers &operator=(Pointers &&) = delete;

protected:
LAMMPS *lmp;
Expand Down Expand Up @@ -133,6 +133,6 @@ class Pointers {
class Python *&python;
};

}
} // namespace LAMMPS_NS

#endif