36 #include <basic/Tracer.hh>
38 #include <utility/assert.hh>
44 #include <utility/vector1.hh>
45 #include <boost/function.hpp>
51 static basic::Tracer
TR(
"WorkUnitManager");
63 return *(
wus_.begin());
69 runtime_assert(
size() != 0 );
76 return wus_.erase( i );
102 std::ofstream ofout(
swap_file_.c_str() , std::ios::app | std::ios::binary );
121 std::ofstream ofout(
std::string(prefix +
".outbound.queue").c_str() , std::ios::binary );
124 std::ofstream ofin(
std::string(prefix +
".inbound.queue").c_str() , std::ios::binary );
130 std::ifstream ifout(
std::string(prefix +
".outbound.queue").c_str() , std::ios::binary );
131 TR <<
"Reading outbound queue..." <<
std::string(prefix +
".outbound.queue") << std::endl;
134 std::ifstream ifin(
std::string(prefix +
".inbound.queue").c_str() , std::ios::binary );
135 TR <<
"Reading inbound queue..." <<
std::string(prefix +
".inbound.queue") << std::endl;
144 TR.Debug <<
"Read: " << count << std::endl;
155 it != the_queue.
end(); ++it )
166 double time1=MPI_Wtime();
168 double time2=MPI_Wtime();
170 int size_of_raw_data;
171 unsigned char * raw_data_ptr=NULL;
172 size_of_raw_data = wu->raw_data_dump( &raw_data_ptr );
173 TR.Debug <<
"Writing workunit .. " << std::endl;
175 out.write( (
char*) &size_of_raw_data, 4 );
176 out.write( (
char*)raw_data_ptr, size_of_raw_data );
177 TR.Debug <<
" Wrote data.. " << std::endl;
178 delete [] raw_data_ptr;
179 TR.Debug <<
" Deleted temp data.. " << std::endl;
180 wu->clear_serial_data();
181 double time3=MPI_Wtime();
182 TR.Debug <<
"S: " << time3-time2 <<
" " << time2-time1 <<
" " << std::endl;
188 unsigned int size_of_raw_data=0;
189 unsigned char * raw_data_ptr=NULL;
190 TR.Debug <<
"Reading a workunit..." << std::endl;
192 unsigned int my_WUB_magic_header_integer=0;
194 in.read( (
char*) &my_WUB_magic_header_integer, 4 );
196 TR.Debug <<
"EOF" << std::endl;
201 TR.Error <<
"ERROR Reading in WorkUnit from stream - Magic integer does not match. " << std::endl;
202 std::cerr <<
"Magic Integer in file: " << my_WUB_magic_header_integer <<
" != " <<
WUB_magic_header_integer << std::endl;
203 utility_exit_with_message(
"ERROR Reading in WorkUnit from stream - Magic integer does not match. " );
206 in.read( (
char*)&size_of_raw_data, 4 );
207 if( size_of_raw_data > (1024*1024*1024) ){
208 TR.Error <<
" Data corruption ? WorkUnitManager::read_work_unit found workunit with memory requirement > 1GB " << std::endl;
211 TR.Debug <<
" READ WU: BLOCKSIZE: " << size_of_raw_data << std::endl;
212 raw_data_ptr =
new unsigned char [size_of_raw_data];
214 in.read( (
char*)raw_data_ptr, (std::streamsize) size_of_raw_data );
216 if( raw_data_ptr[size_of_raw_data-1] != 0){
217 utility_exit_with_message(
" ERROR: cannot load data - terminal zero not found!" );
220 raw_data_ptr[size_of_raw_data-1] = 0;
221 TR.Debug <<
" READ WU: Data: " << std::endl;
224 runtime_assert( wu );
225 wu->raw_data_load( raw_data_ptr, size_of_raw_data );
226 delete [] raw_data_ptr;
234 runtime_assert( qualified_wu );
236 (*qualified_wu) = (*wu);
238 TR.Debug <<
" Received: " << std::endl;
239 if(
TR.Debug.visible() ) qualified_wu->print(
TR );
241 qualified_wu->deserialize( );
242 qualified_wu->clear_serial_data();
244 TR.Debug <<
"DONE Receiving" << std::endl;
254 mem_stats( n_structs, structs_memory, WU_memory);
255 return WU_memory + structs_memory;
269 WU_memory += (*it)->mem_footprint();
272 if ( structure_wu.get() == NULL )
continue;
274 n_structs += structure_wu->decoys().size();
276 jt != decoys.
end(); jt ++ )
278 structs_memory += (*jt)->mem_footprint();