Merge branch 'master' into lammps-icms

This commit is contained in:
Axel Kohlmeyer
2012-08-18 17:17:35 -04:00
22 changed files with 1349 additions and 1183 deletions

View File

@ -58,12 +58,13 @@ operations within LAMMPS, such as running a simulation for a
reasonable number of timesteps, then the overhead cost of invoking
LAMMPS thru Python will be negligible.
</P>
<P>Before using LAMMPS from a Python script, you have to do two things.
You need to set two environment variables. And you need to build
LAMMPS as a dynamic shared library, so it can be loaded by Python.
Both these steps are discussed below. If you wish to run LAMMPS in
parallel from Python, you also need to extend your Python with MPI.
This is also discussed below.
<P>Before using LAMMPS from a Python script, you need to do two things.
You need to build LAMMPS as a dynamic shared library, so it can be
loaded by Python. And you need to tell Python how to find the library
and the Python wrapper file python/lammps.py. Both these steps are
discussed below. If you wish to run LAMMPS in parallel from Python,
you also need to extend your Python with MPI. This is also discussed
below.
</P>
<P>The Python wrapper for LAMMPS uses the amazing and magical (to me)
"ctypes" package in Python, which auto-generates the interface code
@ -131,7 +132,7 @@ python/lammps.py file.
</P>
<P>You can invoke install.py from the python directory as
</P>
<PRE>% python install.py <B>libdir</B> <B>pydir</B>
<PRE>% python install.py [libdir] [pydir]
</PRE>
<P>The optional libdir is where to copy the LAMMPS shared library to; the
default is /usr/local/lib. The optional pydir is where to copy the
@ -146,12 +147,12 @@ non-standard locations, such as within your own user space, you will
need to set your PYTHONPATH and LD_LIBRARY_PATH environment variables
accordingly, as above.
</P>
<P>If the instally.py script does not allow you to copy files into system
<P>If the install.py script does not allow you to copy files into system
directories, prefix the python command with "sudo". If you do this,
make sure that the Python that root runs is the same as the Python you
run. E.g. you may need to do something like
</P>
<PRE>% sudo /usr/local/bin/python install.py <B>libdir</B> <B>pydir</B>
<PRE>% sudo /usr/local/bin/python install.py [libdir] [pydir]
</PRE>
<P>You can also invoke install.py from the make command in the src
directory as
@ -269,20 +270,27 @@ and type:
<PRE>>>> from lammps import lammps
>>> lmp = lammps()
</PRE>
<P>If you get no errors, you're ready to use LAMMPS from Python.
If the load fails, the most common error to see is
<P>If you get no errors, you're ready to use LAMMPS from Python. If the
2nd command fails, the most common error to see is
</P>
<PRE>OSError: Could not load LAMMPS dynamic library
</PRE>
<P>which means Python was unable to load the LAMMPS shared library. This
typically occurs if the system can't find the LAMMMPS shared library
or one of the auxiliary shared libraries it depends on.
typically occurs if the system can't find the LAMMPS shared library or
one of the auxiliary shared libraries it depends on, or if something
about the library is incompatible with your Python. The error message
should give you an indication of what went wrong.
</P>
<P>Python (actually the operating system) isn't verbose about telling you
why the load failed, so carefully go through the steps above regarding
environment variables, and the instructions in <A HREF = "Section_start.html#start_5">Section_start
5</A> about building a shared library and
about setting the LD_LIBRARY_PATH envirornment variable.
<P>You can also test the load directly in Python as follows, without
first importing from the lammps.py file:
</P>
<PRE>>>> from ctypes import CDLL
>>> CDLL("liblammps.so")
</PRE>
<P>If an error occurs, carefully go thru the steps in <A HREF = "Section_start.html#start_5">Section_start
5</A> and above about building a shared
library and about insuring Python can find the necessary two files
it needs.
</P>
<H5><B>Test LAMMPS and Python in serial:</B>
</H5>

View File

