void sort_insert_wrp () { cout<<"=============="<<endl; PRINT_DEBUG_INFO(); vector <int> a={6,5,1,2,3,10,2,3,4,5}; //vector <int> a={6,2,15,3}; //vector <int> a={6,2}; PRINT_VECTOR(a); cout<<"=============="<<endl; vector <int> a_bk=a; chrono::high_resolution_clock::time_point t1 = chrono::high_resolution_clock::now(); sort_insert(a); //sort_insert2(a); chrono::high_resolution_clock::time_point t2 = chrono::high_resolution_clock::now(); cout<<"=============="<<endl; PRINT_VECTOR(a); cout<<"=============="<<endl; sanity_check(a,a_bk); auto duration = chrono::duration_cast< chrono::microseconds>( t2 - t1 ).count(); cout<<"duration:"<<duration<<endl; }
// Can't really test these other than that they compile and visually looking at output void TestDebugMacros() { TRACE("Some trace"); // Note that these macros do nothing in NDEBUG -- we should ensure that the variables get used anyway double use_vars = 0.0; unsigned my_var = 3141; PRINT_VARIABLE(my_var); use_vars += (double) my_var; double another_var = 2.81; PRINT_2_VARIABLES(my_var, another_var); use_vars += another_var; double cancer_curing_constant = 0.053450242435; PRINT_3_VARIABLES(my_var, another_var, cancer_curing_constant); use_vars += cancer_curing_constant; double heart_disease_ending_constant = -3e-141; PRINT_4_VARIABLES(my_var, another_var, cancer_curing_constant, heart_disease_ending_constant); use_vars += heart_disease_ending_constant; std::cout << "\n\n"; for (unsigned i=0; i<10; i++) { HOW_MANY_TIMES_HERE("inside for loop"); for (unsigned j=0; j<2; j++) { HOW_MANY_TIMES_HERE("nested loop"); } } for (unsigned j=0; j<10 /*change to 11 and it should quit*/; j++) { QUIT_AFTER_N_VISITS(11); } std::cout << "\n\n\n"; for (unsigned j=0; j<3; j++) { TRACE_FROM_NTH_VISIT("hello",2); } std::vector<double> vec(4); vec[0] = 0.0; vec[1] = 1.0; vec[2] = 2.7; vec[3] = 3.1; PRINT_VECTOR(vec); MARK; // Something like: "DEBUG: ./global/test/TestDebug.hpp at line 104" MARK_IN_ORDER; // Something like: "DEBUG: proc 0 ./global/test/TestDebug.hpp at line 106" etc // Check interaction with process isolation PetscTools::IsolateProcesses(); TRACE("Processes are isolated."); PetscTools::IsolateProcesses(false); AnotherFunctionOnTheStack(); }
// Can't really test these other than that they compile and visually looking at output void TestDebugMacros() { TRACE("Some trace"); // Note that these macros do nothing in NDEBUG -- we should ensure that the variables get used anyway double use_vars = 0.0; unsigned my_var = 3141; PRINT_VARIABLE(my_var); use_vars += (double) my_var; double another_var = 2.81; PRINT_2_VARIABLES(my_var, another_var); use_vars += another_var; double cancer_curing_constant = 0.053450242435; PRINT_3_VARIABLES(my_var, another_var, cancer_curing_constant); use_vars += cancer_curing_constant; double heart_disease_ending_constant = -3e-141; PRINT_4_VARIABLES(my_var, another_var, cancer_curing_constant, heart_disease_ending_constant); use_vars += heart_disease_ending_constant; std::cout << "\n\n"; for (unsigned i=0; i<10; i++) { HOW_MANY_TIMES_HERE("inside for loop"); for (unsigned j=0; j<2; j++) { HOW_MANY_TIMES_HERE("nested loop"); } } for (unsigned j=0; j<10 /*change to 11 and it should quit*/; j++) { QUIT_AFTER_N_VISITS(11); } std::cout << "\n\n\n"; for (unsigned j=0; j<3; j++) { TRACE_FROM_NTH_VISIT("hello",2); } std::vector<double> vec(4); vec[0] = 0.0; vec[1] = 1.0; vec[2] = 2.7; vec[3] = 3.1; PRINT_VECTOR(vec); MARK; // Something like: "DEBUG: ./global/test/TestDebug.hpp at line 110" MARK_IN_ORDER; // Something like: "DEBUG: proc 0 ./global/test/TestDebug.hpp at line 111" etc MARK_ON_PROCESS(1); // In serial there is no output. In parallel, something like: "DEBUG: proc 1: ./global/test/TestDebug.hpp at line 112" // Check interaction with process isolation PetscTools::IsolateProcesses(); TRACE("Processes are isolated."); PetscTools::IsolateProcesses(false); AnotherFunctionOnTheStack(); MARK_MEMORY; // Should print that PRINT_MEMORY will now be relative to here PRINT_MEMORY; // Should be 0 Mb UNMARK_MEMORY; // Should print that PRINT_MEMORY will now be the absolute footprint PRINT_MEMORY; // Should be > 0 Mb MARK_MEMORY; std::vector<double> poinless_vector; poinless_vector.resize(100000); PRINT_MEMORY; // Should be x Mb poinless_vector.resize(200000); PRINT_MEMORY; // Should be at least 2x Mb }