@@ -14,48 +14,24 @@ struct DaggerForm <: ParallelForm end
14
14
`build_function`
15
15
16
16
Generates a numerically-usable function from a ModelingToolkit `Expression`.
17
- If the `Expression` is an `Operation`, the generated function is a function
18
- with a scalar output, otherwise if it's an `AbstractArray{Operation}`, the output
19
- is two functions, one for out-of-place AbstractArray output and a second which
20
- is a mutating function. The outputted functions match the given argument order,
21
- i.e., f(u,p,args...) for the out-of-place and scalar functions and
22
- `f!(du,u,p,args..)` for the in-place version.
23
17
24
18
```julia
25
19
build_function(ex, args...;
26
- conv = simplified_expr, expression = Val{true},
27
- checkbounds = false, convert_oop = true,
28
- force_SA = false,
29
- linenumbers = false, target = JuliaTarget())
20
+ expression = Val{true},
21
+ target = JuliaTarget(),
22
+ kwargs...)
30
23
```
31
24
32
25
Arguments:
33
26
34
27
- `ex`: The `Expression` to compile
35
- - `vs`: The variables of the expression
36
- - `ps`: The parameters of the expression
37
- - `args`: Extra arguments to the function
38
- - `conv`: The conversion function of the Operation to Expr. By default this uses
39
- the `simplified_expr` function utilized in `convert(Expr,x)`.
28
+ - `args`: The arguments of the function
40
29
- `expression`: Whether to generate code or whether to generate the compiled form.
41
30
By default, `expression = Val{true}`, which means that the code for the
42
- function is returned. If `Val{false}`, then the returned value is a compiled
43
- Julia function, which utilizes GeneralizedGenerated.jl in order to world-age
44
- free.
31
+ function is returned. If `Val{false}`, then the returned value is compiled.
45
32
46
33
Keyword Arguments:
47
34
48
- - `checkbounds`: For whether to enable bounds checking inside of the generated
49
- function. Defaults to false, meaning that `@inbounds` is applied.
50
- - `linenumbers`: Determines whether the generated function expression retains
51
- the line numbers. Defaults to true.
52
- - `convert_oop`: Determines whether the OOP version should try to convert
53
- the output to match the type of the first input. This is useful for
54
- cases like LabelledArrays or other array types that carry extra
55
- information. Defaults to true.
56
- - `force_SA`: Forces the output of the OOP version to be a StaticArray.
57
- Defaults to `false`, and outputs a static array when the first argument
58
- is a static array.
59
35
- `target`: The output target of the compilation process. Possible options are:
60
36
- `JuliaTarget`: Generates a Julia function
61
37
- `CTarget`: Generates a C function
@@ -182,6 +158,63 @@ function fill_array_with_zero!(x::AbstractArray)
182
158
return x
183
159
end
184
160
161
+ """
162
+ Build function target: JuliaTarget
163
+
164
+ ```julia
165
+ function _build_function(target::JuliaTarget, rhss, args...;
166
+ conv = simplified_expr, expression = Val{true},
167
+ checkbounds = false,
168
+ linenumbers = false, multithread=nothing,
169
+ headerfun = addheader, outputidxs=nothing,
170
+ convert_oop = true, force_SA = false,
171
+ skipzeros = outputidxs===nothing,
172
+ fillzeros = skipzeros && !(typeof(rhss)<:SparseMatrixCSC),
173
+ parallel=SerialForm(), kwargs...)
174
+ ```
175
+
176
+ Generates a Julia function which can then be utilized for further evaluations.
177
+ If expression=Val{false}, the return is a Julia function which utilizes
178
+ GeneralizedGenerated.jl in order to be free of world-age issues.
179
+
180
+ If the `Expression` is an `Operation`, the generated function is a function
181
+ with a scalar output, otherwise if it's an `AbstractArray{Operation}`, the output
182
+ is two functions, one for out-of-place AbstractArray output and a second which
183
+ is a mutating function. The outputted functions match the given argument order,
184
+ i.e., f(u,p,args...) for the out-of-place and scalar functions and
185
+ `f!(du,u,p,args..)` for the in-place version.
186
+
187
+ Special Keyword Argumnets:
188
+
189
+ - `parallel`: The kind of parallelism to use in the generated function. Defaults
190
+ to `SerialForm()`, i.e. no parallelism. Note that the parallel forms are not
191
+ exported and thus need to be chosen like `ModelingToolkit.SerialForm()`.
192
+ The choices are:
193
+ - `SerialForm()`: Serial execution.
194
+ - `MultithreadedForm()`: Multithreaded execution with a static split, evenly
195
+ splitting the number of expressions per thread.
196
+ - `DistributedForm()`: Multiprocessing using Julia's Distributed with a static
197
+ schedule, evenly splitting the number of expressions per process.
198
+ - `DaggerForm()`: Multithreading and multiprocessing using Julia's Dagger.jl
199
+ for dynamic scheduling and load balancing.
200
+ - `conv`: The conversion function of the Operation to Expr. By default this uses
201
+ the `simplified_expr` function utilized in `convert(Expr,x)`.
202
+ - `checkbounds`: For whether to enable bounds checking inside of the generated
203
+ function. Defaults to false, meaning that `@inbounds` is applied.
204
+ - `linenumbers`: Determines whether the generated function expression retains
205
+ the line numbers. Defaults to true.
206
+ - `convert_oop`: Determines whether the OOP version should try to convert
207
+ the output to match the type of the first input. This is useful for
208
+ cases like LabelledArrays or other array types that carry extra
209
+ information. Defaults to true.
210
+ - `force_SA`: Forces the output of the OOP version to be a StaticArray.
211
+ Defaults to `false`, and outputs a static array when the first argument
212
+ is a static array.
213
+ - `skipzeros`: Whether to skip filling zeros in the in-place version if the
214
+ filling function is 0.
215
+ - `fillzeros`: Whether to perform `fill(out,0)` before the calculations to ensure
216
+ safety with `skipzeros`.
217
+ """
185
218
function _build_function (target:: JuliaTarget , rhss, args... ;
186
219
conv = simplified_expr, expression = Val{true },
187
220
checkbounds = false ,
0 commit comments