This page describes the basic details of what is required of your code if you choose to write in a language that compiles to binary (such as C/C++/Fortran), and you wish to use that code with the CADI toolkit to perform optimisation or sensitivity analysis.
You must produce a compiled object file with entry points
initialize_ forward_
and user_init_
.
In C and Fortran, the
function signatures are as follows
C -- void initialize_(char* path, int* pathlenptr, int junk)
FORTRAN -- subroutine initialize(path, pathlen) |
This function is only required when the toolkit is run in distributed mode. For stand-alone mode, you must still have the function, but it can (and should) have an empty body.
In distributed mode, this function is called
by the toolkit before any of your other functions
are called. The toolkit passes in an argument
For C code, the path string is guaranteed to be nul terminated. For Fortran code, the path string is guaranteed to have no trailing spaces/padding. For those coding in C, please note that for
uninteresting technical reasons, their is an
additional argument |
C -- void user_init_(int* nd, float* ranges, float* scales)
FORTRAN -- subroutine user_init(nd, ranges, scales) |
The user_init function is called by the toolkit
at the start of the optimisation in order to get
information about the optimisation.
Your implementation
must set The
array The third argument |
C -- void forward_(int* nd, float* model, float* mfit)
FORTRAN -- subroutine forward(nd, model, mfit) |
This is where your code does the 'real' work in the optimisation. The toolkit will call this function multiple
times, passing in different points in the parameter space
you define in The value
Your function must set the
value of If you are using some of the statistical routines
in the toolkit (like the Markov Chain Monte Carlo
sampler), this routine should return
log(prior(model)*likelihood(data|model)), and,
if the |
You can take your source code and produce a shared object with the following 2 steps
fc -c *.f
ld -shared *.o -o nativeUser.so
If you have stuffed things up with linking somehow, you will get an unsatisfied link error printed to the terminal when you try and load your code in the toolkit. If you want to save yourself the trouble of starting up the toolkit and loading your code, you can check if your code has any link errors by ommitting the '-shared' option in the linking stage (i.e. by typing 'ld *.o -o linkTest.bin'). You will get a link error complaining about a missing/undefined MAIN method (this is normal, and OK), but you should not get any other link errors. If you do, you need to fix them first.
Finally, there are some restrictions to the files that your program may access while it is running. These restrictions are:
path
string (passed to your initialize
function) to the path of the file that you want to open.
Any files (data files, for example) that your program
uses must also be accessible/readable by the user who is running
the cadi server. Making it readable by everyone is one solution,
if the data is not sensitive.