SHOGUN
v2.0.0
|
00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 2009 Soeren Sonnenburg 00008 * Copyright (C) 2009 Fraunhofer Institute FIRST and Max-Planck-Society 00009 */ 00010 00011 #include <shogun/base/init.h> 00012 #include <shogun/mathematics/Math.h> 00013 #include <shogun/lib/memory.h> 00014 #include <shogun/lib/Map.h> 00015 #include <shogun/base/Parallel.h> 00016 #include <shogun/base/Version.h> 00017 00018 #ifdef TRACE_MEMORY_ALLOCS 00019 shogun::CMap<void*, shogun::MemoryBlock>* sg_mallocs=NULL; 00020 #endif 00021 00022 namespace shogun 00023 { 00024 Parallel* sg_parallel=NULL; 00025 SGIO* sg_io=NULL; 00026 Version* sg_version=NULL; 00027 CMath* sg_math=NULL; 00028 00030 void (*sg_print_message)(FILE* target, const char* str) = NULL; 00031 00033 void (*sg_print_warning)(FILE* target, const char* str) = NULL; 00034 00036 void (*sg_print_error)(FILE* target, const char* str) = NULL; 00037 00039 void (*sg_cancel_computations)(bool &delayed, bool &immediately)=NULL; 00040 00041 00042 void init_shogun(void (*print_message)(FILE* target, const char* str), 00043 void (*print_warning)(FILE* target, const char* str), 00044 void (*print_error)(FILE* target, const char* str), 00045 void (*cancel_computations)(bool &delayed, bool &immediately)) 00046 { 00047 if (!sg_io) 00048 sg_io = new shogun::SGIO(); 00049 if (!sg_parallel) 00050 sg_parallel=new shogun::Parallel(); 00051 if (!sg_version) 00052 sg_version = new shogun::Version(); 00053 if (!sg_math) 00054 sg_math = new shogun::CMath(); 00055 #ifdef TRACE_MEMORY_ALLOCS 00056 if (!sg_mallocs) 00057 sg_mallocs = new shogun::CMap<void*, MemoryBlock>(631, 1024, false); 00058 00059 SG_REF(sg_mallocs); 00060 #endif 00061 SG_REF(sg_io); 00062 SG_REF(sg_parallel); 00063 SG_REF(sg_version); 00064 SG_REF(sg_math); 00065 00066 sg_print_message=print_message; 00067 sg_print_warning=print_warning; 00068 sg_print_error=print_error; 00069 sg_cancel_computations=cancel_computations; 00070 } 00071 00072 void sg_global_print_default(FILE* target, const char* str) 00073 { 00074 fprintf(target, "%s", str); 00075 } 00076 00077 void init_shogun_with_defaults() 00078 { 00079 init_shogun(&sg_global_print_default, &sg_global_print_default, 00080 &sg_global_print_default); 00081 } 00082 00083 void exit_shogun() 00084 { 00085 #ifdef TRACE_MEMORY_ALLOCS 00086 list_memory_allocs(); 00087 shogun::CMap<void*, shogun::MemoryBlock>* mallocs=sg_mallocs; 00088 sg_mallocs=NULL; 00089 SG_UNREF(mallocs); 00090 #endif 00091 sg_print_message=NULL; 00092 sg_print_warning=NULL; 00093 sg_print_error=NULL; 00094 sg_cancel_computations=NULL; 00095 00096 SG_UNREF(sg_math); 00097 SG_UNREF(sg_version); 00098 SG_UNREF(sg_parallel); 00099 SG_UNREF(sg_io); 00100 00101 } 00102 00103 void set_global_io(SGIO* io) 00104 { 00105 SG_UNREF(sg_io); 00106 sg_io=io; 00107 SG_REF(sg_io); 00108 } 00109 00110 SGIO* get_global_io() 00111 { 00112 SG_REF(sg_io); 00113 return sg_io; 00114 } 00115 00116 void set_global_parallel(Parallel* parallel) 00117 { 00118 SG_UNREF(sg_parallel); 00119 sg_parallel=parallel; 00120 SG_REF(sg_parallel); 00121 } 00122 00123 Parallel* get_global_parallel() 00124 { 00125 SG_REF(sg_parallel); 00126 return sg_parallel; 00127 } 00128 00129 void set_global_version(Version* version) 00130 { 00131 SG_UNREF(sg_version); 00132 sg_version=version; 00133 SG_REF(sg_version); 00134 } 00135 00136 Version* get_global_version() 00137 { 00138 SG_REF(sg_version); 00139 return sg_version; 00140 } 00141 00142 void set_global_math(CMath* math) 00143 { 00144 SG_UNREF(sg_math); 00145 sg_math=math; 00146 SG_REF(sg_math); 00147 } 00148 00149 CMath* get_global_math() 00150 { 00151 SG_REF(sg_math); 00152 return sg_math; 00153 } 00154 }