@ -55,12 +55,13 @@ operations within LAMMPS, such as running a simulation for a
reasonable number of timesteps, then the overhead cost of invoking
LAMMPS thru Python will be negligible.
Before using LAMMPS from a Python script, you have to do two things.
You need to set two environment variables. And you need to build
LAMMPS as a dynamic shared library, so it can be loaded by Python.
Both these steps are discussed below. If you wish to run LAMMPS in
parallel from Python, you also need to extend your Python with MPI.
This is also discussed below.
Before using LAMMPS from a Python script, you need to do two things.
You need to build LAMMPS as a dynamic shared library, so it can be
loaded by Python. And you need to tell Python how to find the library
and the Python wrapper file python/lammps.py. Both these steps are
discussed below. If you wish to run LAMMPS in parallel from Python,
you also need to extend your Python with MPI. This is also discussed
below.
The Python wrapper for LAMMPS uses the amazing and magical (to me)
"ctypes" package in Python, which auto-generates the interface code
@ -127,7 +128,7 @@ python/lammps.py file.
You can invoke install.py from the python directory as
% python install.py [libdir] [pydir] :pre
% python install.py \[libdir\] \[pydir\] :pre
The optional libdir is where to copy the LAMMPS shared library to; the
default is /usr/local/lib. The optional pydir is where to copy the
@ -142,12 +143,12 @@ non-standard locations, such as within your own user space, you will
need to set your PYTHONPATH and LD_LIBRARY_PATH environment variables
accordingly, as above.
If the instally.py script does not allow you to copy files into system
If the install.py script does not allow you to copy files into system
directories, prefix the python command with "sudo". If you do this,
make sure that the Python that root runs is the same as the Python you
run. E.g. you may need to do something like
% sudo /usr/local/bin/python install.py [libdir] [pydir] :pre
% sudo /usr/local/bin/python install.py \[libdir\] \[pydir\] :pre
You can also invoke install.py from the make command in the src
directory as
@ -265,20 +266,27 @@ and type:
>>> from lammps import lammps
>>> lmp = lammps() :pre
If you get no errors, you're ready to use LAMMPS from Python.
If the load fails, the most common error to see is
If you get no errors, you're ready to use LAMMPS from Python. If the
2nd command fails, the most common error to see is
OSError: Could not load LAMMPS dynamic library :pre
which means Python was unable to load the LAMMPS shared library. This
typically occurs if the system can't find the LAMMMPS shared library
or one of the auxiliary shared libraries it depends on.
typically occurs if the system can't find the LAMMPS shared library or
one of the auxiliary shared libraries it depends on, or if something
about the library is incompatible with your Python. The error message
should give you an indication of what went wrong.
Python (actually the operating system) isn't verbose about telling you
why the load failed, so carefully go through the steps above regarding
environment variables, and the instructions in "Section_start
5"_Section_start.html#start_5 about building a shared library and
about setting the LD_LIBRARY_PATH envirornment variable.
You can also test the load directly in Python as follows, without
first importing from the lammps.py file:
>>> from ctypes import CDLL
>>> CDLL("liblammps.so") :pre
If an error occurs, carefully go thru the steps in "Section_start
5"_Section_start.html#start_5 and above about building a shared
library and about insuring Python can find the necessary two files
it needs.
[Test LAMMPS and Python in serial:] :h5

View File

@ -850,7 +850,7 @@ should be the file /usr/local/lib/libmpich.so.
the environment variable LD_LIBRARY_PATH. So you may wish to copy the
file src/liblammps.so or src/liblammps_g++.so (for example) to a place
the system can find it by default, such as /usr/local/lib, or you may
wish to add the lammps src directory to LD_LIBRARY_PATH, so that the
wish to add the LAMMPS src directory to LD_LIBRARY_PATH, so that the
current version of the shared library is always available to programs
that use it.
</P>

View File

@ -844,7 +844,7 @@ The operating system finds shared libraries to load at run-time using
the environment variable LD_LIBRARY_PATH. So you may wish to copy the
file src/liblammps.so or src/liblammps_g++.so (for example) to a place
the system can find it by default, such as /usr/local/lib, or you may
wish to add the lammps src directory to LD_LIBRARY_PATH, so that the
wish to add the LAMMPS src directory to LD_LIBRARY_PATH, so that the
current version of the shared library is always available to programs
that use it.

View File

@ -30,6 +30,7 @@
#include <compute.h>
#include <modify.h>
#include <error.h>
#include <cstdlib>
using namespace LAMMPS_NS;

View File

@ -21,12 +21,6 @@
library.h. All prototypes herein COULD be added to library.h instead of
including this as a separate file. See the README for instructions. */
/* These prototypes probably belong in mpi.h in the src/STUBS directory. */
#ifndef OPEN_MPI
#define MPI_Comm_f2c(a) a
#define MPI_Fint int
#endif
#ifdef __cplusplus
extern "C" {
#endif
@ -38,7 +32,7 @@ int lammps_extract_compute_vectorsize (void*, char*, int);
void lammps_extract_compute_arraysize (void*, char*, int, int*, int*);
int lammps_extract_fix_vectorsize (void*, char*, int);
void lammps_extract_fix_arraysize (void*, char*, int, int*, int*);
void lammps_error_all (void *ptr, const char*, int, const char*);
void lammps_error_all (void*, const char*, int, const char*);
#ifdef __cplusplus
}

