properly use nullptr on pointers (with a little help from clang-tidy)

This commit is contained in:
Axel Kohlmeyer
2022-04-09 20:27:40 -04:00
parent 07bc76871c
commit ddf67ec42d
13 changed files with 44 additions and 44 deletions

View File

@ -71,11 +71,11 @@ FixIntel::FixIntel(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg)
_offload_threads = 0; _offload_threads = 0;
_offload_tpc = 4; _offload_tpc = 4;
_force_array_s = 0; _force_array_s = nullptr;
_force_array_m = 0; _force_array_m = nullptr;
_force_array_d = 0; _force_array_d = nullptr;
_ev_array_s = 0; _ev_array_s = nullptr;
_ev_array_d = 0; _ev_array_d = nullptr;
#ifdef _LMP_INTEL_OFFLOAD #ifdef _LMP_INTEL_OFFLOAD
if (ncops < 0) error->all(FLERR,"Illegal package intel command"); if (ncops < 0) error->all(FLERR,"Illegal package intel command");
@ -557,30 +557,30 @@ void FixIntel::_sync_main_arrays(const int prereverse)
if (!prereverse) _zero_master = 1; if (!prereverse) _zero_master = 1;
int done_this_step = prereverse; int done_this_step = prereverse;
if (_pair_hybrid_zero == 0) done_this_step = 1; if (_pair_hybrid_zero == 0) done_this_step = 1;
if (_force_array_m != 0) { if (_force_array_m != nullptr) {
if (_need_reduce) { if (_need_reduce) {
reduce_results(&_force_array_m[0].x); reduce_results(&_force_array_m[0].x);
_need_reduce = 0; _need_reduce = 0;
} }
add_results(_force_array_m, _ev_array_d, _results_eatom, _results_vatom,0); add_results(_force_array_m, _ev_array_d, _results_eatom, _results_vatom,0);
if (done_this_step) _force_array_m = 0; if (done_this_step) _force_array_m = nullptr;
else _ev_array_d = 0; else _ev_array_d = nullptr;
} else if (_force_array_d != 0) { } else if (_force_array_d != nullptr) {
if (_need_reduce) { if (_need_reduce) {
reduce_results(&_force_array_d[0].x); reduce_results(&_force_array_d[0].x);
_need_reduce = 0; _need_reduce = 0;
} }
add_results(_force_array_d, _ev_array_d, _results_eatom, _results_vatom,0); add_results(_force_array_d, _ev_array_d, _results_eatom, _results_vatom,0);
if (done_this_step) _force_array_d = 0; if (done_this_step) _force_array_d = nullptr;
else _ev_array_d = 0; else _ev_array_d = nullptr;
} else if (_force_array_s != 0) { } else if (_force_array_s != nullptr) {
if (_need_reduce) { if (_need_reduce) {
reduce_results(&_force_array_s[0].x); reduce_results(&_force_array_s[0].x);
_need_reduce = 0; _need_reduce = 0;
} }
add_results(_force_array_s, _ev_array_s, _results_eatom, _results_vatom,0); add_results(_force_array_s, _ev_array_s, _results_eatom, _results_vatom,0);
if (done_this_step) _force_array_s = 0; if (done_this_step) _force_array_s = nullptr;
else _ev_array_s = 0; else _ev_array_s = nullptr;
} }
#ifdef _LMP_INTEL_OFFLOAD #ifdef _LMP_INTEL_OFFLOAD

View File

@ -46,7 +46,7 @@ typedef struct { double x,y,z; } dbl3_t;
FixNHIntel::FixNHIntel(LAMMPS *lmp, int narg, char **arg) : FixNHIntel::FixNHIntel(LAMMPS *lmp, int narg, char **arg) :
FixNH(lmp, narg, arg) FixNH(lmp, narg, arg)
{ {
_dtfm = 0; _dtfm = nullptr;
_nlocal3 = 0; _nlocal3 = 0;
_nlocal_max = 0; _nlocal_max = 0;
} }

View File

