LAMMPS + TDM-GCC-64 + Win7 + MATLAB R2015b + Gnumex By R.L. Carino (carino@cavs.msstate.edu) A. Software setup 1. MinGW, download installer from http://sourceforge.net/projects/mingw/?source=directory. Install gcc, g++, gfortran and MSYS. We do not use the compilers (these are 32-bit), but we need MSYS for a Unix-like compilation environment. Install to C:\Mingw. Add C:\MinGW\msys\1.0\bin to PATH environment variable. 2. TDM-GCC-64 (install to C:\TDM-GCC-64, add C:\TDM-GCC-64\bin to PATH environment variable). I used the installer https://sourceforge.net/projects/tdm-gcc/files/TDM-GCC%20Installer/tdm64-gcc-5.1.0-2.exe/download After installation of TDM-GCC-64, edit C:\MinGW\msys\1.0\etc\fstab, to look like: # /etc/fstab -- mount table configuration for MSYS. # Please refer to /etc/fstab.sample for explanatory annotation. # MSYS-Portable needs this "magic" comment: # MSYSROOT=C:/MinGW/msys/1.0 # Win32_Path Mount_Point #------------------------------------- ----------- #C:/MinGW /mingw C:/TDM-GCC-64 /mingw 3. LAMMPS (14May16) from http://lammps.sandia.gov/download.html (place in C:\lammps-14May16) 4. MATLAB R2015b (Windows 64-bit) - pre-installed on my machine at C:\MATLAB 5. Gnumex 2.06 from http://sourceforge.net/projects/gnumex/files/ (place in C:\Gnumex) B. Compile LAMMPS 1. Unset read-only permissions on C:\lammps-14May16\ 2. Run MSYS as Administrator. In Windows explorer, navigate to C:\MinGW\msys\1.0, right-click msys.bat, then Run as administrator. This opens a command line window. Make sure that PATH is set correctly. On the command line, $ g++ -v should return Using built-in specs. COLLECT_GCC=C:\TDM-GCC-64\bin\g++.exe COLLECT_LTO_WRAPPER=C:/TDM-GCC-64/bin/../libexec/gcc/x86_64-w64-mingw32/5.1.0/lto-wrapper.exe Target: x86_64-w64-mingw32 Configured with: ../../../src/gcc-5.1.0/configure --build=x86_64-w64-mingw32 --enable-targets=all --enable-languages=ada,c,c++,fortran,lto,objc,obj-c++ --enable-libgomp --enable-lto --enable-graphite --enable-cxx-flags=-DWINPTHREAD_STATIC --disable-build-with-cxx --disable-build-poststage1-with-cxx --enable-libstdcxx-debug --enable-threads=posix --enable-version-specific-runtime-libs --enable-full y-dynamic-string --enable-libstdcxx-threads --enable-libstdcxx-time --with-gnu-ld --disable-werror --disable-nls --disable-win32-registry --prefix=/mingw64tdm --with-local-prefix=/mingw64tdm --with-pk gversion=tdm64-1 --with-bugurl=http://tdm-gcc.tdragon.net/bugs Thread model: posix gcc version 5.1.0 (tdm64-1) If not, add C:\TDM-GCC-64\bin\ to the PATH environment variable. Restart MSYS as administrator. 3. Compile libmeam.a. On MSYS command line, cd /c/lammps-14May16/lib/meam make -f Makefile.gfortran (ignore the warnings) 4. Compile libmpi_stubs.a. On MSYS command line, cd /c/lammps-14May16/src/STUBS make (ignore the warnings) 5. Fix the Makefile for compiling the LAMMPS executable and library. Using a text editor, open C:\lammps-14May16\src\MAKE\OPTIONS\Makefile.g++_serial. In the "compiler/linker settings", add -lpsapi after LIB =, i.e. LINK = g++ LINKFLAGS = -g -O LIB = -lpsapi SIZE = size Save edited file and exit text editor. 6. Compile LAMMPS executable and static library. On MSYS command line, cd /c/lammps-14May16/src make clean-all make yes-meam make g++_serial make mode=lib g++_serial (If make complains about write permissions on some file or directory, unset the Read-only flag for those files/directories, then re-run make) 7. Test the LAMMPS executable cd /c/lammps-14May16/examples/meam ../../src/lmp_serial_w64 < in.meam C. Configure MATLAB with Gnumex 1. Run MATLAB 2. Create work directory for LAMMPS-TDM-GCC-64. On the MATLAB prompt, >> mkdir LAMMPS-TDM-GCC-64 3. Setup Gnumex. On the MATLAB prompt, Open C:\Gnumex\gnumex.m Run gnumex.m (Add C:\Gnumex to path) Use the following settings on the Gnumex GUI: MinGW root directory, navigate to C:\TDM-GCC-64 Cygwin root directory, (empty) Path to g95.exe, (empty) Path to gfortran.exe, C:\TDM-GCC-64\bin Path to Gnumex utilities, navigate to C:\Gnumex Environment / linking type, select MinGW Language for compilation, select C / C++ Optimization level, select -O3 Generate mex or engine exe?, select Mex Add stub, select No Path for libraries and .def files, navigate to the LAMMPS-TDM-GCC-64 directory created above Mex options file to create, navigate to the LAMMPS-TDM-GCC-64 directory created above Click 'Make options file', wait (If Gnumex warns about not being able to write files to some MATLAB directories, follow the workarounds) Exit Gnumex GUI 4. Copy the following files to the LAMMPS-TDM-GCC-64 directory created above C:\lammps-14May16\lib\meam\libmeam.a C:\lammps-14May16\src\STUBS\libmpi_stubs.a C:\lammps-14May16\src\liblammps.a C:\lammps-14May16\src\STUBS\mpi.h C:\lammps-14May16\src\library.h lammps_*.c gateway functions (from Kip Barret) lammps_MPCv3.m (from Kip Barret) lammps_setup_TDM-GCC-64.m (attached; from Kip Barrett, modified) test_run_lammps_MPC.m (attached; from Kip Barrett, modified) library.meam (attached) Al-example.parameter.meam (attached) 5. In MATLAB, change directory to the LAMMPS-TDM-GCC-64 directory created above >> mex -v setup (Answer 'n' (No) to "Would you like mex to locate installed compilers [y]/n?" (Answer 'gcc' to "Select a compiler:" (Verify that "Location: C:\TDM-GCC-64\bin") (Answer 'y' to "Are these correct [y]/n?") >> lammps_setup_TDM-GCC-64 (ignore lots of warnings) 6. Test the *.mexw64 >> test_run_lammps_MPC The following should display: Return values are: - SingleElement: temp E0 box alpha rose_a rose_E E1 a1 E1box_volume E1box_b_a E1box_c_a E1box_c_b E1box_b_a_angle E1box_c_a_angle E1box_c_b_angle E1box_ratios E1box_angles E2 a2 box2 E2box_volume E2box_b_a E2box_c_a E2box_c_b E2box_b_a_angle E2box_c_a_angle E2box_c_b_angle E2box_ratios E2box_angles E3 a3 box3 E3box_volume E3box_b_a E3box_c_a E3box_c_b E3box_b_a_angle E3box_c_a_angle E3box_c_b_angle E3box_ratios E3box_angles - Alloy: temp Substitution ans = SingleElement: [1x1 struct] Alloy: [1x1 struct] You can then use the workspace browser of MATLAB to examine 'ans'