Compiling issues (Fujitsu compiler)

Dear all,

I have 3 errors when compiling .cpp files of Lammps using the Fujitsu FX10 compiler. I can fix two (maybe of interest to the developers for improved support of this compiler) but the 2nd of the 3 is more difficult.

The first error:

“…/displace_atoms.cpp”, line 218: error: expected a “)”
if (dim == 2 and (axis[0] != 0.0 || axis[1] != 0.0))

Replace “and” with “&&”.

The second error is harder to fix:

“…/input.cpp”, line 203: error: expression must have a constant value
char str[maxline+32];
^

“…/input.cpp”, line 269: error: expression must have a constant value
char str[maxline+32];

“…/msm.cpp”, line 2274: error: expression must have a constant value
int index[p+2];
^

“…/msm.cpp”, line 2360: error: expression must have a constant value
int index[p+2];
^

The “^” symbols should be under “maxline” and “p” respectively.

I understand that some compilers allow variables to be used when specifying array sizes in C++ [1] but apparently Fujitsu is not one of them. Any suggestions to overcome this?

[1] http://stackoverflow.com/questions/9219712/c-array-expresssion-must-have-a-constant-value/9219745#9219745

Finally, the 3rd error is:

“…/variable.cpp”, line 3621: error: identifier “not” is undefined
if ((strncmp(word,“c_”,2) == 0) && (i>0) && (not isalnum(str[i-1]))){
^

“…/variable.cpp”, line 3621: error: expected a “)”
if ((strncmp(word,“c_”,2) == 0) && (i>0) && (not isalnum(str[i-1]))){
^

“…/variable.cpp”, line 3639: error: expected a “)”
if ((strncmp(word,“f_”,2) == 0) && (i>0) && (not isalnum(str[i-1]))) {
^

“…/variable.cpp”, line 3655: error: expected a “)”
if ((strncmp(word,“v_”,2) == 0) && (i>0) && (not isalnum(str[i-1]))) {
^

Replacing “not” with “!” fixes this.

Any help about the 2nd error would be appreciated.

Thank you.

Best regards,

James

Dear all,

I have 3 errors when compiling .cpp files of Lammps using the Fujitsu FX10
compiler. I can fix two (maybe of interest to the developers for improved
support of this compiler) but the 2nd of the 3 is more difficult.

thanks for reporting this. if you haven't done so, you should also
report this to the compiler vendor, since those are strictly speaking
faults of the compiler and not of LAMMPS. nevertheless, i consider it
a good idea to program defensively, if there are viable alternatives.
and that is the case here.

The first error:

"../displace_atoms.cpp", line 218: error: expected a ")"
      if (dim == 2 and (axis[0] != 0.0 || axis[1] != 0.0))

Replace "and" with "&&".

The second error is harder to fix:

well, not *that* much harder.

"../input.cpp", line 203: error: expression must have a constant value
        char str[maxline+32];
                 ^

"../input.cpp", line 269: error: expression must have a constant value
      char str[maxline+32];

for this you can make the following change (don't worry about a memory
leak, since error->all will abort the run)

[[email protected]... src]$ git diff input.cpp
diff --git a/src/input.cpp b/src/input.cpp
index 31080aa..90f5828 100644
--- a/src/input.cpp
+++ b/src/input.cpp
@@ -201,7 +201,7 @@ void Input::file()
     // execute the command

     if (execute_command()) {
- char str[maxline+32];
+ char *str = new char[maxline+32];
       sprintf(str,"Unknown command: %s",line);
       error->all(FLERR,str);
     }
@@ -267,7 +267,7 @@ char *Input::one(const char *single)
   // execute the command and return its name

   if (execute_command()) {
- char str[maxline+32];
+ char *str = new char[maxline+32];
     sprintf(str,"Unknown command: %s",line);
     error->all(FLERR,str);
   }

"../msm.cpp", line 2274: error: expression must have a constant value
    int index[p+2];
              ^

"../msm.cpp", line 2360: error: expression must have a constant value
    int index[p+2];
              ^

The "^" symbols should be under "maxline" and "p" respectively.

I understand that some compilers allow variables to be used when specifying
array sizes in C++ [1] but apparently Fujitsu is not one of them. Any
suggestions to overcome this?

here you can try two things. making a stack allocation as in the code
should be preferred because it is supposed to lead to faster code.
perhaps the fujitsu compiler will accept this, if you change the
declaration of p into a "const int". that should be done in any case
to aid the compiler in optimizing the code. otherwise you could
new/delete the storage explicitly as in the diff below.

diff --git a/src/KSPACE/msm.cpp b/src/KSPACE/msm.cpp
index dff62c8..c221857 100644
--- a/src/KSPACE/msm.cpp
+++ b/src/KSPACE/msm.cpp
@@ -2265,13 +2265,13 @@ void MSM::restriction(int n)
{
   //fprintf(screen,"Restricting from level %i to %i\n\n",n,n+1);

- int p = order-1;
+ const int p = order-1;

   double ***qgrid1 = qgrid[n];
   double ***qgrid2 = qgrid[n+1];

   int k = 0;
- int index[p+2];
+ int *index = new int[p+2];
   for (int nu=-p; nu<=p; nu++) {
     if (nu%2 == 0 && nu != 0) continue;
     phi1d[0][k] = compute_phi(nu*delxinv[n+1]/delxinv[n]);
@@ -2327,6 +2327,7 @@ void MSM::restriction(int n)
         qgrid2[kp][jp][ip] += q2sum;
       }

+ delete [] index;
}

/* ----------------------------------------------------------------------
@@ -2338,7 +2339,7 @@ void MSM::prolongation(int n)
{
   //fprintf(screen,"Prolongating from level %i to %i\n\n",n+1,n);

- int p = order-1;
+ const int p = order-1;

   double ***egrid1 = egrid[n];
   double ***egrid2 = egrid[n+1];
@@ -2357,7 +2358,7 @@ void MSM::prolongation(int n)
   double ***v5grid2 = v5grid[n+1];

   int k = 0;
- int index[p+2];
+ int *index = new int[p+2];
   for (int nu=-p; nu<=p; nu++) {
     if (nu%2 == 0 && nu != 0) continue;
     phi1d[0][k] = compute_phi(nu*delxinv[n+1]/delxinv[n]);
@@ -2430,6 +2431,7 @@ void MSM::prolongation(int n)

       }

please try both options and let us know which one is the winner.

thanks,
     axel.

Made these changes in the current patch - used
the const int p = … option, so hopefully that
works for Fujistu.

Steve