void SOMap::debug_output() { printf("SOMap:\n"); for(int i = 0; i < (int)(this->my_map.size()); ++i) { for(int j = 0; j < (int)(this->my_map[i].size()); ++j) { printf( "map[%d, %d] == ", i, j ); remark_SOM_element( this->my_map[i][j] ); printf("\n"); } } }
int main(int argc, char** argv) { int l_speculation_start; utility::thread_number_range threads( task_scheduler_init::default_num_threads, task_scheduler_init::default_num_threads() // run only the default number of threads if none specified ); utility::parse_cli_arguments(argc,argv, utility::cli_argument_pack() //"-h" option for for displaying help is present implicitly .positional_arg(threads,"n-of-threads","number of threads to use; a range of the form low[:high], where low and optional high are non-negative integers or 'auto' for the TBB default.") // .positional_arg(InputFileName,"input-file","input file name") // .positional_arg(OutputFileName,"output-file","output file name") .positional_arg(radius_fraction, "radius-fraction","size of radius at which to start speculating") .positional_arg(nPasses, "number-of-epochs","number of examples used in learning phase") .arg(cancel_test, "cancel-test", "test for cancel signal while finding BMU") .arg(extra_debug, "debug", "additional output") .arg(dont_speculate,"nospeculate","don't speculate in SOM map teaching") ); readInputData(); max_radius = (xMax < yMax) ? yMax / 2 : xMax / 2; // need this value for the 1x1 timing below radius_decay_rate = -(log(1.0/(double)max_radius) / (double)nPasses); find_data_ranges(my_teaching, max_range, min_range ); if(extra_debug) { printf( "Data range: "); remark_SOM_element(min_range); printf( " to "); remark_SOM_element(max_range); printf( "\n"); } // find how much time is taken for the single function_node case. // adjust nPasses so the 1x1 time is somewhere around serial_time_adjust seconds. // make sure the example test runs for at least 0.5 second. for(;;) { task_scheduler_init init(1); SOMap map1(xMax,yMax); speculation_start = nPasses + 1; // Don't speculate xranges = 1; yranges = 1; map1.initialize(InitializeGradient, max_range, min_range); tick_count t0 = tick_count::now(); graph_teach(map1, my_teaching); tick_count t1 = tick_count::now(); double nSeconds = (t1-t0).seconds(); if(nSeconds < 0.5) { xMax *= 2; yMax *= 2; continue; } double size_adjust = sqrt(serial_time_adjust / nSeconds); xMax = (int)((double)xMax * size_adjust); yMax = (int)((double)yMax * size_adjust); max_radius = (xMax < yMax) ? yMax / 2 : xMax / 2; radius_decay_rate = log((double)max_radius) / (double)nPasses; if(extra_debug) { printf("original 1x1 case ran in %g seconds\n", nSeconds); printf(" Size of table == %d x %d\n", xMax, yMax); printf(" radius_decay_rate == %g\n", radius_decay_rate); } break; } // the "max_radius" starts at 1/2*radius_fraction the table size. To start the speculation when the radius is // 1 / n * the table size, the constant in the log below should be n / 2. so 2 == 1/4, 3 == 1/6th, // et c. if(dont_speculate) { l_speculation_start = nPasses + 1; if ( extra_debug )printf("speculation will not be done\n"); } else { if(radius_fraction < 1.0 ) { if ( extra_debug )printf("Warning: radius_fraction should be >= 1. Setting to 1.\n"); radius_fraction = 1.0; } l_speculation_start = (int)((double)nPasses * log(radius_fraction) / log((double)nPasses)); if ( extra_debug )printf( "We will start speculation at iteration %d\n", l_speculation_start ); } double single_time; // for speedup calculations for(int p = threads.first; p <= threads.last; ++p) { task_scheduler_init init(p); if ( extra_debug )printf( " -------------- Running with %d threads. ------------\n", p); // run the SOM build for a series of subranges for(xranges = 1; xranges <= xRangeMax; ++xranges) { for(yranges = xranges; yranges <= yRangeMax; ++yranges) { if(xranges == 1 && yranges == 1) { // don't pointlessly speculate if we're only running one subrange. speculation_start = nPasses + 1; } else { speculation_start = l_speculation_start; } SOMap map1(xMax, yMax); map1.initialize(InitializeGradient, max_range, min_range); if(extra_debug) printf( "Start learning for [%d,%d] ----------- \n", xranges,yranges); tick_count t0 = tick_count::now(); graph_teach(map1, my_teaching); tick_count t1 = tick_count::now(); if ( extra_debug )printf( "Done learning for [%d,%d], which took %g seconds ", xranges,yranges, (t1-t0).seconds()); if(xranges == 1 && yranges == 1) single_time = (t1-t0).seconds(); if ( extra_debug )printf( ": speedup == %g\n", single_time / (t1-t0).seconds()); } // yranges } // xranges } // #threads p printf("done\n"); return 0; }