1 #include <TiledArray/config.h>
4 #ifdef TILEDARRAY_HAS_CUDA
10 #ifdef TILEDARRAY_HAS_INTEL_MKL
11 #include <mkl_service.h>
17 #ifdef TILEDARRAY_HAS_CUDA
18 inline void cuda_initialize() {
23 cuBLASHandlePool::handle();
29 inline void cuda_finalize() {
30 CudaSafeCall(cudaDeviceSynchronize());
32 cublasDestroy(cuBLASHandlePool::handle());
33 delete &cuBLASHandlePool::handle();
34 cudaEnv::instance().reset(
nullptr);
38 inline bool& initialized_madworld_accessor() {
39 static bool flag =
false;
42 inline bool initialized_madworld() {
return initialized_madworld_accessor(); }
43 inline bool& initialized_accessor() {
44 static bool flag =
false;
47 inline bool& finalized_accessor() {
48 static bool flag =
false;
51 #ifdef TILEDARRAY_HAS_INTEL_MKL
52 inline int& mklnumthreads_accessor() {
53 static int value = -1;
81 const SafeMPI::Intracomm& comm,
83 if (initialized_madworld() &&
finalized())
85 "TiledArray finalized MADWorld already, cannot re-initialize MADWorld "
89 initialized_madworld_accessor() =
true;
92 if (madness::World::is_default(comm))
94 "MADWorld initialized before TiledArray::initialize(argc, argv, "
95 "comm), but not initialized with comm");
97 auto& default_world = initialized_madworld()
99 : *madness::World::find_instance(comm);
101 #ifdef TILEDARRAY_HAS_CUDA
102 TiledArray::cuda_initialize();
104 #ifdef TILEDARRAY_HAS_INTEL_MKL
106 mklnumthreads_accessor() = mkl_get_max_threads();
107 mkl_set_num_threads(1);
109 madness::print_meminfo_disable();
110 initialized_accessor() =
true;
111 return default_world;
113 throw Exception(
"TiledArray already initialized");
119 #ifdef TILEDARRAY_HAS_INTEL_MKL
121 mkl_set_num_threads(mklnumthreads_accessor());
123 #ifdef TILEDARRAY_HAS_CUDA
124 TiledArray::cuda_finalize();
128 if (initialized_madworld()) {
132 initialized_accessor() =
false;
133 finalized_accessor() =
true;
141 std::cerr << m << std::endl;