Difficulty in using random seed for Fortran Based lammmps

Hello Sir,

I am using LAMMPS as library in Fortran. My Fortran script using the seed. My Fortran code does lot of MD in a loop. I need to use different seed for the my MD part of code in the Fortran. My compilation commands for the LAMMPS based Fortran code is "mpiifort -qopenmp lammps.f90 Hybrid.f90 -o H3 -llammps_mpi ". This compile the file “H3”.

Now i used two methods to generate random seed.

  1. run sing command

mpirun -np 64 H3 P in.lammps -var seed bash -c 'echo $RANDOM'

  1. Added these in my submit script.
    “seed=$RANDOM
    newline='variable seed equal 'seed linetoreplace=(cat in.lammps | grep ‘variable seed equal’)
    sed -i ‘/’”$linetoreplace"'/c'“$newline” in.lammps"

BUT both did not seems to work and generate an error says "Substitution for illegal variable seed ".

I did not find a way to give information for a random seed for compiling with above commands.

Thank you

I cannot comment on your scripts since you are not quoting correctly and thus they are not correctly formatted.

There are many ways how you can pass a different seed to the LAMMPS code. From the parts that I can read, you may have chosen the most convoluted ways to pass the information to LAMMPS.

Some suggestions:

  • LAMMPS has “getenv” style variables, so you just need to set an environment variable on all MPI processes and you can pull that environment variable value into your LAMMPS script by expanding that variable
  • You can generate the random numbers in Fortran (make sure you use an MPI_Bcast() call to make it the same on all MPI ranks) and then use the Fortran WRITE() command to a string which assembles the command line that contains the environment variable and that string can then be passed to lmp%command()
  • You can just put a list of random seeds into a file and then create a file style variable and with each next command in the LAMMPS input it will pick up the next value from the list.