# LAMMPS in Windows and Linux

Hi,
We are using both the Windows (28 March 2023) and Linux (24 March 2022) versions of LAMMPS to execute the same code, which was developed by a previous member of our group. Our workflow comprises various steps, including sample preparation, sample densification, and cyclic thermal loading involving both heating and cooling phases. While we encounter no issues when running the code for sample preparation, densification, etc., on both Windows and Linux systems, we face errors specifically during the thermal cycling phase when running on Linux. These errors occur after the completion of the first heating cycle and seem to be related to the generation of the restart file, since when we stop the process of saving this file, the code continues running smoothly. However, itâ€™s crucial for us to save the data after each cycle. It is worth mentioning that no such errors are observed when running the code on Windows. Also, the Linux version is installed on our HPC system.
This is the part of the code that is related to the heating/cooling cycle:

# ---- HEATING - COOLING CYCLES ----

print " WARNING: THE VALUES OF Nrun AND Ndump ARE OVERWRITTEN"

## Degenerate case of heating or cooling only, i.e. no cycle, when Ncycle = 0

if â€ś\${Ncycle}==0â€ť then &
â€śvariable cycleloop equal 0â€ť &
â€śjump SELF labelcycleloopâ€ť

variable cycleloop loop \${Ncycle} # Ncycle cycles of heating and cooling
label labelcycleloop

variable phaseloop loop 2 # Repeats each phase (heating and cooling) with different parameters
label labelphaseloop

``````if "(\${HEATING_FIRST} && \${phaseloop}==1) || (!\${HEATING_FIRST} && \${phaseloop}==2)" then &
"variable HEATING equal true # Heating -> increase particles dimensions" &
"variable In0 equal \${In0_heat} # Overwrite the inertial number for heating phase" &
"variable heat_cool_str string heating # For output files naming" &
"variable Nrun equal \${Nrun_heat}" &
"variable DTramp equal \${DTstep}" &
"print '					HEATING, cycle \$(v_cycleloop)'" &
elif "(!\${HEATING_FIRST} && \${phaseloop}==1) || (\${HEATING_FIRST} && \${phaseloop}==2)" &
"variable HEATING equal false # Cooling -> decrease particles dimensions" &
"variable In0 equal \${In0_cool} # Overwrite the inertial number for cooling phase" &
"variable heat_cool_str string cooling # For output files naming" &
"variable DTramp equal -\${DTstep}" &
"variable Nrun equal \${Nrun_cool}" &
"print '					COOLING, cycle \$(v_cycleloop)'" &
else "print 'Script Error: flag HEATING_FIRST should have value true or false and was given \$(v_HEATING_FIRST)'" "quit"

variable steploop loop \$(floor(v_DTtarget/v_DTstep+0.5)) # Heating/Cooling in steps of DTstep: ramp + equilibrium
label labelsteploop

#Boundary conditions
if "\${HEATCOOL_ISO}" then "include in.PRESET_BC_control_ISO_3 # preset isotropic conditions during heating/cooling" &
elif "!\${HEATCOOL_ISO}" &
"include in.PRESET_BC_control_HC_OEDO_3 # preset oedometric conditions with ring expansion during heating/cooling" &
"variable logstrain equal ln(1.0+v_DTcurrent*v_lcte_ring) # Radial strain due to ring thermal expansion" &
"variable BC_XX_TARGET equal v_logstrain #Overwrite Strain-controlled deformation in the x-direction" &
"variable BC_YY_TARGET equal v_logstrain #Overwrite Strain-controlled deformation in the y-direction" &
else "print 'Script Error: flag HEATCOOL_ISO should have value true or false and was given \$(v_HEATCOOL_ISO)'" "quit"

