questions about writing a new compute

Hi, I am trying to write a new compute class. I have some questions to discuss.

  1. The fix/store class is used to store the initial coordinates, and then I define a variable to retrieve them in my code. The code is as following:
    double **rj0 = modify->fix[istore]->array_atom;
    However, I got an error: pointer to incomplete class type is not allowed. I have include “modify.h”

  2. The information of atoms are stored locally. How to get the global index of each atom according to it local index? When we process the information of each atom, the following loop is generally used in Lammps.
    x0 is a variable with atom information, and it is read from an external file with the global atom index. Is it an efficient or parallel way to do this?

for ( i = 0; i < nlocal; i++)
{
if (mask[i] & groupbit)
{
//if I want to calculated the variable below
a=a+exp(x[i][1]-x0[?][1]); //What is the first index of x0?
}
}

  1. Read data from external file. This should be simple. But I got a weird warning for the following codes.
    double temp;
    fscanf (pFile, “%f”, &temp);
    warning #181: argument is incompatible with corresponding format string conversion

Thank you for any comment and suggestion.

Regards,
Liang Chen

Hi, I am trying to write a new compute class. I have some questions to
discuss.

1) The fix/store class is used to store the initial coordinates, and then I
define a variable to retrieve them in my code. The code is as following:
double **rj0 = modify->fix[istore]->array_atom;
However, I got an error: pointer to incomplete class type is not allowed. I
have include "modify.h"

how about "fix.h"?

2) The information of atoms are stored locally. How to get the global index
of each atom according to it local index? When we process the information of
each atom, the following loop is generally used in Lammps.
x0 is a variable with atom information, and it is read from an external file
with the global atom index. Is it an efficient or parallel way to do this?

you do it the other way around.

atom->map(idx) will give you the local index
corresponding to the global index or -1.

for ( i = 0; i < nlocal; i++)
{
if (mask[i] & groupbit)
{
//if I want to calculated the variable below
a=a+exp(x[i][1]-x0[?][1]); //What is the first index of x0?
}
}

3) Read data from external file. This should be simple. But I got a weird
warning for the following codes.
double temp;
fscanf (pFile, "%f", &temp);
warning #181: argument is incompatible with corresponding format string
conversion

have you tried %g? %f is for single precision.

axel.

HI, Axel, thank you for the suggestions. If I use atom->map(idx), I have to loop all the atoms in every processor, which is not efficient. May I use the atom->tag[i] to get the global index?

for ( i = 0; i < nlocal; i++)
{
if (mask[i] & groupbit)
{
//if I want to calculated the variable below
j=atom->tag[i];
a=a+exp(x[i][1]-x0[j][1]);
}
}

HI, Axel, thank you for the suggestions. If I use atom->map(idx), I have to
loop all the atoms in every processor, which is not efficient. May I use the
atom->tag[i] to get the global index?

for ( i = 0; i < nlocal; i++)
{
if (mask[i] & groupbit)
{
//if I want to calculated the variable below
j=atom->tag[i];
a=a+exp(x[i][1]-x0[j][1]);

no. this construct cannot work.
tag will give you the global id, so
you have to use atom->map() to
translate it back to a local index.

please keep in mind that atoms
are communicated between nodes
and get re-ordered.

axel.

Hi, Axel,

I am kind of confused. The array x0[j][] is a variable I defined and the values are read from external file. j is the global ID. The accumulation of variable "a " is first done for the nlocal atoms in every processor, and then is summed over all the processor using MPI_Allreduce. So I use atom->tag[i] to get the global ID of the each atom in a local processor.

Thank you.

Regards,

Liang Chen

Hi, Axel,

I am kind of confused. The array x0[j][] is a variable I defined and the

i am confused, too. your previous e-mail implied that
this was the array from the fix.

values are read from external file. j is the global ID. The accumulation of
variable "a " is first done for the nlocal atoms in every processor, and
then is summed over all the processor using MPI_Allreduce. So I use
atom->tag[i] to get the global ID of the each atom in a local processor.

you have the source,
you know what you want to do,
you can use a debugger,
you can find it out.

it is *very* difficult to give recommendations
when having only fractions of that knowledge.

axel.

hi, Axel, sorry for the confusion. I should try and debug it. Thanks.

Regards,
Liang Chen

If x and x0 are both per-atom variables, then
the index for both should be "i". That is how
fix store would store x0.

Axel has already answered your other Qs.

Steve