Question to fix atom/swap function

Deal users and developers

Recently, I tried to use fix atom/swap function in lammps to do monte carlo simulation. The issue I have is at some timestep, the simulation require a very large memory. I don’t know how to fix this.
The input I use is like that:

#Randomly select swap atom type

variable random1 equal floor(random(1.0,5.9999999,52344625))
variable random2 equal floor(random(1.0,5.9999999,84646342))

variable RunMC loop 1 15000

label MC

label RandomType

variable r1 equal {random1} variable r2 equal {random2}

if “{r1} >= {r2}” then &
"jump {linkdir}/{InputName} RandomType "

print “{r1}" print "{r2}”

fix mc all atom/swap 1 100 141239 300 ke yes types {r1} {r2}
run 1
unfix mc

#write_restart restart.mc
#clear
#read_restart restart.mc

#pair_style eam/alloy
#pair_coeff * * ${linkdir}/FeNiCrCoCu.eam.alloy Fe Ni Cr Co Cu

next RunMC
jump {linkdir}/{InputName} MC

unfix ED

Please always let us know which LAMMPS version you are using and on what platform you are running your calculations.

How do you determine that your calculation needs a large amount of memory? And how large? Is it a gradual increase or suddenly?

The example input below is incomplete and thus insufficient to debug and test. Hence it is not possible to determine the cause and make a suggestion for a remedy.
Please provide a small and complete and fast to run test input that we can examine and investigate for memory leaks or similar issues.

Thanks,
Axel.

Hi Axel,

Thanks for your quick response,
I use the 29Oct2020 version lammps on a high performance computer (UF hipergator). I think it a linux platform.

I know it require a large amount of memory because the job was failed due to out of memory. The memory should be enough since I had many MD job with same number of atoms. I think it gradually increased, because if I required a larger amount of memory, the MC simulation could run longer. I required about ten times larger memory for the MC simulation than a MD simulation with same amount of atoms.

I just created an toy model. The memory I required is 200Mb and 300Mb. The job with 300Mb can run longer than the job with 200Mb(both of them would failed due to out of memory)

The input file is :

#Create log file
variable A string “0”
variable InputName string “in.mc.test”

log log.MC.test
print “With new displace_atoms.cpp” screen yes

#Units and boundary conditions
units lj
atom_style atomic
atom_modify map array sort 0 0.0

#Variables to build parameters

units lj
atom_style atomic
atom_modify map array sort 0 0.0

dimension 2

lattice hex 1
region box block 0 20 0 20 -0.5 0.5

create_box 5 box
create_atoms 5 box
mass 1 1.0
mass 2 1.1
mass 3 1.2
mass 4 1.3
mass 5 1.4

pair_style lj/cut 2.5
pair_coeff * * 1.0 1.0 2.5
pair_modify shift yes

neighbor 0.3 bin
neigh_modify delay 0 every 1 check yes

#Define output frequency and styles
thermo 1
thermo_style custom step temp epair etotal lx ly lz yz xz xy

#get original energy
run 0
variable ETotal equal “pe”
variable ETotal0 equal ${ETotal}
variable EChange equal “(etotal-v_ETotal0)”

#####Monte Carlo
##region to do monte carlo
fix ED all print 1 “${EChange}” append “EDelta.txt” screen “no”

#Randomly select swap atom type

variable random1 equal floor(random(1.0,5.9999999,52344625))
variable random2 equal floor(random(1.0,5.9999999,84646342))

variable RunMC loop 1 15000

label MC

label RandomType

variable r1 equal {random1} variable r2 equal {random2}

if “{r1} >= {r2}” then &
"jump in.mc.test RandomType "

print “{r1}" print "{r2}”

fix mc all atom/swap 1 100 141239 300 ke yes types {r1} {r2}
run 1
unfix mc

next RunMC
jump in.mc.test MC

2 Likes

Thanks for providing a test case. I have run some tests based on it and found that there is indeed a memory leak in fix atom/swap that is leaking some memory every time you unfix it and then create it new with another fix command. To plug the leak you need to add two function calls to the FixAtomSwap::~FixAtomSwap() function in src/MS/fix_atom_swap.cpp:

memory->destroy(local_swap_iatom_list);
memory->destroy(local_swap_jatom_list);

After recompilation it should not leak memory anymore.

The change will be included in a future patch release of LAMMPS:

Thanks for your help. I really appreciate it.