simplify intel versions of electrode fixes

This commit is contained in:
Shern Ren Tee
2023-01-03 12:29:45 +10:00
parent f84b64bc86
commit 8610fc6d33
13 changed files with 53 additions and 169 deletions

View File

@ -112,9 +112,5 @@ if(PKG_KSPACE)
RegisterIntegrateStyle(${INTEL_SOURCES_DIR}/verlet_lrt_intel.h)
endif()
if(PKG_ELECTRODE)
list(APPEND INTEL_SOURCES ${INTEL_SOURCES_DIR}/electrode_accel_intel.cpp)
endif()
target_sources(lammps PRIVATE ${INTEL_SOURCES})
target_include_directories(lammps PRIVATE ${INTEL_SOURCES_DIR})

View File

@ -1,33 +0,0 @@
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
LAMMPS development team: developers@lammps.org
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing authors: Ludwig Ahrens-Iwers (TUHH), Shern Tee (UQ), Robert Meißner (TUHH)
------------------------------------------------------------------------- */
#ifndef LMP_ELECTRODE_ACCEL_INTERFACE_H
#define LMP_ELECTRODE_ACCEL_INTERFACE_H
#include "pointers.h"
namespace LAMMPS_NS {
class ElectrodeAccelInterface : protected Pointers {
public:
ElectrodeAccelInterface(class LAMMPS *lmp) : Pointers(lmp) {}
virtual void intel_find_fix() {}
virtual void intel_pack_buffers() {}
};
} // namespace LAMMPS_NS
#endif

View File

@ -21,7 +21,6 @@
#include "citeme.h"
#include "comm.h"
#include "domain.h"
#include "electrode_accel_interface.h"
#include "electrode_math.h"
#include "electrode_matrix.h"
#include "electrode_vector.h"
@ -272,8 +271,6 @@ FixElectrodeConp::FixElectrodeConp(LAMMPS *lmp, int narg, char **arg) :
groupbit = group->bitmask[igroup];
ngroup = group->count(igroup);
accel_interface = std::unique_ptr<ElectrodeAccelInterface>(new ElectrodeAccelInterface(lmp));
if (matrix_algo) {
memory->create(iele_gathered, ngroup, "FixElectrode:iele_gathered");
memory->create(buf_gathered, ngroup, "FixElectrode:buf_gathered");
@ -381,7 +378,6 @@ void FixElectrodeConp::init()
if (count > 1) error->all(FLERR, "More than one fix electrode");
// check for package intel
accel_interface->intel_find_fix();
if (etypes_neighlists)
request_etypes_neighlists();
else {
@ -795,7 +791,6 @@ void FixElectrodeConp::update_charges()
double *q = atom->q;
gather_list_iele();
pre_update();
accel_interface->intel_pack_buffers(); // update buffers for pppmintel to compute potential
auto q_local = std::vector<double>(nlocalele, 0.);
if (algo == Algo::MATRIX_INV) {
std::fill(sb_charges.begin(), sb_charges.end(), 0.);
@ -866,7 +861,6 @@ void FixElectrodeConp::update_charges()
}
set_charges(q_local);
update_time += MPI_Wtime() - start;
accel_interface->intel_pack_buffers();
}
std::vector<double> FixElectrodeConp::ele_ele_interaction(const std::vector<double>& q_local)
@ -889,7 +883,7 @@ void FixElectrodeConp::set_charges(std::vector<double> q_local)
double *q = atom->q;
for (int i = 0; i < nlocalele; i++) q[atom->map(taglist_local[i])] = q_local[i];
comm->forward_comm(this);
accel_interface->intel_pack_buffers();
intel_pack_buffers();
}
/* ---------------------------------------------------------------------- */

View File

