The CompilationTarget option of Compile specifies the target runtime system for the compiled function. The default setting is "MVM", which creates code for the traditional Wolfram Language virtual machine. This virtual machine is described in detail in the section on compiled function operation.
You can call the LibraryFunction directly.
If the generated code needs to make an external call, this works as expected.
The speed acceleration will not always be so large. If an expensive internal function such as matrix-matrix multiplication was called, the time for this would be similar for both C and the Wolfram Language virtual machine, and in this case there would be no speed benefit.
As is the case for traditional compiled function execution, external calls can also lead to inefficiencies when using the Wolfram System compiler. In particular, undefined external calls should be avoided.
Other factors that can have an effect include the use of RuntimeOptions such as CatchMachineOverflow, CatchMachineUnderflow, and CatchMachineIntegerOverflow. As explained, these can all have an influence on the efficiency of a compiled function.
You can use set listability and parallelization for Compile in conjunction with C execution. The following creates and executes a listable compiled function.
The conversion uses the CCodeGenerator package to generate C code for a Wolfram library and then the CCompilerDriver package (using CreateLibrary) to compile the code into an actual library. The libraries are all placed into a folder that is unique for each session of the Wolfram System.
If you want to change option settings for the call to CreateLibrary you can do this with Compile`$CCompilerOptions. This is useful for various reasons such as inspecting and debugging generated code.
To inspect the generated code you need to change the default behavior of CreateLibrary. This will clean any intermediate files that are generated and is controlled by the "CleanIntermediate" option. A change is shown below.
This displays the C code; the meaning of some of these terms is explained in the CCodeGenerator documentation.
Note that when you prevent deletion of intermediate files, this will interfere with tidying of the generated code folders when the Wolfram System session is terminated. At this point you might wish to delete the files yourself.
To debug the generated code you need to add debugging options to CreateLibrary. These are different for different C compilers. For Visual Studio, you can set the following.
It is necessary to set "CleanIntermediate" to False so that the intermediate files are saved and also set "CompileOptions" to insert debugging information in the resulting library.