make_dll
options
newCommand
argDec
argDec
argDec …
make_dll_i
options
newCommand
argDec
argDec
argDec …
make_dll.tcl defines procedures for automatically
producing an interface from NAP to a
DLL (
dynamic-link library or
shared library) based on C or Fortran Code. This process
defines a new tcl command which can either be used directly or via
another interface (written in Tcl) defining a NAP function.
make_dll options newCommand argDec argDec argDec …
newCommand is name of new command.
Each argument-declaration
argDec is a list with the form
{
name
dataType
intent
} where
c8 i8 u8 i16 u16 i32 u32 f32 f64 voidin (default) or
inout. Actual
in arguments can be expressions of any type (including
ragged) and will be converted to the specified type
(unless this is
void).
options are:
-quiet: Do not echo commands.
-compile
command: C compile-command with options
-dll
fileName: output filename for DLL (default:
newCommand.dll for windows,
newCommand.so for unix)
-entry
string: User-routine entry-point (default:
newCommand). Note that fortran entry points often include
suffix '_'.
-header
fileName: header (
*.h) filename (default: none)
-libs
fileNames: filenames of extra binary libraries (default:
none)
-link
command: Link-command with options
-object
fileName: User-routine object-file (default:
newCommand
.obj for windows,
newCommand
.o for unix)
-source
fileName: Output file containing C source code of
interface (default:
newCommand
_i.c)
-version
n.m: Version number (default:
1.0)
partialProd which calculates partial-products. This is
analogous to the standard nap function
psum which calculates partial sums. The new function is
based on the following C file
pprod.c:
void pprod(int *n, float *x, float *result) {
int i;
float prod = 1;
for (i = 0; i < *n; i++) {
result[i] = prod = prod * x[i];
}
}
% exec cc -c -o pprod.o pprod.c
% make_dll pprod {n i32 in} {x f32} {y f32 inout}
cc -I/sol/home/dav480/tcl/include -c pprod_i.c
ld -G -o libpprod.so pprod_i.o pprod.o
% load ./libpprod.so
% proc partialProd x {
nap "result = reshape(f32(_), shape(x))"
pprod "nels(x)" x result
nap "result"
}
% [nap "partialProd({2 1.5 3 0.5})"]
2 3 9 4.5
pprod.f90 is:
subroutine pprod(n, x, result)
integer, intent(in) :: n
real, intent(in) :: x(n)
real, intent(out) :: result(n)
integer :: i
real :: prod
prod = 1.0
do i = 1, n
prod = prod * x(i)
result(i) = prod
end do
end subroutine pprod
The following log was produced using the SunOS 5.8 f95 compiler.
(Note that the entry point is "pprod_".)
% exec f95 -c pprod.f90
% make_dll -entry pprod_ pprod {n i32 in} {x f32} {y f32 inout}
cc -I/sol/home/dav480/tcl/include -c pprod_i.c
ld -G -o libpprod.so pprod_i.o pprod.o
% load ./libpprod.so
% proc partialProd x {
nap "result = reshape(f32(_), shape(x))"
pprod "nels(x)" x result
nap "result"
}
% [nap "partialProd({2 1.5 3 0.5})"]
2 3 9 4.5
make_dll_i options newCommand argDec argDec argDec …
make_dll, but may be used directly if you prefer to do
your own compiling and linking. The result of
make_dll_i is the C code.
The arguments are similar to
make_dll, except that the only options are:
-entry
string: User-routine entry-point (default:
newCommand). Note that fortran entry points often include
suffix '_'.
-header
fileName: header (
*.h) filename (default: none)
-version
n.m: Version number (default:
1.0)