# include # include # include # include # include using namespace std; # include "task_division.hpp" int main ( int argc, char *argv[] ); void timestamp ( ); //****************************************************************************80 int main ( int argc, char *argv[] ) //****************************************************************************80 // // Purpose: // // task_division_test() tests task_division(). // // Discussion: // // This program simply demonstrates how one might automate the // assignment of T tasks to P processors, assuming that the assignment // is to be beforehand. // // In that case, we just want to make sure that we assign each task // to a processor, that we assign about the same number of tasks // to each processor, and that we assign each processor a contiguous // range of tasks, say tasks I_LO to I_HI. // // The routine that is called simulates this process. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 23 October 2011 // // Author: // // John Burkardt // { int proc_first; int proc_last; int task_number; timestamp ( ); cout << "\n"; cout << "TASK_DIVISION_TEST():\n"; cout << " C++ version\n"; cout << " Test TASK_DIVISION(), which automates the division of\n"; cout << " T tasks among a range of P processors\n"; cout << " indexed from PROC_FIRST to PROC_LAST.\n"; task_number = 23; proc_first = 0; proc_last = 3; task_division ( task_number, proc_first, proc_last ); task_number = 17; proc_first = 1; proc_last = 6; task_division ( task_number, proc_first, proc_last ); task_number = 17; proc_first = 4; proc_last = 6; task_division ( task_number, proc_first, proc_last ); task_number = 5; proc_first = -2; proc_last = 6; task_division ( task_number, proc_first, proc_last ); task_number = 5; proc_first = 0; proc_last = 4; task_division ( task_number, proc_first, proc_last ); task_number = 5; proc_first = 0; proc_last = 0; task_division ( task_number, proc_first, proc_last ); task_number = 1000; proc_first = 1; proc_last = 17; task_division ( task_number, proc_first, proc_last ); // // Terminate. // cout << "\n"; cout << "TASK_DIVISION_TEST():\n"; cout << " Normal end of execution.\n"; cout << "\n"; timestamp ( ); return 0; } //****************************************************************************80 void timestamp ( ) //****************************************************************************80 // // Purpose: // // timestamp() prints the current YMDHMS date as a time stamp. // // Example: // // 31 May 2001 09:45:54 AM // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 19 March 2018 // // Author: // // John Burkardt // { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct std::tm *tm_ptr; std::time_t now; now = std::time ( NULL ); tm_ptr = std::localtime ( &now ); std::strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm_ptr ); std::cout << time_buffer << "\n"; return; # undef TIME_SIZE }