LAMMPS library not applying kokkos command line options as expected

Hello,

I am working on an existing c program that calls the LAMMPS library. The "lammps_open" command is not correctly applying command line options for subsequent "lammps_command" calls. I am using the 3Mar2020 stable release and have verified that it is built correctly by running the binary with identical input commands. Therefore, I believe there is something wrong with my implementation of the library call.

Specifically, I am trying to allow my software to utilize kokkos by passing in the "-k on" option to "lammps_open" before individual "lammps_command" calls. However, despite my best efforts, the "-k on" is not applied. Here is my MWE.

I have 4 files, with global variables to contain the command line args.

main.h:
  extern char **cmds;
  extern double call_lammps ();
  int nargs

lammps.h:
  #include "main.h"
  char **cmds;
  double call_lammps ();

main.c:
  #include "main.h"
  #include "lammps.h"
  nargs = 3
  cmds = (char **) calloc (nargs, sizeof (char *));
  cmds[0] = "";
  cmds[1] = "-k";
  cmds[2] = "on";
  err = call_lammps ();

lammps.c:
  #include "library.h"
  #include "lammps.h"
  double call_lammps () {
    char *line;
    lammps_open (nargs, cmds, comm, &ptr);
    sprintf (line, "package kokkos");
    lammps_command (ptr, line);
  }

I have also verified that in my function “call_lammps", the variable "cmds" indeed contains the correct command line args immediately before "lammps_open." But when the "package kokkos" command is sent to "lammps_command," I receive the error:

  ERROR: Package kokkos command without KOKKOS package enabled
  Last command: package kokkos

Which indicates that "-k on" did not successfully enable kokkos for this instance of LAMMPS. I do not understand why.

Can anyone suggest what I can do to debug this?

Thanks

I cannot reproduce this.

calling a header file “lammps.h” is a bad idea since LAMMPS ships with one that has that name.

here is a cleaner minimal example that works for me. just copy the in.melt file from the example/melt folder into the current working directory.

#include “library.h”
#include <mpi.h>
#include <stdio.h>

int main(int argc, char **argv)
{
void *handle;
int version;

char *args[] = { “liblammps”, “-k”, “on”, “-log”, “none”, “-sf”,“kk” };
int narg = sizeof(args)/sizeof(char *);

MPI_Init(&argc,&argv);
lammps_open(narg, args, MPI_COMM_WORLD, &handle);
version = lammps_version(handle);
printf(“LAMMPS version is: %d\n”,version);
lammps_file(handle,“in.melt”);
lammps_close(handle);
MPI_Barrier(MPI_COMM_WORLD);
MPI_Finalize();
return 0;
}

as output i get:

LAMMPS (19 Mar 2020)
KOKKOS mode is enabled (src/KOKKOS/kokkos.cpp:85)
will use up to 0 GPU(s) per node
LAMMPS version is: 20200319
Lattice spacing in x,y,z = 1.6796 1.6796 1.6796
Created orthogonal box = (0 0 0) to (16.796 16.796 16.796)
1 by 1 by 1 MPI processor grid
Created 4000 atoms
create_atoms CPU = 0.00236416 secs
Neighbor list info …
update every 20 steps, delay 0 steps, check no
max neighbors/atom: 2000, page size: 100000
master list distance cutoff = 2.8
ghost atom cutoff = 2.8
binsize = 1.4, bins = 12 12 12
1 neighbor lists, perpetual/occasional/extra = 1 0 0
(1) pair lj/cut/kk, perpetual
attributes: half, newton on, kokkos_device
pair build: half/bin/kk/device
stencil: half/bin/3d/newton
bin: kk/device
Setting up Verlet run …
Unit style : lj
Current step : 0
Time step : 0.005
Per MPI rank memory allocation (min/avg/max) = 2.987 | 2.987 | 2.987 Mbytes
Step Temp E_pair E_mol TotEng Press
0 3 -6.7733681 0 -2.2744931 -3.7033504
50 1.6758903 -4.7955425 0 -2.2823355 5.670064
100 1.6458363 -4.7492704 0 -2.2811332 5.8691042
150 1.6324555 -4.7286791 0 -2.280608 5.9589514
200 1.6630725 -4.7750988 0 -2.2811136 5.7364886
250 1.6275257 -4.7224992 0 -2.281821 5.9567365
Loop time of 0.942786 on 1 procs for 250 steps with 4000 atoms

Performance: 114554.101 tau/day, 265.172 timesteps/s
99.8% CPU use with 1 MPI tasks x 1 OpenMP threads

MPI task timing breakdown:
Section | min time | avg time | max time |%varavg| %total