Commit 8456f3f2 authored by Sebastian Hütter's avatar Sebastian Hütter
Browse files

MEAM/C: refactor file reading with MPI, scope locals accordingly

parent 9e0e046e
Loading
Loading
Loading
Loading
+121 −119
Original line number Diff line number Diff line
@@ -368,53 +368,39 @@ void PairMEAMC::read_files(char *globalfile, char *userfile)
  // store params if element name is in element list
  // if element name appears multiple times, only store 1st entry


  int n,nwords;
  char **words = new char*[params_per_line+1];
  char line[MAXLINE],*ptr;
  int eof = 0;

  if (comm->me == 0) {
    int nset = 0;
    char **words = new char*[params_per_line+1];
    char line[MAXLINE];
    while (1) {
    if (comm->me == 0) {
      char *ptr;
      ptr = fgets(line,MAXLINE,fp);
      if (ptr == NULL) {
        eof = 1;
        fclose(fp);
      } else n = strlen(line) + 1;
        break;
      }
    MPI_Bcast(&eof,1,MPI_INT,0,world);
    if (eof) break;
    MPI_Bcast(&n,1,MPI_INT,0,world);
    MPI_Bcast(line,n,MPI_CHAR,0,world);

      // strip comment, skip line if blank

      if ((ptr = strchr(line,'#'))) *ptr = '\0';
    nwords = atom->count_words(line);
      int nwords = atom->count_words(line);
      if (nwords == 0) continue;

      // concatenate additional lines until have params_per_line words

      while (nwords < params_per_line) {
      n = strlen(line);
      if (comm->me == 0) {
        int n = strlen(line);
        ptr = fgets(&line[n],MAXLINE-n,fp);
        if (ptr == NULL) {
          eof = 1;
          fclose(fp);
        } else n = strlen(line) + 1;
          break;
        }
      MPI_Bcast(&eof,1,MPI_INT,0,world);
      if (eof) break;
      MPI_Bcast(&n,1,MPI_INT,0,world);
      MPI_Bcast(line,n,MPI_CHAR,0,world);
        if ((ptr = strchr(line,'#'))) *ptr = '\0';
        nwords = atom->count_words(line);
      }

      if (nwords != params_per_line)
      error->all(FLERR,"Incorrect format in MEAM library file");
        error->one(FLERR,"Incorrect format in MEAM library file");

      // words = ptrs to all words in line
      // strip single and double quotes from words
@@ -425,13 +411,10 @@ void PairMEAMC::read_files(char *globalfile, char *userfile)

      // skip if element name isn't in element list

    int index = -1;
    for (int i = 0; i < nelements; i++)
      if (strcmp(words[0],elements[i]) == 0) {
        index = i;
        break;
      }
    if (index < 0) continue;
      int index;
      for (index = 0; index < nelements; index++)
        if (strcmp(words[0],elements[index]) == 0) break;
      if (index == nelements) continue;

      // skip if element already appeared (technically error in library file, but always ignored)

@@ -441,7 +424,7 @@ void PairMEAMC::read_files(char *globalfile, char *userfile)
      // map lat string to an integer

      if (!MEAM::str_to_lat(words[1], true, lat[index]))
      ERRFMT(error->all, "Unrecognized lattice type in MEAM library file: %s", words[1]);
        ERRFMT(error->one, "Unrecognized lattice type in MEAM library file: %s", words[1]);

      // store parameters

@@ -464,11 +447,11 @@ void PairMEAMC::read_files(char *globalfile, char *userfile)
      ibar[index] = atoi(words[18]);

      if (!isone(t0[index]))
      error->all(FLERR,"Unsupported parameter in MEAM library file: t0!=1");
        error->one(FLERR,"Unsupported parameter in MEAM library file: t0!=1");

      // z given is ignored: if this is mismatched, we definitely won't do what the user said -> fatal error
      if (z[index] != MEAM::get_Zij(lat[index]))
      error->all(FLERR,"Mismatched parameter in MEAM library file: z!=lat");
        error->one(FLERR,"Mismatched parameter in MEAM library file: z!=lat");

      nset++;
    }
@@ -482,9 +465,32 @@ void PairMEAMC::read_files(char *globalfile, char *userfile)
          strcat(str," ");
          strcat(str,elements[i]);
        }
    error->all(FLERR,str);
      error->one(FLERR,str);
    }

    delete [] words;
  }

  // distribute complete parameter sets
  MPI_Bcast(lat, nelements, MPI_INT, 0, world);
  MPI_Bcast(ielement, nelements, MPI_INT, 0, world);
  MPI_Bcast(ibar, nelements, MPI_INT, 0, world);
  MPI_Bcast(z, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(atwt, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(alpha, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(b0, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(b1, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(b2, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(b3, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(alat, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(esub, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(asub, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(t0, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(t1, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(t2, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(t3, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(rozero, nelements, MPI_DOUBLE, 0, world);

  // pass element parameters to MEAM package

  meam_inst->meam_setup_global(nelements,lat,ielement,atwt,alpha,b0,b1,b2,b3,
@@ -496,8 +502,6 @@ void PairMEAMC::read_files(char *globalfile, char *userfile)

  // clean-up memory

  delete [] words;

  delete [] lat;
  delete [] ielement;
  delete [] ibar;
@@ -534,37 +538,34 @@ void PairMEAMC::read_files(char *globalfile, char *userfile)
  // pass them one at a time to MEAM package
  // match strings to list of corresponding ints
  
  int which;
  double value;
  lattice_t latt;
  int nindex,index[3];
  int maxparams = 6;
  char **params = new char*[maxparams];
  int nparams;

  eof = 0;
  while (1) {
    int which;
    int nindex, index[3];
    double value;
    char line[MAXLINE];
    int nline;
    char *ptr;
    if (comm->me == 0) {
      ptr = fgets(line,MAXLINE,fp);
      if (ptr == NULL) {
        eof = 1;
        fclose(fp);
      } else n = strlen(line) + 1;
        nline = -1;
      } else nline = strlen(line) + 1;
    }
    MPI_Bcast(&eof,1,MPI_INT,0,world);
    if (eof) break;
    MPI_Bcast(&n,1,MPI_INT,0,world);
    MPI_Bcast(line,n,MPI_CHAR,0,world);
    MPI_Bcast(&nline,1,MPI_INT,0,world);
    if (nline<0) break;
    MPI_Bcast(line,nline,MPI_CHAR,0,world);

    // strip comment, skip line if blank

    if ((ptr = strchr(line,'#'))) *ptr = '\0';
    nparams = atom->count_words(line);
    if (nparams == 0) continue;
    if (atom->count_words(line) == 0) continue;

    // words = ptrs to all words in line
    // params = ptrs to all fields in line
    
    nparams = 0;
    int nparams = 0;
    params[nparams++] = strtok(line,"=(), '\t\n\r\f");
    while (nparams < maxparams &&
           (params[nparams++] = strtok(NULL,"=(), '\t\n\r\f")))
@@ -582,6 +583,7 @@ void PairMEAMC::read_files(char *globalfile, char *userfile)
    // map lattce_meam value to an integer

    if (which == 4) {
      lattice_t latt;
      if (!MEAM::str_to_lat(params[nparams-1], false, latt))
        ERRFMT(error->all, "Unrecognized lattice type in MEAM parameter file: %s", params[nparams-1]);
      value = latt;
@@ -602,8 +604,8 @@ void PairMEAMC::read_files(char *globalfile, char *userfile)
      }
      error->all(FLERR,str);
    }
  }
    
  }
  delete [] params;
}