int main ( int argc, char **argv ) { int result = 0; int i; nanos_wd_props_t props = { .mandatory_creation = true, .tied = false }; int level = omp_get_level(); int ancestor_num = omp_get_ancestor_thread_num( level ); int team_size = omp_get_team_size(level); int active_level = omp_get_active_level(); int in_final = omp_in_final(); printf ( " OpenMP API calls simple test:\n" ); printf ( "\tomp_get_level() = %d\n", level ); printf ( "\tomp_get_ancestor_thread_num(%d) = %d\n", level, ancestor_num ); printf ( "\tomp_get_team_size(%d) = %d\n", level, team_size ); printf ( "\tomp_get_active_level() = %d\n", active_level ); printf ( "\tomp_in_final() = %d\n", in_final ); if ( in_final != 0 ) result = 1; if ( active_level != 0 ) result = 2; if ( level != 0 ) result = 3; if ( ancestor_num != 0 ) result = 4; return result; }
int32_t omp_in_final_ (void) { return omp_in_final (); }
int add_cell(int id, coor FOOTPRINT, ibrd BOARD, struct cell *CELLS,int level) { int i, j, nn, area, nnc, nnl; coor footprint, NWS[DMAX]; nnc = nnl = 0; /* for each possible shape */ for (i = 0; i < CELLS[id].n; i++) { /* compute all possible locations for nw corner */ nn = starts(id, i, NWS, CELLS); nnl += nn; /* for all possible locations */ for (j = 0; j < nn; j++) { #pragma omp task untied private(footprint,area) \ firstprivate(NWS,i,j,id,nn,level,bots_cutoff_value) \ shared(FOOTPRINT,BOARD,CELLS,MIN_AREA,MIN_FOOTPRINT,N,BEST_BOARD,nnc,bots_verbose_mode) \ final(level >= bots_cutoff_value) mergeable { ibrd board; struct cell *cells; if ( omp_in_final() && level > bots_cutoff_value ) { cells = CELLS; } else { cells = alloca(sizeof(struct cell)*(N+1)); memcpy(cells,CELLS,sizeof(struct cell)*(N+1)); } /* extent of shape */ cells[id].top = NWS[j][0]; cells[id].bot = cells[id].top + cells[id].alt[i][0] - 1; cells[id].lhs = NWS[j][1]; cells[id].rhs = cells[id].lhs + cells[id].alt[i][1] - 1; memcpy(board, BOARD, sizeof(ibrd)); /* if the cell cannot be layed down, prune search */ if (! lay_down(id, board, cells)) { bots_debug("Chip %d, shape %d does not fit\n", id, i); } else { /* calculate new footprint of board and area of footprint */ footprint[0] = max(FOOTPRINT[0], cells[id].bot+1); footprint[1] = max(FOOTPRINT[1], cells[id].rhs+1); area = footprint[0] * footprint[1]; /* if last cell */ if (cells[id].next == 0) { /* if area is minimum, update global values */ if (area < MIN_AREA) { #pragma omp critical if (area < MIN_AREA) { MIN_AREA = area; MIN_FOOTPRINT[0] = footprint[0]; MIN_FOOTPRINT[1] = footprint[1]; memcpy(BEST_BOARD, board, sizeof(ibrd)); bots_debug("N %d\n", MIN_AREA); } } /* if area is less than best area */ } else if (area < MIN_AREA) { int val = add_cell(cells[id].next, footprint, board,cells,level+1); #pragma omp atomic nnc += val; /* if area is greater than or equal to best area, prune search */ } else { bots_debug("T %d, %d\n", area, MIN_AREA); } } } } } #pragma omp taskwait return nnc+nnl; }