I think I know the answer to this, but after two days of Googling, this is my last effort before going down an unwanted path...
I have a function that takes lots of large data as arguments as well as assigns new values to one of the arguments in place. Here is what it looks like:
LinearIsotropicElastic[youngMod_,poisson_,node_,dilitation_,devElongState_,families_,volumes_,refMagState_,volState_,internalForce_] :=
Module[{ti,td,forceState,bulkMod=youngMod/3.0/(1.0 - 2.0*poisson),shearMod=youngMod/2.0/(1.0 + poisson)},
ti = 3.0*bulkMod*dilitation[[node]]/volState[[node]]*refMagState[[node]];
td = 15.0*shearMod/volState[[node]]*devElongState[[node]];
forceState = ti + td;
internalForce[[node]] += Total[forceState*volumes[[families[[node]]]]];
internalForce[[families[[node]]]] -= forceState*volumes[[node]];
]
In pure Mathematica, I used SetAttributes[]=HoldAll
and everything works fine. The issue is I need to map this function over many thousand "node" and this takes forever, therefore I'd really like to compile this function. I have not been able to successfully get the tricks that have been offered to compile a function while changing one of its arguments. This is standard pass-by-reference stuff in C of course. Are there any suggestions before I resort to writing this function in C and LibraryLink'ing it in? I really don't want to go down this path, because I actually already have a working similar application in C++ and was building this in Mathematica to be a prototyping code and not deal with all the complexity of C/C++. Any help will be appreciated.
Compile
at present, there are several work-arounds, but without a self-contained example (with large sample data, perhaps randomly generated), it is hard to say what will work best. $\endgroup$ – Leonid Shifrin Mar 7 '12 at 6:04