Accessing a global/computed value in a fix

Hello,
I am currently writing a fix that will use the number of atoms of a specific type (which are open to changing over time) as an input. Since the fix runs on the local domain, I understand that I need to have a preliminary step that obtains these values globally. I was thinking that a compute reduce would do the job, and the resulting value would be accessed by the fix. However, I am not sure how the fix would access the resulting value from the compute - I searched for an extract function in compute.cpp and could not find one. Is there a proper way to go about this?
Thank you,
Anne

Hello,
I am currently writing a fix that will use the number of atoms of a specific type (which are open to changing over time) as an input. Since the fix runs on the local domain, I understand that I need to have a preliminary step that obtains these values globally. I was thinking that a compute reduce would do the job, and the resulting value would be accessed by the fix. However, I am not sure how the fix would access the resulting value from the compute - I searched for an extract function in compute.cpp and could not find one. Is there a proper way to go about this?

yes, there is. but in this specific case, I would recommend against it. just program it directly with an MPI call. you need something like this:

int searchtype = 2;
bigint mycount = 0, allcount = 0;
for (int i = 0; i < atom->nlocal; ++i) {
if (atom->type[i] == searchtype) ++mycount;
}
MPI_Allreduce(&mycount, &allcount, 1, MPI_LMP_BIGINT, MPI_SUM, world);

after this you have the number of atoms with type “searchtype” (i.e. 2 in this example) in “allcount”.
accessing a previously defined compute reduce will do the same thing, but with many more complications and steps.
just getting access to a compute will require at least twice as many lines of code.

Got it; thank you very much!