Exemple #1
0
/* Print a check if the cell was visited. */
void maze_to_fig_visited(FILE *fp, struct maze *mp, int row, int col, int upc)
{
	if (maze_get_cell(mp, row, col) & VISITED)
		maze_to_fig_line(fp, col * upc, row * upc,
				 (col + 1) * upc, (row + 1) * upc, 14,
				 100 + maze_get_cell_tid(mp, row, col));
}
Exemple #2
0
/*
 * Mark the subsolution located by a interior thread, in other words, a
 * thread other than the ones that started at the beginning and end cells.
 */
int maze_mark_subsolution(struct maze *mp, int r1, int c1, int r2, int c2)
{
	int cr1 = r1;
	int cc1 = c1;
	int cr2 = r2;
	int cc2 = c2;
	cell_t *cp;
	int d1 = maze_get_cell_distance(mp, cr1, cc1);
	int d2 = maze_get_cell_distance(mp, cr2, cc2);
	int nr;
	int nc;
	int s = 0;

	for (;;) {
		if (maze_get_cell_tid(mp, cr1, cc1) !=
		    maze_get_cell_tid(mp, cr2, cc2))
		    	ABORT();
		if (cr1 == cr2 && cc1 == cc2) {
			cp = maze_get_cell_addr(mp, cr1, cc1);
			*cp |= SOLUTION;
			return s + 1;
		}
		if (d1 > d2) {
			maze_mark_advance_cell(mp, cr1, cc1, &nr, &nc);
			s++;
			cr1 = nr;
			cc1 = nc;
			d1 = maze_get_cell_distance(mp, cr1, cc1);
		} else if (d1 <= d2 && d2 != 1) {
			maze_mark_advance_cell(mp, cr2, cc2, &nr, &nc);
			s++;
			cr2 = nr;
			cc2 = nc;
			d2 = maze_get_cell_distance(mp, cr2, cc2);
		} else
			ABORT();
	}
}
Exemple #3
0
/* Record an encounter between a pair of threads. */
void record_encounter(struct maze *mp, int cr, int cc, int tr, int tc)
{
	int theirtid;
	struct maze_child_shared *mcsp;

	if (mymcp == NULL || nthreads == 1)
		return;  /* Not yet solving the maze or only one thread. */
	mcsp = mymcp->mcsp;
	theirtid = maze_get_cell_tid(mp, tr, tc);
	if (theirtid == myid)
		return; /* We  ran into ourselves, so ignore. */
	(void)__sync_lock_test_and_set(&mymcp->adj[theirtid].mr, cr);
	mymcp->adj[theirtid].mc = cc;
	mymcp->adj[theirtid].tr = tr;
	mymcp->adj[theirtid].tc = tc;
	if (nthreads == 2)
		ACCESS_ONCE(mcsp->done) = 1;
	maze_solve_propagate(mymcp, &mymcp->mcp0[theirtid]);
	maze_solve_propagate(&mymcp->mcp0[theirtid], mymcp);
}
Exemple #4
0
/* Return true if both cells were visited by the same thread. */
int maze_same_tids(struct maze *mp, int r1, int c1, int r2, int c2)
{
	return maze_get_cell_tid(mp, r1, c1) == maze_get_cell_tid(mp, r2, c2);
}