/* first_avail() * - Pick first avail output port w/ at least 1 unallocated VC */ int ocin_router_sel_noturn::first_avail(ocin_msg *msg) { map <int, set <int> >::iterator routes_itr; routes_itr = msg->routes.begin(); int p_out = (*routes_itr).first; if (msg->routes.size() > 1) { for (; routes_itr != msg->routes.end(); routes_itr++) { p_out = (*routes_itr).first; // If an avail VC has been found, terminate the search if (is_avail(p_out, msg)) break; } // for each valid output port } // if (routes > 1) return p_out; }
/* select() * - Oblivious selector implementing the "no turn" policy. * - Tries to keep the packet from turning as long as the * buffer space in the current dimension is avail. */ int ocin_router_sel_noturn::select(ocin_msg *msg) { map <int, set <int> >::iterator routes_itr; if (msg->routes.size() > 1) { int prev_pout = msg->p_out; // is the port we routed to on the prev node // available at this node? routes_itr = msg->routes.find(prev_pout); if (routes_itr != msg->routes.end()) { if (is_avail(prev_pout, msg)) return prev_pout; } } // If can't route in the same dim as before for whatever reason // (dim is not valid or no free buffers), route in the first // available dimension. return first_avail(msg); }
void solve(int depth) { if (depth >= N) return; for (int j = 0; j < N; ++j) { // detect if available if (is_avail(depth, j)) { grid[depth][j] = 'Q'; // output solution if (depth == N-1) { sol.push_back(grid); } else { solve(depth+1); } // reset grid[depth][j] = '.'; } } }