View File

@ -39,8 +39,8 @@
!! subroutine lammps_extract_compute (compute, ptr, id, style, type)
!! subroutine lammps_extract_variable (variable, ptr, name, group)
!! function lammps_get_natoms (ptr)
!! subroutine lammps_get_coords (ptr, coords)
!! subroutine lammps_put_coords (ptr, coords)
!! subroutine lammps_gather_atoms (ptr, name, count, data)
!! subroutine lammps_scatter_atoms (ptr, name, data)
#define FLERR __FILE__,__LINE__
! The above line allows for similar error checking as is done with standard
@ -55,8 +55,9 @@ module LAMMPS
public :: lammps_open, lammps_open_no_mpi, lammps_close, lammps_file, &
lammps_command, lammps_free, lammps_extract_global, &
lammps_extract_atom, lammps_extract_compute, lammps_extract_fix, &
lammps_extract_variable, lammps_get_natoms, lammps_get_coords, &
lammps_put_coords, lammps_instance
lammps_extract_variable, lammps_get_natoms, lammps_gather_atoms, &
lammps_scatter_atoms
public :: lammps_instance
!! Functions supplemental to the prototypes in library.h. {{{1
!! The function definitions (in C++) are contained in LAMMPS-wrapper.cpp.
@ -204,18 +205,21 @@ module LAMMPS
integer (C_int) :: natoms
end function lammps_get_natoms
subroutine lammps_actual_get_coords (ptr, coords) &
bind (C, name='lammps_get_coords')
import :: C_ptr
type (C_ptr), value :: ptr, coords
end subroutine lammps_actual_get_coords
subroutine lammps_actual_gather_atoms (ptr, name, type, count, data) &
bind (C, name='lammps_gather_atoms')
import :: C_ptr, C_int, C_char
type (C_ptr), value :: ptr, data
character (kind=C_char), dimension(*) :: name
integer (C_int), value :: type, count
end subroutine lammps_actual_gather_atoms
subroutine lammps_actual_put_coords (ptr, coords) &
bind (C, name='lammps_put_coords')
import :: C_ptr, C_double
type (C_ptr), value :: ptr
real (C_double), dimension(*) :: coords
end subroutine lammps_actual_put_coords
subroutine lammps_actual_scatter_atoms (ptr, name, type, count, data) &
bind (C, name='lammps_scatter_atoms')
import :: C_ptr, C_int, C_char
type (C_ptr), value :: ptr, data
character (kind=C_char), dimension(*) :: name
integer (C_int), value :: type, count
end subroutine lammps_actual_scatter_atoms
end interface
! Generic functions for the wrappers below {{{1
@ -258,6 +262,16 @@ module LAMMPS
lammps_extract_variable_dpa
end interface lammps_extract_variable
interface lammps_gather_atoms
module procedure lammps_gather_atoms_ia, lammps_gather_atoms_dpa, &
lammps_gather_atoms_ra
end interface lammps_gather_atoms
interface lammps_scatter_atoms
module procedure lammps_scatter_atoms_ia, lammps_scatter_atoms_dpa, &
lammps_scatter_atoms_ra
end interface lammps_scatter_atoms
contains !! Wrapper functions local to this module {{{1
subroutine lammps_open (command_line, communicator, ptr)
@ -374,7 +388,6 @@ contains !! Wrapper functions local to this module {{{1
integer (C_int), pointer :: Fptr
integer :: natoms
natoms = lammps_get_natoms (ptr)
if ( allocated (atom) ) deallocate (atom)
allocate (atom(natoms))
Cptr = lammps_extract_atom_Cptr (ptr, name)
call C_F_pointer (Cptr, Fptr, (/natoms/))
@ -399,7 +412,6 @@ contains !! Wrapper functions local to this module {{{1
! Everything else we can get is probably nlocal units long
call lammps_extract_global_i (nelements, ptr, 'nlocal')
end if
if ( allocated (atom) ) deallocate (atom)
allocate (atom(nelements))
Cptr = lammps_extract_atom_Cptr (ptr, name)
if ( name == 'mass' ) then
@ -417,7 +429,6 @@ contains !! Wrapper functions local to this module {{{1
character (len=*), intent(in) :: name
double precision, dimension(:), allocatable :: d_atom
call lammps_extract_atom_dpa (d_atom, ptr, name)
if ( allocated (atom) ) deallocate (atom)
allocate (atom(size(d_atom)))
atom = real(d_atom)
deallocate (d_atom)
@ -428,7 +439,6 @@ contains !! Wrapper functions local to this module {{{1
character (len=*), intent(in) :: name
type (C_ptr) :: Cptr
integer :: nelements
if ( allocated (atom) ) deallocate (atom)
if ( name /= 'x' .and. name /= 'v' .and. name /= 'f' ) then
call lammps_error_all (ptr, FLERR, 'You cannot extract ' // name // &
' into a rank 2 array.')
@ -445,7 +455,6 @@ contains !! Wrapper functions local to this module {{{1
character (len=*), intent(in) :: name
double precision, dimension(:,:), allocatable :: d_atom
call lammps_extract_atom_dp2a (d_atom, ptr, name)
if ( allocated (atom) ) deallocate (atom)
if ( allocated (d_atom) ) then
allocate (atom(size(d_atom,1), size(d_atom,2)))
else
@ -515,7 +524,6 @@ contains !! Wrapper functions local to this module {{{1
type (C_ptr) :: Cptr
real (C_double), dimension(:), pointer :: Fptr
integer :: nelements
if ( allocated (compute) ) deallocate (compute)
! Check for the correct dimensionality
if ( type == 0 ) then
call lammps_error_all (ptr, FLERR, 'You cannot extract a compute&
@ -541,7 +549,6 @@ contains !! Wrapper functions local to this module {{{1
integer, intent(in) :: style, type
double precision, dimension(:), allocatable :: d_compute
call lammps_extract_compute_dpa (d_compute, ptr, id, style, type)
if ( allocated (compute) ) deallocate (compute)
allocate (compute(size(d_compute)))
compute = real(d_compute)
deallocate (d_compute)
@ -554,7 +561,6 @@ contains !! Wrapper functions local to this module {{{1
type (C_ptr) :: Cptr
real (C_double), dimension(:,:), pointer :: Fptr
integer :: nr, nc
if ( allocated (compute) ) deallocate (compute)
! Check for the correct dimensionality
if ( type == 0 ) then
call lammps_error_all (ptr, FLERR, 'You cannot extract a compute&
@ -580,7 +586,6 @@ contains !! Wrapper functions local to this module {{{1
integer, intent(in) :: style, type
double precision, dimension(:,:), allocatable :: d_compute
call lammps_extract_compute_dp2a (d_compute, ptr, id, style, type)
if ( allocated (compute) ) deallocate (compute)
allocate (compute(size(d_compute,1), size(d_compute,2)))
compute = real(d_compute)
deallocate (d_compute)
@ -658,7 +663,6 @@ contains !! Wrapper functions local to this module {{{1
type (C_ptr) :: Cptr
real (C_double), dimension(:), pointer :: Fptr
integer :: fix_len
if ( allocated (fix) ) deallocate (fix)
! Check for the correct dimensionality
if ( style == 0 ) then
call lammps_error_all (ptr, FLERR, 'You can''t extract the&
@ -692,7 +696,6 @@ contains !! Wrapper functions local to this module {{{1
integer, intent(in) :: style, type, i, j
double precision, dimension(:), allocatable :: d_fix
call lammps_extract_fix_dpa (d_fix, ptr, id, style, type, i, j)
if ( allocated (fix) ) deallocate (fix)
allocate (fix(size(d_fix)))
fix = real(d_fix)
deallocate (d_fix)
@ -705,7 +708,6 @@ contains !! Wrapper functions local to this module {{{1
type (C_ptr) :: Cptr
real (C_double), dimension(:,:), pointer :: Fptr
integer :: nr, nc
if ( allocated (fix) ) deallocate (fix)
! Check for the correct dimensionality
if ( style == 0 ) then
call lammps_error_all (ptr, FLERR, 'It is not possible to extract the&
@ -735,7 +737,6 @@ contains !! Wrapper functions local to this module {{{1
integer, intent(in) :: style, type, i, j
double precision, dimension(:,:), allocatable :: d_fix
call lammps_extract_fix_dp2a (d_fix, ptr, id, style, type, i, j)
if ( allocated (fix) ) deallocate (fix)
allocate (fix(size(d_fix,1), size(d_fix,2)))
fix = real(d_fix)
deallocate (d_fix)
@ -824,7 +825,6 @@ contains !! Wrapper functions local to this module {{{1
Cptr = lammps_extract_variable_Cptr (ptr, name)
end if
natoms = lammps_get_natoms (ptr)
if ( allocated (variable) ) deallocate (variable)
allocate (variable(natoms))
call C_F_pointer (Cptr, Fptr, (/natoms/))
variable = Fptr
@ -845,7 +845,6 @@ contains !! Wrapper functions local to this module {{{1
Cptr = lammps_extract_variable_Cptr (ptr, name)
end if
natoms = lammps_get_natoms (ptr)
if ( allocated (variable) ) deallocate (variable)
allocate (variable(natoms))
call C_F_pointer (Cptr, Fptr, (/natoms/))
variable = Fptr
@ -863,7 +862,6 @@ contains !! Wrapper functions local to this module {{{1
else
call lammps_extract_variable_dpa (d_var, ptr, name)
end if
if ( allocated (variable) ) deallocate (variable)
allocate (variable(size(d_var)))
variable = real(d_var)
deallocate (d_var)
@ -871,32 +869,146 @@ contains !! Wrapper functions local to this module {{{1
!-------------------------------------------------------------------------2}}}
subroutine lammps_get_coords (ptr, coords)
type (C_ptr) :: ptr
double precision, dimension(:), allocatable :: coords
real (C_double), dimension(:), allocatable, target :: C_coords
integer :: natoms
subroutine lammps_gather_atoms_ia (ptr, name, count, data)
type (C_ptr), intent(in) :: ptr
character (len=*), intent(in) :: name
integer, intent(in) :: count
integer, dimension(:), allocatable, intent(out) :: data
type (C_ptr) :: Cdata
integer (C_int), dimension(:), pointer :: Fdata
integer (C_int) :: natoms
character (kind=C_char), dimension(len_trim(name)) :: Cname
integer (C_int), parameter :: Ctype = 0
integer (C_int) :: Ccount
natoms = lammps_get_natoms (ptr)
if ( allocated(coords) ) deallocate (coords)
allocate (coords(3*natoms))
allocate (C_coords(3*natoms))
call lammps_actual_get_coords (ptr, C_loc(C_coords))
coords = C_coords
deallocate (C_coords)
end subroutine lammps_get_coords
Cname = string2Cstring (name)
if ( count /= 1 .and. count /= 3 ) then
call lammps_error_all (ptr, FLERR, 'lammps_gather_atoms requires&
& count to be either 1 or 3')
else
Ccount = count
end if
allocate ( Fdata(count*natoms) )
allocate ( data(count*natoms) )
Cdata = C_loc (Fdata(1))
call lammps_actual_gather_atoms (ptr, Cname, Ctype, Ccount, Cdata)
data = Fdata
deallocate (Fdata)
end subroutine lammps_gather_atoms_ia
subroutine lammps_gather_atoms_dpa (ptr, name, count, data)
type (C_ptr), intent(in) :: ptr
character (len=*), intent(in) :: name
integer, intent(in) :: count
double precision, dimension(:), allocatable, intent(out) :: data
type (C_ptr) :: Cdata
real (C_double), dimension(:), pointer :: Fdata
integer (C_int) :: natoms
character (kind=C_char), dimension(len_trim(name)) :: Cname
integer (C_int), parameter :: Ctype = 1
integer (C_int) :: Ccount
natoms = lammps_get_natoms (ptr)
Cname = string2Cstring (name)
if ( count /= 1 .and. count /= 3 ) then
call lammps_error_all (ptr, FLERR, 'lammps_gather_atoms requires&
& count to be either 1 or 3')
else
Ccount = count
end if
allocate ( Fdata(count*natoms) )
allocate ( data(count*natoms) )
Cdata = C_loc (Fdata(1))
call lammps_actual_gather_atoms (ptr, Cname, Ctype, Ccount, Cdata)
data = Fdata(:)
deallocate (Fdata)
end subroutine lammps_gather_atoms_dpa
subroutine lammps_gather_atoms_ra (ptr, name, count, data)
type (C_ptr), intent(in) :: ptr
character (len=*), intent(in) :: name
integer, intent(in) :: count
real, dimension(:), allocatable, intent(out) :: data
double precision, dimension(:), allocatable :: d_data
call lammps_gather_atoms_dpa (ptr, name, count, d_data)
allocate (data(size(d_data)))
data = d_data
deallocate (d_data)
end subroutine lammps_gather_atoms_ra
!-----------------------------------------------------------------------------
subroutine lammps_put_coords (ptr, coords)
type (C_ptr) :: ptr
double precision, dimension(:) :: coords
real (C_double), dimension(size(coords)) :: C_coords
C_coords = coords
call lammps_actual_put_coords (ptr, C_coords)
end subroutine lammps_put_coords
subroutine lammps_scatter_atoms_ia (ptr, name, data)
type (C_ptr), intent(in) :: ptr
character (len=*), intent(in) :: name
integer, dimension(:), intent(in) :: data
integer (kind=C_int) :: natoms, Ccount
integer (kind=C_int), parameter :: Ctype = 0
character (kind=C_char), dimension(len_trim(name)) :: Cname
integer, dimension(size(data)), target :: Fdata
type (C_ptr) :: Cdata
natoms = lammps_get_natoms (ptr)
Cname = string2Cstring (name)
Ccount = size(data) / natoms
if ( Ccount /= 1 .and. Ccount /= 3 ) &
call lammps_error_all (ptr, FLERR, 'lammps_gather_atoms requires&
& count to be either 1 or 3')
Fdata = data
Cdata = C_loc (Fdata(1))
call lammps_actual_scatter_atoms (ptr, Cname, Ctype, Ccount, Cdata)
end subroutine lammps_scatter_atoms_ia
subroutine lammps_scatter_atoms_dpa (ptr, name, data)
type (C_ptr), intent(in) :: ptr
character (len=*), intent(in) :: name
double precision, dimension(:), intent(in) :: data
integer (kind=C_int) :: natoms, Ccount
integer (kind=C_int), parameter :: Ctype = 0
character (kind=C_char), dimension(len_trim(name)) :: Cname
double precision, dimension(size(data)), target :: Fdata
type (C_ptr) :: Cdata
natoms = lammps_get_natoms (ptr)
Cname = string2Cstring (name)
Ccount = size(data) / natoms
if ( Ccount /= 1 .and. Ccount /= 3 ) &
call lammps_error_all (ptr, FLERR, 'lammps_gather_atoms requires&
& count to be either 1 or 3')
Fdata = data
Cdata = C_loc (Fdata(1))
call lammps_actual_scatter_atoms (ptr, Cname, Ctype, Ccount, Cdata)
end subroutine lammps_scatter_atoms_dpa
subroutine lammps_scatter_atoms_ra (ptr, name, data)
type (C_ptr), intent(in) :: ptr
character (len=*), intent(in) :: name
real, dimension(:), intent(out) :: data
double precision, dimension(size(data)) :: d_data
d_data = real (data, kind(d_data))
call lammps_scatter_atoms_dpa (ptr, name, d_data)
end subroutine lammps_scatter_atoms_ra
!-----------------------------------------------------------------------------
! subroutine lammps_get_coords (ptr, coords)
! type (C_ptr) :: ptr
! double precision, dimension(:), allocatable, intent(out) :: coords
! real (C_double), dimension(:), allocatable, target :: C_coords
! integer :: natoms
! natoms = lammps_get_natoms (ptr)
! allocate (coords(3*natoms))
! allocate (C_coords(3*natoms))
! call lammps_actual_get_coords (ptr, C_loc(C_coords))
! coords = C_coords
! deallocate (C_coords)
! end subroutine lammps_get_coords
!
!!-----------------------------------------------------------------------------
!
! subroutine lammps_put_coords (ptr, coords)
! type (C_ptr) :: ptr
! double precision, dimension(:) :: coords
! real (C_double), dimension(size(coords)) :: C_coords
! C_coords = coords
! call lammps_actual_put_coords (ptr, C_coords)
! end subroutine lammps_put_coords
!
!!-----------------------------------------------------------------------------
function lammps_extract_compute_vectorsize (ptr, id, style) &
result (vectorsize)
integer :: vectorsize

View File

@ -12,7 +12,7 @@ questions:
Karl D. Hammond
University of Tennessee, Knoxville
karlh at ugcs.caltech.edu
karlh atutk.edu
karlh at utk.edu
-------------------------------------
@ -27,7 +27,7 @@ compile.
The following steps will work to compile this module (replace ${LAMMPS_SRC}
with the path to your LAMMPS source directory):
(1) Compile LAMMPS as a static library. Call the resulting file ${LAMMPS_LIB},
which will have an actual name lake liblammps_openmpi.a. If compiling
which will have an actual name lake liblmp_openmpi.a. If compiling
using the MPI stubs in ${LAMMPS_SRC}/STUBS, you will need to know where
libmpi.a is as well (I'll call it ${MPI_STUBS} hereafter)
(2) Copy said library to your Fortran program's source directory or include
@ -61,7 +61,7 @@ with the path to your LAMMPS source directory):
need to have the .mod file from part (3).
It is also possible to add LAMMPS.o and LAMMPS-wrapper.o into the
LAMMPS library (e.g., liblammps_openmpi.a) instead of creating a separate
LAMMPS library (e.g., liblmp_openmpi.a) instead of creating a separate
library, like so:
ar rs ${LAMMPS_LIB} LAMMPS.o LAMMPS-wrapper.o
In this case, you can now use the Fortran wrapper functions as if they

View File

@ -1,7 +1,7 @@
SHELL = /bin/sh
# Path to LAMMPS extraction directory
LAMMPS_ROOT = ../svn-dist
LAMMPS_ROOT = ../../..
LAMMPS_SRC = $(LAMMPS_ROOT)/src
# Remove the line below if using mpicxx/mpic++ as your C++ compiler

View File

@ -1,35 +1,67 @@
#!/usr/local/bin/python
# copy LAMMPS shared library src/liblammps.so and lammps.py to system dirs
# Syntax: python install.py [libdir] [pydir]
# libdir = target dir for src/liblammps.so, default = /usr/local/lib
# pydir = target dir for lammps.py, default = Python site-packages dir
# copy LAMMPS src/liblammps.so and lammps.py to system dirs
import sys,commands
instructions = """
Syntax: python install.py [-h] [libdir] [pydir]
libdir = target dir for src/liblammps.so, default = /usr/local/lib
pydir = target dir for lammps.py, default = Python site-packages dir
"""
if len(sys.argv) > 3:
print "Syntax: python install.py [libdir] [pydir]"
import sys,os,commands
if (len(sys.argv) > 1 and sys.argv[1] == "-h") or len(sys.argv) > 3:
print instructions
sys.exit()
if len(sys.argv) >= 2: libdir = sys.argv[1]
else: libdir = "/usr/local/lib"
if len(sys.argv) == 3: pydir = sys.argv[2]
else: pydir = ""
# copy C lib to libdir if it exists
# warn if not in LD_LIBRARY_PATH or LD_LIBRARY_PATH is undefined
if not os.path.isdir(libdir):
print "ERROR: libdir %s does not exist" % libdir
sys.exit()
if "LD_LIBRARY_PATH" not in os.environ:
print "WARNING: LD_LIBRARY_PATH undefined, cannot check libdir %s" % libdir
else:
paths = sys.path
for i,path in enumerate(paths):
index = path.rfind("site-packages")
if index < 0: continue
if index == len(path) - len("site-packages"): break
pydir = paths[i]
libpaths = os.environ['LD_LIBRARY_PATH'].split(':')
if libdir not in libpaths:
print "WARNING: libdir %s not in LD_LIBRARY_PATH" % libdir
str = "cp ../src/liblammps.so %s" % libdir
print str
outstr = commands.getoutput(str)
if len(outstr.strip()): print outstr
str = "cp ../python/lammps.py %s" % pydir
print str
outstr = commands.getoutput(str)
if len(outstr.strip()): print outstr
# copy lammps.py to pydir if it exists
# if pydir not specified, install in site-packages via distutils setup()
if pydir:
if not os.path.isdir(pydir):
print "ERROR: pydir %s does not exist" % pydir
sys.exit()
str = "cp ../python/lammps.py %s" % pydir
print str
outstr = commands.getoutput(str)
if len(outstr.strip()): print outstr
sys.exit()
print "installing lammps.py in Python site-packages dir"
os.chdir('../python') # in case invoked via make in src dir
from distutils.core import setup
sys.argv = ["setup.py","install"] # as if had run "python setup.py install"
setup(name = "lammps",
version = "15Aug12",
author = "Steve Plimpton",
author_email = "sjplimp@sandia.gov",
url = "http://lammps.sandia.gov",
description = "LAMMPS molecular dynamics library",
py_modules = ["lammps"])

View File

@ -13,7 +13,7 @@
# Python wrapper on LAMMPS library via ctypes
import types
import sys,traceback,types
from ctypes import *
import os.path
@ -27,6 +27,8 @@ class lammps:
if not name: self.lib = CDLL("liblammps.so")
else: self.lib = CDLL("liblammps_%s.so" % name)
except:
type,value,tb = sys.exc_info()
traceback.print_exception(type,value,tb)
raise OSError,"Could not load LAMMPS dynamic library"
# create an instance of LAMMPS

View File

@ -39,6 +39,8 @@ class FFT3d : protected Pointers {
E: Could not create 3d FFT plan
The FFT setup in pppm failed.
The FFT setup for the PPPM solver failed, typically due
to lack of memory. This is an unusual error. Check the
size of the FFT grid you are requesting.
*/

View File

@ -100,7 +100,6 @@ PPPM::PPPM(LAMMPS *lmp, int narg, char **arg) : KSpace(lmp, narg, arg)
// see JCP 109, pg 7698 for derivation of coefficients
// higher order coefficients may be computed if needed
memory->destroy(acons);
memory->create(acons,8,7,"pppm:acons");
acons[1][0] = 2.0 / 3.0;
acons[2][0] = 1.0 / 50.0;

View File

@ -85,9 +85,6 @@ $(EXE): $(OBJ)
lib: $(OBJ)
$(ARCHIVE) $(ARFLAGS) $(EXE) $(OBJ)
#shlib: $(OBJ)
# $(ARCHIVE) $(ARFLAGS) $(EXE) $(OBJ)
shlib: $(OBJ)
$(CC) $(CCFLAGS) $(SHFLAGS) $(SHLIBFLAGS) $(EXTRA_PATH) -o $(EXE) \
$(OBJ) $(EXTRA_LIB) $(LIB)

View File

@ -1,6 +1,8 @@
# Make.sh = update Makefile.lib or Makefile.list or style_*.h files
# Make.sh = update Makefile.lib, Makefile.shlib, Makefile.list
# or style_*.h files
# Syntax: sh Make.sh style
# sh Make.sh Makefile.lib
# sh Make.sh Makefile.shlib
# sh Make.sh Makefile.list
# function to create one style_*.h file

View File

@ -130,7 +130,7 @@ makelist:
@$(SHELL) Make.sh style
@$(SHELL) Make.sh Makefile.list
# install LAMMPS shared lib and Python wrapper in Python
# install LAMMPS shared lib and Python wrapper for Python usage
install-python:
@python ../python/install.py

View File

@ -21,9 +21,6 @@ help:
@files="`ls MAKE/Makefile.*`"; \
for file in $$files; do head -1 $$file; done
clean:
rm -rf Obj_*
.DEFAULT:
@test -f MAKE/Makefile.$@
@if [ ! -d Obj_$@ ]; then mkdir Obj_$@; fi

View File

@ -21,9 +21,6 @@ help:
@files="`ls MAKE/Makefile.*`"; \
for file in $$files; do head -1 $$file; done
clean:
rm -rf Obj_*
.DEFAULT:
@test -f MAKE/Makefile.$@
@if [ ! -d Obj_$@ ]; then mkdir Obj_$@; fi

File diff suppressed because one or more lines are too long

View File

@ -410,6 +410,8 @@ void Cuda::setDomainParams()
cu_domain->boxlo_lamda[i] = domain->boxlo_lamda[i];
cu_domain->boxhi_lamda[i] = domain->boxhi_lamda[i];
cu_domain->prd_lamda[i] = domain->prd_lamda[i];
cu_domain->sublo[i] = domain->sublo_lamda[i];
cu_domain->subhi[i] = domain->subhi_lamda[i];
}
cu_domain->xy = domain->xy;

View File

@ -17,7 +17,7 @@
#ifdef PAIR_CLASS
PairStyle(lj/cut/omp,PairLJExpandOMP)
PairStyle(lj/expand/omp,PairLJExpandOMP)
#else

View File

@ -30,7 +30,9 @@
#include "modify.h"
#include "compute.h"
#include "fix.h"
#include "comm.h"
#include "memory.h"
#include "error.h"
using namespace LAMMPS_NS;
@ -383,8 +385,13 @@ void lammps_gather_atoms(void *ptr, char *name,
// error if tags are not defined or not consecutive
if (lmp->atom->tag_enable == 0 || lmp->atom->tag_consecutive() == 0) return;
if (lmp->atom->natoms > MAXSMALLINT) return;
int flag = 0;
if (lmp->atom->tag_enable == 0 || lmp->atom->tag_consecutive() == 0) flag = 1;
if (lmp->atom->natoms > MAXSMALLINT) flag = 1;
if (flag && lmp->comm->me == 0) {
lmp->error->warning(FLERR,"Library error in lammps_gather_atoms");
return;
}
int natoms = static_cast<int> (lmp->atom->natoms);
@ -464,10 +471,16 @@ void lammps_scatter_atoms(void *ptr, char *name,
{
LAMMPS *lmp = (LAMMPS *) ptr;
// error if tags are not defined or not consecutive
// error if tags are not defined or not consecutive or no atom map
if (lmp->atom->tag_enable == 0 || lmp->atom->tag_consecutive() == 0) return;
if (lmp->atom->natoms > MAXSMALLINT) return;
int flag = 0;
if (lmp->atom->tag_enable == 0 || lmp->atom->tag_consecutive() == 0) flag = 1;
if (lmp->atom->natoms > MAXSMALLINT) flag = 1;
if (lmp->atom->map_style == 0) flag = 1;
if (flag && lmp->comm->me == 0) {
lmp->error->warning(FLERR,"Library error in lammps_scatter_atoms");
return;
}
int natoms = static_cast<int> (lmp->atom->natoms);