Permalink
Browse files

Merge branch 'code_compilation_in_thread' into 'master'

[code generation] Start a thread to compile generated code

See merge request !227
  • Loading branch information...
JSchoeberl committed Sep 7, 2017
2 parents 3334410 + 9c6661d commit 6be0222e3c40623ea14276a71739e60f6f22515a
Showing with 16 additions and 9 deletions.
  1. +1 −1 fem/code_generation.cpp
  2. +1 −1 fem/code_generation.hpp
  3. +14 −7 fem/coefficient.cpp
@@ -29,7 +29,7 @@ namespace ngfem
#endif // WIN32
}
void Library::Compile( std::vector<string> &codes )
void Library::Compile(const std::vector<string> &codes )
{
static ngstd::Timer tcompile("CompiledCF::Compile");
static ngstd::Timer tlink("CompiledCF::Link");
@@ -170,7 +170,7 @@ namespace ngfem
public:
Library() : lib(nullptr) {}
// Compile a given string and load the library
void Compile( std::vector<string> &codes );
void Compile( const std::vector<string> &codes );
void Load( string alib_name );
@@ -4751,13 +4751,20 @@ shared_ptr<CoefficientFunction> MakeCoordinateCoefficientFunction (int comp)
pointer_code += "}\n";
codes.push_back(pointer_code);
}
library.Compile( codes );
compiled_function_simd = library.GetFunction<lib_function_simd>("CompiledEvaluateSIMD");
compiled_function = library.GetFunction<lib_function>("CompiledEvaluate");
compiled_function_simd_deriv = library.GetFunction<lib_function_simd_deriv>("CompiledEvaluateDerivSIMD");
compiled_function_deriv = library.GetFunction<lib_function_deriv>("CompiledEvaluateDeriv");
compiled_function_simd_dderiv = library.GetFunction<lib_function_simd_dderiv>("CompiledEvaluateDDerivSIMD");
compiled_function_dderiv = library.GetFunction<lib_function_dderiv>("CompiledEvaluateDDeriv");
std::thread( [this, codes] () {
try {
library.Compile( codes );
compiled_function_simd = library.GetFunction<lib_function_simd>("CompiledEvaluateSIMD");
compiled_function = library.GetFunction<lib_function>("CompiledEvaluate");
compiled_function_simd_deriv = library.GetFunction<lib_function_simd_deriv>("CompiledEvaluateDerivSIMD");
compiled_function_deriv = library.GetFunction<lib_function_deriv>("CompiledEvaluateDeriv");
compiled_function_simd_dderiv = library.GetFunction<lib_function_simd_dderiv>("CompiledEvaluateDDerivSIMD");
compiled_function_dderiv = library.GetFunction<lib_function_dderiv>("CompiledEvaluateDDeriv");
cout << IM(7) << "Compilation done" << endl;
} catch (const std::exception &e) {
cerr << IM(3) << "Compilation of CoefficientFunction failed: " << e.what() << endl;
}
}).detach();
}
}

0 comments on commit 6be0222

Please sign in to comment.