int main () { char row0[9] = {'.', '.', '.', '.', '.', '.', '5', '.', '.'}; char row1[9] = {'.', '4', '.', '.', '.', '.', '.', '.', '.'}; char row2[9] = {'.', '.', '.', '.', '.', '.', '.', '.', '.'}; char row3[9] = {'9', '3', '.', '.', '2', '4', '.', '.', '.'}; char row4[9] = {'.', '.', '7', '.', '.', '.', '3', '.', '.'}; char row5[9] = {'.', '.', '.', '.', '.', '.', '.', '.', '.'}; char row6[9] = {'.', '.', '.', '3', '4', '.', '.', '.', '.'}; char row7[9] = {'.', '.', '.', '.', '.', '3', '.', '.', '.'}; char row8[9] = {'.', '.', '.', '.', '.', '5', '2', '.', '.'}; std::vector<char> myVector0 (row0, row0 + 9); std::vector<char> myVector1 (row1, row1 + 9); std::vector<char> myVector2 (row2, row2 + 9); std::vector<char> myVector3 (row3, row3 + 9); std::vector<char> myVector4 (row4, row4 + 9); std::vector<char> myVector5 (row5, row5 + 9); std::vector<char> myVector6 (row6, row6 + 9); std::vector<char> myVector7 (row7, row7 + 9); std::vector<char> myVector8 (row8, row8 + 9); std::vector<std::vector<char> > matrix; matrix.push_back(myVector0); matrix.push_back(myVector1); matrix.push_back(myVector2); matrix.push_back(myVector3); matrix.push_back(myVector4); matrix.push_back(myVector5); matrix.push_back(myVector6); matrix.push_back(myVector7); matrix.push_back(myVector8); Solution *s = new Solution(); s->isValidSudoku(matrix); }
/** * Dynamically determines when to rearrange the pixel * allocations for the ray tracer step */ int step_decompose_image::execute ( const int & frame, ray_tracer & rt ) const { int current_frame = frame; // Consume // Execute - compute an initial even distribution int distributed = 0; int current_fragment = -1; std::vector<Point2D*> points[rt.number_fragments]; // No history yet, do an even distribution if(current_frame == 0) { int distribution = ((double)rt.image_width * (double)rt.image_height) / (double)rt.number_fragments; for(int i = 0; i < rt.image_width; ++i) { for(int j = 0; j < rt.image_height; ++j) { if((current_fragment + 1) < rt.number_fragments && distributed % distribution == 0) { points[++current_fragment] = std::vector<Point2D*>(); } points[current_fragment].push_back(new Point2D(i, j)); distributed++; } } } else { // Gather our previous pixel locations and times to compute each of them std::vector<Point2D*> all_points; std::vector<double> average_times; double total_time = 0; for(int fragment = 0; fragment < rt.number_fragments; fragment++) { std::vector<Point2D*> points; double time_to_trace; rt.pixel_locations.get(pair(current_frame - 1, fragment), points); rt.execution_time.get(pair(current_frame - 1, fragment), time_to_trace); double average_per_pixel = time_to_trace / (double) points.size(); std::cout << time_to_trace << ", "; for(int i = 0; i < points.size(); i++) { all_points.push_back(points[i]); average_times.push_back(average_per_pixel); } total_time += time_to_trace; } bool random_order = true; if(random_order) { std::vector<double> myVector(average_times.size()); std::vector<Point2D*> myVector2(all_points.size()); std::vector<Point2D*>::iterator it2 = all_points.begin(); int lastPos = 0; for(std::vector<double>::iterator it = average_times.begin(); it != average_times.end(); it2++, it++, lastPos++) { int insertPos = rand() % (lastPos + 1); if (insertPos < lastPos) { myVector[lastPos] = myVector[insertPos]; myVector2[lastPos] = myVector2[insertPos]; } myVector[insertPos] = *it; myVector2[insertPos] = *it2; } all_points = std::vector<Point2D*>(myVector2.begin(), myVector2.end()); average_times = std::vector<double>(myVector.begin(), myVector.end()); } std::cout << "\n"; int total_points = all_points.size(); double goal_time = total_time / 8.0; double current_time = 0; int current_fragment = 0; points[current_fragment] = std::vector<Point2D*>(); double new_total_time = 0; for(int i = 0; i < total_points; i++) { double time_for_pixel = average_times.back(); Point2D * point = all_points.back(); new_total_time += time_for_pixel; average_times.pop_back(); all_points.pop_back(); if(current_fragment + 1 < rt.number_fragments && (current_time + time_for_pixel) > goal_time) { points[++current_fragment] = std::vector<Point2D*>(); current_time = 0; } current_time += time_for_pixel; points[current_fragment].push_back(point); } } // Produce for(int fragment = 0; fragment < rt.number_fragments; fragment++) { std::cout << points[fragment].size() << ", "; rt.pixel_locations.put(pair(current_frame, fragment), points[fragment]); rt.frame_fragment.put(pair(frame, fragment)); } std::cout << "\n"; // Clean up //delete [] points; return CnC::CNC_Success; };