Dear Axel,
thanks for all your hints. I need, however, the reduce inside the every block and it still does not work. I attach below a minimal code producing the segfault.
there is a major difference here. in your previous example the compute
reduce was over group all, and thus could be moved outside.
in this example, you use it on a group you newly define. i don't see,
how there currently is a way to do this kind of operation with LAMMPS
scripting using script code conforming to the requirements put forth
in the documentation.
according to the documentation, you *must not* put definitions of
computes or fixes into an "every" block, since they require "run pre
yes", which triggers the initialization, but using "run every" is
essentially a shortcut to doing a loop over "run pre no post no"
commands. so technically speaking, LAMMPS is working correctly,
because you are not using it correctly.
i see three options here:
1) write a custom compute style, that does exactly the kind of
analysis, that you want to do and then do what is done now with
explicit commands internally. this would avoid having to use "run
every" and is going to be the most efficient way to do things, and
most useful in the long run, if you need to do this a lot. it is the
most effort, too, though.
2) you modify the "region sphere" sphere command source code so it can
take (equal style) variables for the center coordinates, not just the
radius, and then use "compute reduce/region" on group all and also
"variable natm equal count(all,mysphere)", and the group inside does
not need to be defined altogether. since it looks like the root of
your issue is that you need a region, that is moving with a specific
particle. that would eliminate the need to use "run every". you could
do a regular run and output what you want with "fix print". this could
be further optimized to combine the implicit reduction operation
included in the count() function with compute reduce/region using a
variable with rmask(mysphere)
3) you hack the "compute reduce" source code to detect when it is
being used without initialization and then trigger the initialization
internally and hope for the best. we should put a check for being used
without initialization into that code, anyway, in order to avoid the
segfault resulting from using the compute in an incorrect context.
axel.