1

I am trying to generate C code for some functions, which I do not post in full because they are a few hundred lines long. The functions do nothing too fancy: a bunch of dot products, powers and roots.

Still, when compiling to C code Mathematica sticks in some unwanted dependency on its own libraries, which is not acceptable for the use case in question. The functions I am trying to compile have 5 arguments, 4 of which are 3-dimensional vectors.

The compile printout of one of them can be found here. As you can see, there are 3 Mathematica functions being pulled in: DotVV, Power and Internal`ReciprocalSqrt. Is there any way I can get rid of these without modifying the code manually?

Edit: here is the code I am using to compile the function

Compile[{{pos, _Real, 1} , {a, _Real, 1}, {v, _Real, 1}, {ba, _Real, 
    1} , {V, _Real}} , 
  xSol, CompilationTarget -> "C"];
em70
  • 340
  • 1
  • 7
  • Can you whittle down your code and output to something that will fit in the Q? That would make it self-contained and easier to work with. – Yves Klett Jul 04 '14 at 05:33
  • Thanks for your comment. Unfortunately how I get to xSol is quite complicated and requires some lengthy evaluations. As for the compiled code, I would not know how to shrink it. I have, however, included the call I am making to Compile, hoping that it helps. – em70 Jul 04 '14 at 05:47
  • The outlook of reverse-engineering compiled code may not get you many takers. Providing code (e.g. in a linked notebook) would make the task easier, e.g. by identification of functions that do not compile, see. eg. List of compilable functions. – Yves Klett Jul 04 '14 at 06:01
  • I do not expect anybody to reverse-engineer the code. That is just posted for reference. The point is that I have a huge expression which is, at its essence, just a large sum of the values of applications of the functions I listed in my question. Moreover, all of those are compilable, hence the question. I wonder if the fact that there is no size constraint on the vectors is the issue (how could Mathematica know that they are 3d otherwise?) – em70 Jul 04 '14 at 06:10
  • Hopefully someone can help you right away (and yes, you did not request anything untoward). My point is just that supplying as much info as (sensibly) possible could be helpful in getting you more feedback, especially including the source code. – Yves Klett Jul 04 '14 at 07:07
  • Is this not a minimal example? Needs["CompiledFunctionTools`"]; CompilePrint[ Compile[{{pos, _Real, 1}, {a, _Real, 1}}, pos.a, CompilationTarget -> "WVM"] ] – acl Jul 04 '14 at 10:38
  • Close, @acl, but CompilationTarget->"C" and this won't generate anything using Internal`ReciprocalSqrt or Power. Thanks, though. – em70 Jul 04 '14 at 14:10
  • 2
    @emaster70 I meant: this is an example that produces DotVV. As your question is posed, we'd need to come up with code that produces Internal`ReciprocalSqrt, DotVV and Power when compiled, solve the problem, then report to you. You could help by providing an example of problematic code. This is what I have been trying to hint at, but... – acl Jul 04 '14 at 14:14
  • Can you please comment on why the dependency on the runtime library is not acceptable in this case? One can always link statically, if it is the dependency that is the problem, rather than the use of library functions in itself. – Oleksandr R. Dec 12 '15 at 21:59

0 Answers0