@ -32,7 +32,7 @@ using namespace FixConst;
FixNVEIntel::FixNVEIntel(LAMMPS *lmp, int narg, char **arg) : FixNVEIntel::FixNVEIntel(LAMMPS *lmp, int narg, char **arg) :
FixNVE(lmp, narg, arg) FixNVE(lmp, narg, arg)
{ {
_dtfm = 0; _dtfm = nullptr;
_nlocal3 = 0; _nlocal3 = 0;
_nlocal_max = 0; _nlocal_max = 0;
} }

View File

@ -26,18 +26,18 @@ using namespace LAMMPS_NS;
template <class flt_t, class acc_t> template <class flt_t, class acc_t>
IntelBuffers<flt_t, acc_t>::IntelBuffers(class LAMMPS *lmp_in) : IntelBuffers<flt_t, acc_t>::IntelBuffers(class LAMMPS *lmp_in) :
lmp(lmp_in), _x(0), _q(0), _quat(0), _f(0), _off_threads(0), lmp(lmp_in), _x(nullptr), _q(nullptr), _quat(nullptr), _f(nullptr), _off_threads(0),
_n_list_ptrs(1), _max_list_ptrs(4), _buf_size(0), _buf_local_size(0) { _n_list_ptrs(1), _max_list_ptrs(4), _buf_size(0), _buf_local_size(0) {
_neigh_list_ptrs = new IntelNeighListPtrs[_max_list_ptrs]; _neigh_list_ptrs = new IntelNeighListPtrs[_max_list_ptrs];
_neigh_list_ptrs[0].cnumneigh = 0; _neigh_list_ptrs[0].cnumneigh = nullptr;
_list_alloc_atoms = 0; _list_alloc_atoms = 0;
_ntypes = 0; _ntypes = 0;
_off_map_listlocal = 0; _off_map_listlocal = 0;
_ccachex = 0; _ccachex = nullptr;
_ncache_alloc = 0; _ncache_alloc = 0;
_ncachetag = 0; _ncachetag = nullptr;
_cutneighsq = 0; _cutneighsq = nullptr;
_cutneighghostsq = 0; _cutneighghostsq = nullptr;
_need_tag = 0; _need_tag = 0;
#ifdef _LMP_INTEL_OFFLOAD #ifdef _LMP_INTEL_OFFLOAD
_separate_buffers = 0; _separate_buffers = 0;
@ -104,8 +104,8 @@ void IntelBuffers<flt_t, acc_t>::free_buffers()
#endif #endif
lmp->memory->destroy(x); lmp->memory->destroy(x);
if (q != 0) lmp->memory->destroy(q); if (q != nullptr) lmp->memory->destroy(q);
if (quat != 0) lmp->memory->destroy(quat); if (quat != nullptr) lmp->memory->destroy(quat);
lmp->memory->destroy(_f); lmp->memory->destroy(_f);
_buf_size = _buf_local_size = 0; _buf_size = _buf_local_size = 0;
} }
@ -251,7 +251,7 @@ void IntelBuffers<flt_t, acc_t>::free_list_local()
if (_off_map_listlocal > 0) { if (_off_map_listlocal > 0) {
if (_neigh_list_ptrs[0].cnumneigh) { if (_neigh_list_ptrs[0].cnumneigh) {
int * cnumneigh = _neigh_list_ptrs[0].cnumneigh; int * cnumneigh = _neigh_list_ptrs[0].cnumneigh;
_neigh_list_ptrs[0].cnumneigh = 0; _neigh_list_ptrs[0].cnumneigh = nullptr;
#ifdef _LMP_INTEL_OFFLOAD #ifdef _LMP_INTEL_OFFLOAD
if (_off_map_ilist != nullptr) { if (_off_map_ilist != nullptr) {
#pragma offload_transfer target(mic:_cop) \ #pragma offload_transfer target(mic:_cop) \
@ -286,7 +286,7 @@ void IntelBuffers<flt_t, acc_t>::free_list_ptrs()
lmp->memory->destroy(_neigh_list_ptrs[list_num].numneighhalf); lmp->memory->destroy(_neigh_list_ptrs[list_num].numneighhalf);
} }
_neigh_list_ptrs[list_num].size = 0; _neigh_list_ptrs[list_num].size = 0;
_neigh_list_ptrs[list_num].list_ptr = 0; _neigh_list_ptrs[list_num].list_ptr = nullptr;
} }
_n_list_ptrs = 1; _n_list_ptrs = 1;
} }
@ -447,7 +447,7 @@ void IntelBuffers<flt_t, acc_t>::free_ccache()
lmp->memory->destroy(ccachef); lmp->memory->destroy(ccachef);
#endif #endif
_ccachex = 0; _ccachex = nullptr;
} }
} }
@ -546,7 +546,7 @@ void IntelBuffers<flt_t, acc_t>::free_ncache()
if (ncachetag) if (ncachetag)
lmp->memory->destroy(ncachetag); lmp->memory->destroy(ncachetag);
_ncache_alloc = 0; _ncache_alloc = 0;
_ncachetag = 0; _ncachetag = nullptr;
} }
} }
@ -563,7 +563,7 @@ void IntelBuffers<flt_t, acc_t>::grow_ncache(const int off_flag,
const int vsize = _ncache_stride * nt; const int vsize = _ncache_stride * nt;
if (_ncache_alloc) { if (_ncache_alloc) {
if (vsize > _ncache_alloc || (need_tag() && _ncachetag == 0)) if (vsize > _ncache_alloc || (need_tag() && _ncachetag == nullptr))
free_ncache(); free_ncache();
#ifdef _LMP_INTEL_OFFLOAD #ifdef _LMP_INTEL_OFFLOAD
else if (off_flag && _off_ncache == 0) else if (off_flag && _off_ncache == 0)
@ -660,7 +660,7 @@ void IntelBuffers<flt_t, acc_t>::set_ntypes(const int ntypes,
} }
#endif #endif
lmp->memory->destroy(_cutneighsq); lmp->memory->destroy(_cutneighsq);
if (_cutneighghostsq != 0) lmp->memory->destroy(_cutneighghostsq); if (_cutneighghostsq != nullptr) lmp->memory->destroy(_cutneighghostsq);
} }
if (ntypes > 0) { if (ntypes > 0) {
lmp->memory->create(_cutneighsq, ntypes, ntypes, "_cutneighsq"); lmp->memory->create(_cutneighsq, ntypes, ntypes, "_cutneighsq");

View File

@ -36,7 +36,7 @@ NPairSkipIntel::NPairSkipIntel(LAMMPS *lmp) : NPair(lmp) {
if (!_fix) error->all(FLERR, "The 'package intel' command is required for /intel styles"); if (!_fix) error->all(FLERR, "The 'package intel' command is required for /intel styles");
_inum_starts = new int[comm->nthreads]; _inum_starts = new int[comm->nthreads];
_inum_counts = new int[comm->nthreads]; _inum_counts = new int[comm->nthreads];
_full_props = 0; _full_props = nullptr;
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
@ -203,11 +203,11 @@ void NPairSkipIntel::build(NeighList *list)
if (_fix->three_body_neighbor()==0 || if (_fix->three_body_neighbor()==0 ||
_full_props[list->listskip->index] == 0) { _full_props[list->listskip->index] == 0) {
if (_fix->precision() == FixIntel::PREC_MODE_MIXED) if (_fix->precision() == FixIntel::PREC_MODE_MIXED)
build_t<float,0>(list, 0, 0, 0); build_t<float,0>(list, nullptr, nullptr, nullptr);
else if (_fix->precision() == FixIntel::PREC_MODE_DOUBLE) else if (_fix->precision() == FixIntel::PREC_MODE_DOUBLE)
build_t<double,0>(list, 0, 0, 0); build_t<double,0>(list, nullptr, nullptr, nullptr);
else else
build_t<float,0>(list, 0, 0, 0); build_t<float,0>(list, nullptr, nullptr, nullptr);
} else { } else {
int *nhalf, *cnumneigh, *nhalf_skip, *u; int *nhalf, *cnumneigh, *nhalf_skip, *u;
if (_fix->precision() == FixIntel::PREC_MODE_MIXED) { if (_fix->precision() == FixIntel::PREC_MODE_MIXED) {

View File

@ -401,7 +401,7 @@ void PairBuckCoulCutIntel::eval(const int offload, const int vflag,
if (EFLAG || vflag) if (EFLAG || vflag)
fix->add_result_array(f_start, ev_global, offload, eatom, 0, vflag); fix->add_result_array(f_start, ev_global, offload, eatom, 0, vflag);
else else
fix->add_result_array(f_start, 0, offload); fix->add_result_array(f_start, nullptr, offload);
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */

View File

@ -477,7 +477,7 @@ void PairBuckCoulLongIntel::eval(const int offload, const int vflag,
if (EFLAG || vflag) if (EFLAG || vflag)
fix->add_result_array(f_start, ev_global, offload, eatom, 0, vflag); fix->add_result_array(f_start, ev_global, offload, eatom, 0, vflag);
else else
fix->add_result_array(f_start, 0, offload); fix->add_result_array(f_start, nullptr, offload);
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */

View File

@ -368,7 +368,7 @@ void PairBuckIntel::eval(const int offload, const int vflag,
if (EFLAG || vflag) if (EFLAG || vflag)
fix->add_result_array(f_start, ev_global, offload, eatom, 0, vflag); fix->add_result_array(f_start, ev_global, offload, eatom, 0, vflag);
else else
fix->add_result_array(f_start, 0, offload); fix->add_result_array(f_start, nullptr, offload);
} }
void PairBuckIntel::init_style() void PairBuckIntel::init_style()

View File

@ -513,7 +513,7 @@ void PairLJCharmmCoulLongIntel::eval(const int offload, const int vflag,
if (EFLAG || vflag) if (EFLAG || vflag)
fix->add_result_array(f_start, ev_global, offload, eatom, 0, vflag); fix->add_result_array(f_start, ev_global, offload, eatom, 0, vflag);
else else
fix->add_result_array(f_start, 0, offload); fix->add_result_array(f_start, nullptr, offload);
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */

View File

@ -478,7 +478,7 @@ void PairLJCutCoulLongIntel::eval(const int offload, const int vflag,
if (EFLAG || vflag) if (EFLAG || vflag)
fix->add_result_array(f_start, ev_global, offload, eatom, 0, vflag); fix->add_result_array(f_start, ev_global, offload, eatom, 0, vflag);
else else
fix->add_result_array(f_start, 0, offload); fix->add_result_array(f_start, nullptr, offload);
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */

View File

@ -384,7 +384,7 @@ void PairLJCutIntel::eval(const int offload, const int vflag,
if (EFLAG || vflag) if (EFLAG || vflag)
fix->add_result_array(f_start, ev_global, offload, eatom, 0, vflag); fix->add_result_array(f_start, ev_global, offload, eatom, 0, vflag);
else else
fix->add_result_array(f_start, 0, offload); fix->add_result_array(f_start, nullptr, offload);
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */

View File

@ -81,7 +81,7 @@ void VerletLRTIntel::init()
void VerletLRTIntel::setup(int flag) void VerletLRTIntel::setup(int flag)
{ {
if (_intel_kspace == 0) { if (_intel_kspace == nullptr) {
Verlet::setup(flag); Verlet::setup(flag);
return; return;
} }
@ -202,7 +202,7 @@ void VerletLRTIntel::setup(int flag)
void VerletLRTIntel::run(int n) void VerletLRTIntel::run(int n)
{ {
if (_intel_kspace == 0) { if (_intel_kspace == nullptr) {
Verlet::run(n); Verlet::run(n);
return; return;
} }

View File

@ -183,7 +183,7 @@ double MPI_Wtime()
double time; double time;
struct timeval tv; struct timeval tv;
gettimeofday(&tv, NULL); gettimeofday(&tv, nullptr);
time = 1.0 * tv.tv_sec + 1.0e-6 * tv.tv_usec; time = 1.0 * tv.tv_sec + 1.0e-6 * tv.tv_usec;
return time; return time;
#endif #endif
@ -223,7 +223,7 @@ static int stubtypesize(MPI_Datatype datatype)
int MPI_Type_size(MPI_Datatype datatype, int *size) int MPI_Type_size(MPI_Datatype datatype, int *size)
{ {
if (size == NULL) return MPI_ERR_ARG; if (size == nullptr) return MPI_ERR_ARG;
*size = stubtypesize(datatype); *size = stubtypesize(datatype);
return 0; return 0;