# Temperature variation ramp
if "!\${FIXED}" then "include in.START_BC_control_3 # Start boundary controller only if simulation not in fixed box"
thermo_style custom step v_DTcurrent v_epsv v_pxx v_pyy v_pzz v_press v_qdev v_pxy v_pxz v_pyz v_convke v_convufr v_convfres v_convtqres
thermo_modify warn reset # Reset warning counter to avoid "Too many warning" messages that break Pizza.py post-processing of log files
variable DTstart equal \${DTcurrent}
variable DTstop equal \$(v_DTstart+v_DTramp)
variable DTcurrent equal ramp(\${DTstart},\${DTstop})
thermo \${Nthermo}
run \${Nrun}
variable DTcurrent equal \${DTstop}
variable DTprior equal \${DTcurrent}
if "!\${FIXED}" then "include in.STOP_BC_control_3 # Stop boundary controller only if simulation not in fixed box"

# Equilibrium
if "!\${FIXED}" then "include in.START_BC_control_3 # Start boundary controller only if simulation not in fixed box"
include in.PRESET_equilibrium_all_3 # Sets equilibrium conditions on all variables
include in.START_equilibrium_3
thermo_style custom step v_convke v_convufr v_convfres v_convtqres v_pxx v_pyy v_pzz v_press v_qdev v_pxy v_pxz v_pyz v_pf
thermo \${Nthermo}
run \${Nmax} # Will be stopped at equilibrium
if "!\${FIXED}" then "include in.STOP_BC_control_3 # Stop boundary controller only if simulation not in fixed box"
include in.STOP_equilibrium_3

# Save equilibrium state at the end of the step
if "(\${HEATING} && \${SAVE_HEATING}) || (!\${HEATING} && \${SAVE_COOLING})" then &
"variable fname_write_restart string '\${pathstr}/restart.after_\${heat_cool_str}_cycle_\${cycleloop}_step_\${steploop}\${suffixstr}' # Name of restart file written with absolute path" &
"variable fname_write_dump_co string '\${pathstr}/dump.co_sample_after_\${heat_cool_str}_cycle_\${cycleloop}_step_\${steploop}\${suffixstr}.lammpstrj' # Name of coordinates dump file written with absolute path" &
"variable fname_write_dump_topo string '\${pathstr}/dump.topo_sample_after_\${heat_cool_str}_cycle_\${cycleloop}_step_\${steploop}\${suffixstr}.lammpstrj' # Name of coordinates dump file written with absolute path" &
"thermo_style custom step v_DTcurrent v_epsx v_epsy v_epsz v_epsv v_pf v_pxx v_pyy v_pzz v_press v_qdev v_pxy v_pxz v_pyz # 15 entries" &
"dump dump_co particles custom 1 \${fname_write_dump_co} id x y z diameter" &
"dump_modify dump_co sort id" &
"dump dump_topo particles local 1 \${fname_write_dump_topo} c_final_geometry[*] c_final_topology[*]" &
"log \${fname_write_log_eq} append" &
"run 0 # To save state in log file for post-processing" &
"log \${fname_write_log} append" &
"undump dump_co" &
"undump dump_topo" &
"write_restart \${fname_write_restart} # Save current state"

next steploop
jump SELF labelsteploop

## Degenerate case of heating or cooling only, i.e. no cycle, when Ncycle = 0
if "\${Ncycle}==0" then &
"print 'DEGENERATE SIMULATION, MONOTONIC HEATING/COOLING ONLY: END OF SIMULATION'" &
"quit"
``````

next phaseloop
jump SELF labelphaseloop

next cycleloop
jump SELF labelcycleloop

Besides pasting your input script as pre-formatted text (Please Read This First: Guidelines and Suggestions for posting LAMMPS questions), I would compile a newer version of LAMMPS on the Linux cluster. Too trivial?

I cannot understand if the code you are referring to is the hellish script snippet that you kindly shared â€“ which is of no useâ€“, or some custom package that is used by the script. Please explain.

1 Like

Check character encodings and file paths â€“ if thereâ€™s a subtle-but-easy bug causing cross-OS inconsistency itâ€™s usually one of those. See for example the usage of programs like `unix2dos` and `dos2unix`.

Having said that, the usual debugging steps apply: start with small simple scripts that work on both systems. Add things on one at a time. Keep notes; version control if you know how to (with `git` for example). And remember: the best code is no code at all.

1 Like