@ -35,7 +35,6 @@ FixStyle(electrode/conp, FixElectrodeConp);
namespace LAMMPS_NS {
// forward decls
class ElectrodeAccelInterface;
class ElectrodeVector;
class NeighList;
class Pair;
@ -56,7 +55,7 @@ class FixElectrodeConp : public Fix {
double compute_array(int, int) override;
int modify_param(int, char **) override;
int modify_param(const std::string &);
void init() override;
virtual void init() override;
void init_list(int, NeighList *) override;
void post_constructor() override; // used by ffield to set up fix efield
double memory_usage() override;
@ -101,7 +100,7 @@ class FixElectrodeConp : public Fix {
bool ffield; // possibly tweak electrode/conq's version
std::string fixname; // used by electrode/ffield to set up internal efield
bool intelflag;
std::unique_ptr<ElectrodeAccelInterface> accel_interface; // used by /intel
inline virtual void intel_pack_buffers() {}
private:
std::string output_file_inv, output_file_mat, output_file_vec;

View File

@ -1,65 +0,0 @@
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/ Sandia National Laboratories
LAMMPS development team: developers@lammps.org
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "electrode_accel_intel.h"
#include "comm.h"
#include "fix_intel.h"
#include "intel_buffers.h"
#include "modify.h"
using namespace LAMMPS_NS;
ElectrodeAccelIntel::ElectrodeAccelIntel(class LAMMPS *lmp) : ElectrodeAccelInterface(lmp) {}
void ElectrodeAccelIntel::intel_find_fix()
{
int ifix = modify->find_fix("package_intel");
if (ifix < 0) error->all(FLERR, "The 'package intel' command is required for /intel styles");
fix = static_cast<FixIntel *>(modify->fix[ifix]);
}
void ElectrodeAccelIntel::intel_pack_buffers()
{
switch (fix->precision()) {
case FixIntel::PREC_MODE_MIXED:
intel_pack_buffers_prec<float, double>(fix->get_mixed_buffers());
break;
case FixIntel::PREC_MODE_DOUBLE:
intel_pack_buffers_prec<double, double>(fix->get_double_buffers());
break;
default: // FixIntel::PREC_MODE_SINGLE
intel_pack_buffers_prec<float, float>(fix->get_single_buffers());
}
}
template <class flt_t, class acc_t>
void ElectrodeAccelIntel::intel_pack_buffers_prec(IntelBuffers<flt_t, acc_t> *buffers)
{
fix->start_watch(TIME_PACK);
int packthreads;
if (comm->nthreads > INTEL_HTHREADS)
packthreads = comm->nthreads;
else
packthreads = 1;
#if defined(_OPENMP)
#pragma omp parallel if (packthreads > 1)
#endif
{
int ifrom, ito, tid;
IP_PRE_omp_range_id_align(ifrom, ito, tid, atom->nlocal + atom->nghost, packthreads,
sizeof(ATOM_T));
buffers->thr_pack(ifrom, ito, 0);
}
fix->stop_watch(TIME_PACK);
}

View File

@ -1,37 +0,0 @@
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/ Sandia National Laboratories
LAMMPS development team: developers@lammps.org
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#ifndef LMP_ELECTRODE_ACCEL_INTEL_H
#define LMP_ELECTRODE_ACCEL_INTEL_H
#include "electrode_accel_interface.h"
#include "fix_intel.h"
#include "intel_buffers.h"
namespace LAMMPS_NS {
class ElectrodeAccelIntel : public ElectrodeAccelInterface {
public:
ElectrodeAccelIntel(class LAMMPS *lmp);
void intel_find_fix() override;
void intel_pack_buffers() override;
private:
class FixIntel *fix;
template <class flt_t, class acc_t>
void intel_pack_buffers_prec(IntelBuffers<flt_t, acc_t> *buffers);
};
} // namespace LAMMPS_NS
#endif

View File

@ -26,18 +26,27 @@ FixStyle(electrode/conp/intel, FixElectrodeConpIntel)
#ifndef LMP_FIX_ELECTRODE_CONP_INTEL_H
#define LMP_FIX_ELECTRODE_CONP_INTEL_H
#include "electrode_accel_intel.h"
#include "fix_electrode_conp.h"
#include "pppm_intel.h"
namespace LAMMPS_NS {
class FixElectrodeConpIntel : public FixElectrodeConp {
public:
FixElectrodeConpIntel(class LAMMPS *lmp, int narg, char **arg) : FixElectrodeConp(lmp, narg, arg)
{
FixElectrodeConpIntel(class LAMMPS *lmp, int narg, char **arg) : FixElectrodeConp(lmp, narg, arg) {}
inline void init() final override {
_intel_kspace = dynamic_cast<PPPMIntel*>(force->kspace_match("pppm/electrode/intel", 0));
if (_intel_kspace == nullptr) error->all(FLERR, "pppm/electrode/intel is required by fix electrode/conp/intel");
intelflag = true;
accel_interface = std::unique_ptr<ElectrodeAccelInterface>(new ElectrodeAccelIntel(lmp));
FixElectrodeConp::init();
}
inline void intel_pack_buffers() final override {
_intel_kspace->pack_buffers(0);
}
private:
PPPMIntel * _intel_kspace;
};
} // namespace LAMMPS_NS

View File

@ -26,20 +26,30 @@ FixStyle(electrode/conq/intel, FixElectrodeConqIntel)
#ifndef LMP_FIX_ELECTRODE_CONQ_INTEL_H
#define LMP_FIX_ELECTRODE_CONQ_INTEL_H
#include "electrode_accel_intel.h"
#include "fix_electrode_conq.h"
#include "pppm_intel.h"
namespace LAMMPS_NS {
class FixElectrodeConqIntel : public FixElectrodeConq {
public:
FixElectrodeConqIntel(class LAMMPS *lmp, int narg, char **arg) : FixElectrodeConq(lmp, narg, arg)
{
FixElectrodeConqIntel(class LAMMPS *lmp, int narg, char **arg) : FixElectrodeConq(lmp, narg, arg) {}
inline void init() final override {
_intel_kspace = dynamic_cast<PPPMIntel*>(force->kspace_match("pppm/electrode/intel", 0));
if (_intel_kspace == nullptr) error->all(FLERR, "pppm/electrode/intel is required by fix electrode/conq/intel");
intelflag = true;
accel_interface = std::unique_ptr<ElectrodeAccelInterface>(new ElectrodeAccelIntel(lmp));
FixElectrodeConq::init();
}
inline void intel_pack_buffers() final override {
_intel_kspace->pack_buffers(0);
}
private:
PPPMIntel * _intel_kspace;
};
} // namespace LAMMPS_NS
#endif

View File

@ -26,19 +26,27 @@ FixStyle(electrode/thermo/intel, FixElectrodeThermoIntel)
#ifndef LMP_FIX_ELECTRODE_THERMO_INTEL_H
#define LMP_FIX_ELECTRODE_THERMO_INTEL_H
#include "electrode_accel_intel.h"
#include "fix_electrode_thermo.h"
#include "pppm_intel.h"
namespace LAMMPS_NS {
class FixElectrodeThermoIntel : public FixElectrodeThermo {
public:
FixElectrodeThermoIntel(class LAMMPS *lmp, int narg, char **arg) :
FixElectrodeThermo(lmp, narg, arg)
{
FixElectrodeThermoIntel(class LAMMPS *lmp, int narg, char **arg) : FixElectrodeThermo(lmp, narg, arg) {}
inline void init() final override {
_intel_kspace = dynamic_cast<PPPMIntel*>(force->kspace_match("pppm/electrode/intel", 0));
if (_intel_kspace == nullptr) error->all(FLERR, "pppm/electrode/intel is required by fix electrode/thermo/intel");
intelflag = true;
accel_interface = std::unique_ptr<ElectrodeAccelInterface>(new ElectrodeAccelIntel(lmp));
FixElectrodeThermo::init();
}
inline void intel_pack_buffers() final override {
_intel_kspace->pack_buffers(0);
}
private:
PPPMIntel * _intel_kspace;
};
} // namespace LAMMPS_NS

View File

@ -338,6 +338,7 @@ void PPPMElectrodeIntel::compute_vector(double *vec, int sensor_grpbit, int sour
// electrolyte density (without writing an additional function)
FFT_SCALAR ***density_brick_real = density_brick;
FFT_SCALAR *density_fft_real = density_fft;
pack_buffers(1); // update positions if called before pair_compute
switch (fix->precision()) {
case FixIntel::PREC_MODE_MIXED:
make_rho_in_brick<float, double>(fix->get_mixed_buffers(), source_grpbit,

View File

@ -1052,7 +1052,8 @@ double PPPMIntel::memory_usage()
Pack data into intel package buffers if using LRT mode
------------------------------------------------------------------------- */
void PPPMIntel::pack_buffers()
void PPPMIntel::pack_buffers(int ago)
// VerletLRTIntel uses ago 1, fix electrode/*/intel uses ago 0
{
fix->start_watch(TIME_PACK);
int packthreads;
@ -1067,11 +1068,11 @@ void PPPMIntel::pack_buffers()
packthreads,
sizeof(IntelBuffers<float,double>::atom_t));
if (fix->precision() == FixIntel::PREC_MODE_MIXED)
fix->get_mixed_buffers()->thr_pack(ifrom,ito,1);
fix->get_mixed_buffers()->thr_pack(ifrom,ito,ago);
else if (fix->precision() == FixIntel::PREC_MODE_DOUBLE)
fix->get_double_buffers()->thr_pack(ifrom,ito,1);
fix->get_double_buffers()->thr_pack(ifrom,ito,ago);
else
fix->get_single_buffers()->thr_pack(ifrom,ito,1);
fix->get_single_buffers()->thr_pack(ifrom,ito,ago);
}
fix->stop_watch(TIME_PACK);
}

View File

@ -42,7 +42,7 @@ class PPPMIntel : public PPPM {
double memory_usage() override;
void compute_first(int, int);
void compute_second(int, int);
void pack_buffers();
void pack_buffers(int);
#ifdef _LMP_INTEL_OFFLOAD
int use_base();

View File

@ -67,7 +67,8 @@ void VerletLRTIntel::init()
{
Verlet::init();
_intel_kspace = dynamic_cast<PPPMIntel*>(force->kspace_match("^pppm/intel", 0));
_intel_kspace = dynamic_cast<PPPMIntel*>(force->kspace_match("^pppm\..*intel$", 0));
// include pppm/electrode/intel
#ifndef LMP_INTEL_USELRT
error->all(FLERR,
@ -252,7 +253,7 @@ void VerletLRTIntel::run(int n)
timer->stamp();
comm->forward_comm();
timer->stamp(Timer::COMM);
_intel_kspace->pack_buffers();
_intel_kspace->pack_buffers(1);
} else {
if (n_pre_exchange) {
timer->stamp();