Unverified Commit 56e86724 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

When restoring restarts try to strip known accelerator suffixes and possibly...

When restoring restarts try to strip known accelerator suffixes and possibly apply current ones instead
parent ad125bf3
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -911,7 +911,7 @@ void Modify::add_fix(int narg, char **arg, int trysuffix)

  for (int i = 0; i < nfix_restart_global; i++)
    if (strcmp(id_restart_global[i],fix[ifix]->id) == 0 &&
        strcmp(style_restart_global[i],fix[ifix]->style) == 0) {
        utils::nosuffixmatch(style_restart_global[i],fix[ifix]->style)) {
      fix[ifix]->restart(state_restart_global[i]);
      used_restart_global[i] = 1;
      if (comm->me == 0) {
@@ -931,7 +931,7 @@ void Modify::add_fix(int narg, char **arg, int trysuffix)

  for (int i = 0; i < nfix_restart_peratom; i++)
    if (strcmp(id_restart_peratom[i],fix[ifix]->id) == 0 &&
        strcmp(style_restart_peratom[i],fix[ifix]->style) == 0) {
        utils::nosuffixmatch(style_restart_peratom[i],fix[ifix]->style)) {
      used_restart_peratom[i] = 1;
      for (int j = 0; j < atom->nlocal; j++)
        fix[ifix]->unpack_restart(j,index_restart_peratom[i]);
+7 −7
Original line number Diff line number Diff line
@@ -856,7 +856,7 @@ void ReadRestart::header(int incompatible)
    // create new AtomVec class using any stored args

    } else if (flag == ATOM_STYLE) {
      char *style = read_string();
      char *style = utils::stripsuffix(read_string());
      int nargcopy = read_int();
      char **argcopy = new char*[nargcopy];
      for (int i = 0; i < nargcopy; i++)
@@ -996,7 +996,7 @@ void ReadRestart::force_fields()
  while (flag >= 0) {

    if (flag == PAIR) {
      style = read_string();
      style = utils::stripsuffix(read_string());
      force->create_pair(style,1);
      delete [] style;
      if (comm->me ==0) {
@@ -1008,7 +1008,7 @@ void ReadRestart::force_fields()
      force->pair->read_restart(fp);

    } else if (flag == NO_PAIR) {
      style = read_string();
      style = utils::stripsuffix(read_string());
      if (comm->me ==0) {
        if (screen) fprintf(screen,"  pair style %s stores no "
                            "restart info\n", style);
@@ -1019,7 +1019,7 @@ void ReadRestart::force_fields()
      force->pair_restart = style;

    } else if (flag == BOND) {
      style = read_string();
      style = utils::stripsuffix(read_string());
      force->create_bond(style,1);
      delete [] style;
      if (comm->me ==0) {
@@ -1031,7 +1031,7 @@ void ReadRestart::force_fields()
      force->bond->read_restart(fp);

    } else if (flag == ANGLE) {
      style = read_string();
      style = utils::stripsuffix(read_string());
      force->create_angle(style,1);
      delete [] style;
      if (comm->me ==0) {
@@ -1043,7 +1043,7 @@ void ReadRestart::force_fields()
      force->angle->read_restart(fp);

    } else if (flag == DIHEDRAL) {
      style = read_string();
      style = utils::stripsuffix(read_string());
      force->create_dihedral(style,1);
      delete [] style;
      if (comm->me ==0) {
@@ -1055,7 +1055,7 @@ void ReadRestart::force_fields()
      force->dihedral->read_restart(fp);

    } else if (flag == IMPROPER) {
      style = read_string();
      style = utils::stripsuffix(read_string());
      force->create_improper(style,1);
      delete [] style;
      if (comm->me ==0) {
+53 −0
Original line number Diff line number Diff line
@@ -84,7 +84,60 @@ bool utils::strmatch(std::string text, std::string pattern)
  return (pos >= 0);
}

/* duplicate string */
char *utils::strdup(const char *in)
{
  int len = strlen(in)+1;
  char *out = new char[len];
  strcpy(out,in);
  return out;
}

/** List of known accelerator suffixes */
static const char *accelsuffix[] =
{
  (const char *)"/gpu",
  (const char *)"/intel",
  (const char *)"/kk",
  (const char *)"/omp",
  (const char *)"/opt",
  NULL
};

/* Strip known accelertor suffixes from input string */

char *utils::stripsuffix(char *style)
{
  if (style == NULL) return style;

  char *slash = strrchr(style,'/');
  for (int i = 0; accelsuffix[i] != NULL; ++i) {
    if (strcmp(slash,accelsuffix[i]) == 0) {
      *slash = '\0';
      return style;
    }
  }
  return style;
}

/** Compare two strings without considering accelerator suffixes
 *
 * We need to work on copies of the strings, since utils::stripsuffix
 * will replace a '/' with a '\0'.
 */

bool utils::nosuffixmatch(const char *first, const char *second)
{
  char *s1 = utils::stripsuffix(utils::strdup(first));
  char *s2 = utils::stripsuffix(utils::strdup(second));
  bool rv = strcmp(s1,s2) == 0;
  delete[] s1;
  delete[] s2;
  return rv;
}

/* utility function to avoid code repetition when parsing args */

int utils::cfvarg(std::string mode, const char *arg, char *&cfv_id)
{
  int rv = utils::NONE;
+32 −0
Original line number Diff line number Diff line
@@ -28,6 +28,38 @@ namespace LAMMPS_NS {

  namespace utils {

    /** \brief Create a copy of a C-style string
     *
     * \param in input string
     * \return copied string
     *
     * This uses "new" to allocate the storage so it must be
     * deallocated with "delete[]"
     */
    char *strdup(const char *in);

    /** \brief Truncate string to remove known accelerator suffixes
     *
     * \param style style name
     * \return style name with possible accelerator suffix removed
     *
     * This modifies the style string passed as an argument to look
     * any known accelerator suffixes like "/gpu", "/intel", "/omp" etc.
     * and replaces the '/' character with a '\0' and returns
     */
    char *stripsuffix(char *style);

    /** \brief Compare two strings with suffixes removed
     *
     * \param first style string
     * \param second style string
     * \return true if strings match while ignoring known suffixes, or false
     *
     * This compares two strings with known accelerator suffixes removed
     * before comparing.
     */
    bool nosuffixmatch(const char *first, const char *second);

    /** \brief Match text against a simplified regex pattern
     *
     *  \param text the text to be matched against the pattern