SAGA Adaptor CPI v.1.0
|
00001 // Copyright (c) 2005 Stephan Hirmer (shirmer@cct.lsu.edu) 00002 // 00003 // Use, modification and distribution is subject to the Boost Software 00004 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 00005 // http://www.boost.org/LICENSE_1_0.txt) 00006 00007 #include <utility> 00008 #include <vector> 00009 00010 #include <saga/saga/adaptors/task_declaration.hpp> 00011 #include <saga/impl/engine/task_container.hpp> 00012 #include <saga/saga/adaptors/bulk_strategy_simple_sort.hpp> 00013 00015 namespace saga 00016 { 00017 namespace adaptors 00018 { 00019 bulk_strategy_simple_sort::bulk_strategy_simple_sort() 00020 { 00021 } 00022 00023 void bulk_strategy_simple_sort::apply(sorted_tc_type & analyser_res) 00024 { 00025 // this->thread_ = simple_future <int> ( 00026 // TR1::bind (&bulk_strategy_simple_sort::bond_apply, 00027 // this, TR1::ref(analyser_res)) ); 00028 // //this->complete_wait(); 00029 this->bond_apply(analyser_res); 00030 } 00031 00032 int bulk_strategy_simple_sort::bond_apply (sorted_tc_type& analyser_res) 00033 { 00034 using namespace boost; 00035 using namespace saga::impl; 00036 00037 // iterate over the sorted result 00038 sorted_tc_type::iterator it = analyser_res.begin (); 00039 00040 while ( it != analyser_res.end () ) 00041 { 00042 saga::task_container tmp_tc = it->second; 00043 00044 // just for testing 00045 // std::cout << "task container: " << it->first << std::endl; 00046 // std::cout << "----------> Number in there: " 00047 // << (unsigned)(it->second.list_tasks () ).size () << std::endl; 00048 00049 saga::impl::v1_0::preference_type prefs; 00050 00051 std::string cpi_name; 00052 std::string op_name; 00053 00054 this->default_process_func_name ((it->first), cpi_name, op_name); 00055 00056 // asking the first task, to search an appropriate adaptor for 00057 // an possible bulk execution 00058 std::vector<saga::task> bulk_task_list = tmp_tc.list_tasks(); 00059 00060 // we search for a bulk adaptor, if the bulk contains more than 00061 // one task. 00062 00063 // TR1::shared_ptr <v1_0::cpi> my_bulk_adaptor; 00064 std::vector<saga::task>::iterator bulk_task_list_iter = bulk_task_list.begin (); 00065 00066 if ( bulk_task_list.size () > 1 ) 00067 { 00068 my_bulk_adaptor = TR1::shared_ptr<v1_0::cpi> 00069 (runtime::get_impl (*bulk_task_list_iter) 00070 ->get_bulk_adaptor (cpi_name, op_name, prefs) ); 00071 } 00072 00073 // if we have an appropriate bulk_adaptor, we execute the 00074 // bulk using this bulk_adaptor 00075 if ( my_bulk_adaptor ) 00076 { 00077 // std::cout<<"found bulk adaptor ... "<<std::endl; 00078 my_bulk_adaptor->init_bulk (); 00079 00080 // prepare the arguments 00081 while ( bulk_task_list_iter != bulk_task_list.end () ) 00082 { 00083 runtime::get_impl (*bulk_task_list_iter) 00084 ->visit_args (my_bulk_adaptor.get ()); 00085 ++bulk_task_list_iter; 00086 } 00087 00088 my_bulk_adaptor->execute_bulk(); 00089 00090 // set the state of all the tasks to Done 00091 boost::get_pointer(runtime::get_impl (tmp_tc)) 00092 ->set_state_for_all (saga::task::Done); 00093 00094 00095 } 00096 // if not, we execute the task one by one. 00097 else 00098 { 00099 // std::cout << "NO bulk adaptor found ... " << std::endl; 00100 // execute this task_container one by one! 00101 runtime::get_impl (it->second)->simple_run (); 00102 } 00103 00104 ++it; 00105 00106 } // end while 00107 return 1; 00108 } 00109 00110 } // namespace adaptors 00111 00112 } // namespace saga 00113