| 1 | The C API of MUSCLE is a subset of the C++ API, the C API is again a subset of the Java API. Because the core of MUSCLE is written in Java, any C++ executable will communicate with Java code, but this is hidden in the API. In both cases, the include path is $MUSCLE_HOME/include |
| 2 | |
| 3 | == C API == |
| 4 | |
| 5 | All muscle2 headers are installed in {{{$MUSCLE_HOME/include/muscle2}}}. The header for the C API is {{{muscle2/cmuscle.h}}}. |
| 6 | |
| 7 | The functions there are very limited, but they should be sufficient for most needs: |
| 8 | {{{ |
| 9 | muscle_error_t MUSCLE_Init(int* argc, char*** argv); |
| 10 | void MUSCLE_Finalize(void); |
| 11 | |
| 12 | const char* MUSCLE_Get_Kernel_Name(void); |
| 13 | const char* MUSCLE_Get_Property(const char* name); |
| 14 | int MUSCLE_Will_Stop(void); |
| 15 | |
| 16 | muscle_error_t MUSCLE_Send(const char *exit_name, void *array, size_t size, muscle_datatype_t type); |
| 17 | void* MUSCLE_Receive(const char *entrance_name, void *array, size_t *size, muscle_datatype_t type); |
| 18 | }}} |
| 19 | The {{{MUSCLE_Init}}} function must be called before any of the other MUSCLE functions is used, and also before MPI_Init is called, if MPI is used. The usage is the same of MPI_Init: to initialize MUSCLE given the current arguments of main. After all MUSCLE calls have been made, MUSCLE_Finalize should be called. Usually: |
| 20 | {{{ |
| 21 | int main(int argc, char *argv[]) |
| 22 | { |
| 23 | MUSCLE_Init(&argc, &argv); |
| 24 | ... |
| 25 | MUSCLE_Finalize(); |
| 26 | return 0; |
| 27 | } |
| 28 | }}} |
| 29 | After this, any code can be written. The MUSCLE_Get_Kernel_Name function gives the current kernel name. This must be freed after use. Similarly, MUSCLE_Get_Property gives a property as a string, which must be freed afterwards. |
| 30 | |
| 31 | The send and receive functions can transport several datatypes, which are enumerated in {{{muscle2/muscle_types.h}}}. For reference, it takes the following datatypes |
| 32 | ||={{{muscle_datatype_t}}}=||=C data type=||= Java data type =||=maximum size=|| |
| 33 | ||{{{MUSCLE_DOUBLE}}}||{{{double *}}}||{{{double[]}}}||134e6 values || |
| 34 | ||{{{MUSCLE_FLOAT}}}||{{{float *}}}||{{{float[]}}}||268e6 values|| |
| 35 | ||{{{MUSCLE_INT32}}}||{{{int *}}}||{{{int[]}}}||268e6 values|| |
| 36 | ||{{{MUSCLE_INT64}}}||{{{long *}}}||{{{long[]}}}||134e6 values|| |
| 37 | ||{{{MUSCLE_STRING}}}||{{{char *}}}||{{{String}}}||64e3 characters|| |
| 38 | ||{{{MUSCLE_RAW}}}||{{{unsigned char *}}}||{{{byte[]}}}||268e6 values|| |
| 39 | ||{{{MUSCLE_COMPLEX}}}||{{{muscle::ComplexData *}}}||any other object||1 GiB|| |
| 40 | |
| 41 | The type {{{MUSCLE_COMPLEX}}} is only available for C++ code. |