From bea0a3091d0b77bead59ca25b23926bd4acbb09b Mon Sep 17 00:00:00 2001
From: Michael Brown <michael.w.brown@intel.com>
Date: Mon, 15 Oct 2018 10:25:39 -0700
Subject: [PATCH] Fix to allow suffix and pair hybrid to work together with
 USER-INTEL.

---
 src/USER-INTEL/fix_intel.cpp | 37 +++++++++++-------------------------
 src/USER-INTEL/fix_intel.h   |  2 +-
 2 files changed, 12 insertions(+), 27 deletions(-)

diff --git a/src/USER-INTEL/fix_intel.cpp b/src/USER-INTEL/fix_intel.cpp
index e0865f0431..b305590729 100644
--- a/src/USER-INTEL/fix_intel.cpp
+++ b/src/USER-INTEL/fix_intel.cpp
@@ -65,6 +65,7 @@ FixIntel::FixIntel(LAMMPS *lmp, int narg, char **arg) :  Fix(lmp, narg, arg)
 
   _nbor_pack_width = 1;
   _three_body_neighbor = 0;
+  _pair_intel_count = 0;
   _hybrid_nonpair = 0;
 
   _precision_mode = PREC_MODE_MIXED;
@@ -312,22 +313,14 @@ void FixIntel::init()
   }
   #endif
 
-  int nstyles = 0;
+  const int nstyles = _pair_intel_count;
   if (force->pair_match("hybrid", 1) != NULL) {
     _pair_hybrid_flag = 1;
-    PairHybrid *hybrid = (PairHybrid *) force->pair;
-    for (int i = 0; i < hybrid->nstyles; i++)
-      if (strstr(hybrid->keywords[i], "/intel") != NULL)
-        nstyles++;
     if (force->newton_pair != 0 && force->pair->no_virial_fdotr_compute)
       error->all(FLERR,
                  "Intel package requires fdotr virial with newton on.");
   } else if (force->pair_match("hybrid/overlay", 1) != NULL) {
     _pair_hybrid_flag = 1;
-    PairHybridOverlay *hybrid = (PairHybridOverlay *) force->pair;
-    for (int i = 0; i < hybrid->nstyles; i++)
-      if (strstr(hybrid->keywords[i], "/intel") != NULL)
-        nstyles++;
     if (force->newton_pair != 0 && force->pair->no_virial_fdotr_compute)
       error->all(FLERR,
                  "Intel package requires fdotr virial with newton on.");
@@ -345,6 +338,8 @@ void FixIntel::init()
       _pair_hybrid_zero = 1;
   _hybrid_nonpair = 0;
 
+  _pair_intel_count = 0;
+
   #ifdef _LMP_INTEL_OFFLOAD
   if (offload_balance() != 0.0) {
     _pair_hybrid_zero = 0;
@@ -458,7 +453,7 @@ void FixIntel::pair_init_check(const bool cdmessage)
         force->special_coul[3] == 0.0) flag = 1;
     if (flag)
       error->all(FLERR,"Add -DLMP_INTEL_NBOR_COMPAT to build for special_bond"
-                 "exclusions with Intel");
+                 " exclusions with Intel");
   }
   #endif
   
@@ -478,6 +473,8 @@ void FixIntel::pair_init_check(const bool cdmessage)
     get_double_buffers()->need_tag(need_tag);
   }
 
+  _pair_intel_count++;
+
   #ifdef _LMP_INTEL_OFFLOAD
   set_offload_affinity();
   #endif
@@ -521,16 +518,10 @@ void FixIntel::bond_init_check()
     intel_pair = 1;
   else if (force->pair_match("hybrid", 1) != NULL) {
     _hybrid_nonpair = 1;
-    PairHybrid *hybrid = (PairHybrid *) force->pair;
-    for (int i = 0; i < hybrid->nstyles; i++)
-      if (strstr(hybrid->keywords[i], "/intel") != NULL)
-        intel_pair = 1;
+    if (_pair_intel_count) intel_pair = 1;
   } else if (force->pair_match("hybrid/overlay", 1) != NULL) {
     _hybrid_nonpair = 1;
-    PairHybridOverlay *hybrid = (PairHybridOverlay *) force->pair;
-    for (int i = 0; i < hybrid->nstyles; i++)
-      if (strstr(hybrid->keywords[i], "/intel") != NULL)
-        intel_pair = 1;
+    if (_pair_intel_count) intel_pair = 1;
   }
 
   if (intel_pair == 0)
@@ -547,16 +538,10 @@ void FixIntel::kspace_init_check()
     intel_pair = 1;
   else if (force->pair_match("hybrid", 1) != NULL) {
     _hybrid_nonpair = 1;
-    PairHybrid *hybrid = (PairHybrid *) force->pair;
-    for (int i = 0; i < hybrid->nstyles; i++)
-      if (strstr(hybrid->keywords[i], "/intel") != NULL)
-        intel_pair = 1;
+    if (_pair_intel_count) intel_pair = 1;
   } else if (force->pair_match("hybrid/overlay", 1) != NULL) {
     _hybrid_nonpair = 1;
-    PairHybridOverlay *hybrid = (PairHybridOverlay *) force->pair;
-    for (int i = 0; i < hybrid->nstyles; i++)
-      if (strstr(hybrid->keywords[i], "/intel") != NULL)
-        intel_pair = 1;
+    if (_pair_intel_count) intel_pair = 1;
   }
 
   if (intel_pair == 0)
diff --git a/src/USER-INTEL/fix_intel.h b/src/USER-INTEL/fix_intel.h
index 81dd0b5d97..a01ed18bfe 100644
--- a/src/USER-INTEL/fix_intel.h
+++ b/src/USER-INTEL/fix_intel.h
@@ -101,7 +101,7 @@ class FixIntel : public Fix {
   IntelBuffers<double,double> *_double_buffers;
 
   int _precision_mode, _nthreads, _nbor_pack_width, _three_body_neighbor;
-  int _pair_hybrid_flag;
+  int _pair_intel_count, _pair_hybrid_flag;
   // These should be removed in subsequent update w/ simpler hybrid arch
   int _pair_hybrid_zero, _hybrid_nonpair, _zero_master;
   
-- 
GitLab