I don't know why the MinGW compiler used by the AceGen is not automatically found by Mathematica. Maybe because it is not installed to some specific location or because it is missing some metadata?
This is a workaround. We choose generic compiler and then set its installation path and name to MinGW.
(* This is valid for 64-bit Windows OS *)
<< CCompilerDriver`;
$CCompiler = {
"Compiler" -> CCompilerDriver`GenericCCompiler`GenericCCompiler,
"CompilerInstallation" ->
FileNameJoin[{$UserBaseDirectory, "Applications", "MinGW",
"MinGW64", "bin"}],
"CompilerName" -> "x86_64-w64-mingw32-gcc.exe"
};
This example is taken from documentation for Compile. For some functions compiling to C can give really significant speedup.
(* Function without compilation. *)
f[x_, n_] := Module[ {sum, inc},
sum = 1.; inc = 1.;
Do[inc = inc*x/i; sum = sum + inc, {i, n}];
sum
]
(* Compile to Wolfram virtual machine *)
fCompile = Compile[ {{x, _Real}, {n, _Integer}},
Module[ {sum, inc},
sum = 1.; inc = 1.;
Do[inc = inc*x/i; sum = sum + inc, {i, n}];
sum
]
];
(* Compile to C *)
fCompileToC = Compile[ {{x, _Real}, {n, _Integer}},
Module[ {sum, inc},
sum = 1.; inc = 1.;
Do[inc = inc*x/i; sum = sum + inc, {i, n}];
sum
], CompilationTarget -> "C"
];
f[1.5, 1000000] // AbsoluteTiming
(*{3.1352802071330084`, 4.481689070338066`}*)
fCompile[1.5, 1000000] // AbsoluteTiming
(*{0.06240285331664793`, 4.481689070338066`}*)
fCompileToC[1.5, 1000000] // AbsoluteTiming
(*{0.008644816153883178`, 4.481689070338066`}*)