I'm trying to minimize the computation time of problem which is too long to post. I use compile
in order to gain some speed. To increase speed I would like to use the options Parallelization -> True
and RuntimeAttributes -> {Listable}
among others. The problem is now that some built-in functions I use, such as Map
, do not have the attribute Listable
. Thus, it seems that my code produces an error once the input is e.g. a list instead of a real number. To gain some insights I post some toy-code.
toy=Compile[{{h1,_Real},{list,_Real,1}},
leg=Length[list];
Map[Total[{list[[#]]}]/h1&, Range[leg]],
CompilationTarget->"C",
Parallelization->True,
RuntimeAttributes->{Listable},
RuntimeOptions -> "Speed"];
What this code does is it divides each element of list
by h1
. Please notice that this code does not have any meaning but to show the problem of using a non-listable function within a compile function. Now, let h1
be some real and list
be some random list. Then,
h1=0.1; list=RandomReal[{-1., 1.}, 100]; toy[h1, list]
works just fine. However, if one sets
h1={0.1,0.2}; toy[h1, list]
results in an error.
My question is whether one of you knows a simple way to make this compiled function listable.
One may use e.g. a Do
-loop to get the result, but this is too slow. Thanks in advance I really appreciate it.