Q:

AceGen: How to use MinGW in Compile[]?

Note: This question is about AceGen package for automatic code generation for finite element analysis. 
MinGW compiler is recommended for compiling finite element subroutines generated by AceGen and is bundled with the installation. How can I use this compiler for compiling other Mathematica expressions to C (e.g. Compile[...,CompilationTarget->"C"]) and make them faster?
The problem is that my MinGW compiler is not automatically detected by Mathematica. Command CCompilers[] returns empty list.
<< CCompilerDriver`;
CCompilers[] 
(* {} *)

A:

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`}*)

