int main(int argc, char **argv) { int a_origin_size; int i, max; signal(SIGCHLD, sigchld_handler); signal(SIGTERM, clean); signal(SIGQUIT, clean); if(argc == 1) { printf("введите количество элементов в массиве: "); fflush(stdout); } scanf("%d", &a_origin_size); if(a_origin_size <= 0) { exit(0); } a_size = round2(a_origin_size); sn_init(); for(i = max = 0; i < a_origin_size; i++) { scanf("%d", array + i); max = MAX(array[i], max); } for(; i < a_size; array[i++] = max); if(a_origin_size > 1) { build_schedule(); //print_schedule(); run(); } for(i = 0; i < a_origin_size; printf("%d ", array[i++])); printf("\n"); clean(0); return 0; }
shacal1(key_type const &k) : basic_shacal(build_schedule(k)) {}
shacal2(key_type const &key) : schedule(build_schedule(key)) {}
/** * Converts a SCoP as extracted by PolyOpt's auto-scop detection * into ISL representation. * * bugs/limitations: * (a) not robust to union of iteration domains in scoplib * (b) code is leaking, need proper copy constructor that duplicates all * ISL structures. */ int PolyOptISLRepresentation::convertScoplibToISL (scoplib_scop_p scop) { int i; isl_union_map* all_reads = NULL; isl_union_map* all_writes = NULL; isl_union_map* all_scheds = NULL; isl_ctx* ctxt = isl_ctx_alloc(); // 1. Prepare the arrays of unique names for statements and arrays. char buffer[32]; int nb_statements; scoplib_statement_p s; for (nb_statements = 0, s = scop->statement; s; s = s->next, nb_statements++) ; char* stmt_names[nb_statements]; for (i = 0; i < nb_statements; ++i) { sprintf (buffer, "S_%d", i); stmt_names[i] = strdup (buffer); } char* array_names[scop->nb_arrays]; for (i = 0; i < scop->nb_arrays; ++i) array_names[i] = strdup (((SgVariableSymbol*)(scop->arrays[i]))->get_name().str()); isl_union_map* umap; int stmt_id; for (s = scop->statement, stmt_id = 0; s; s = s->next, ++stmt_id) { isl_union_map* all_reads_stmt = NULL; isl_union_map* all_writes_stmt = NULL; isl_space* sp = NULL; for (i = 0; i < scop->nb_arrays; ++i) { sp = build_isl_space (scop, s, i+1, ctxt); // 1. Handle access matrices. scoplib_matrix_p m; int k; for (k = 0, m = s->read, umap = all_reads_stmt; k < 2; k++, m = s->write, umap = all_writes_stmt) { isl_map* acc_map = NULL; int row_pos = 0; do { acc_map = build_access_function (scop, s, m, sp, ctxt, &row_pos, i+1); if (acc_map) { acc_map = isl_map_set_tuple_name (acc_map, isl_dim_in, stmt_names[stmt_id]); acc_map = isl_map_set_tuple_name (acc_map, isl_dim_out, array_names[i]); if (umap == NULL) umap = isl_union_map_from_map (isl_map_copy (acc_map)); else umap = isl_union_map_union (umap, isl_union_map_from_map (isl_map_copy (acc_map))); isl_map_free (acc_map); } } while (acc_map != NULL); if (k == 0) all_reads_stmt = umap; else all_writes_stmt = umap; } } // Store the union of access functions of statement i. stmt_accfunc_read.push_back (all_reads_stmt); stmt_accfunc_write.push_back (all_writes_stmt); // 2. Handle iteration domains. isl_set* dom = build_iteration_domain (scop, s, sp, ctxt); dom = isl_set_set_tuple_name (dom, stmt_names[stmt_id]); if (all_reads_stmt != NULL) all_reads_stmt = isl_union_map_intersect_domain (isl_union_map_copy (all_reads_stmt), isl_union_set_from_set (isl_set_copy (dom))); if (all_writes_stmt != NULL) all_writes_stmt = isl_union_map_intersect_domain (all_writes_stmt, isl_union_set_from_set (isl_set_copy (dom))); // Store the iteration domain of statement i. stmt_iterdom.push_back (dom); // Store the union of access functions of statement i after intersection by domain. stmt_read_domain.push_back (all_reads_stmt); stmt_write_domain.push_back (all_writes_stmt); // Unionize the result. if (all_reads == NULL) all_reads = isl_union_map_copy (all_reads_stmt); else all_reads = isl_union_map_union (all_reads, isl_union_map_copy (all_reads_stmt)); if (all_writes == NULL) all_writes = isl_union_map_copy (all_writes_stmt); else all_writes = isl_union_map_union (all_writes, isl_union_map_copy (all_writes_stmt)); // isl_union_map_free (all_reads_stmt); // isl_union_map_free (all_writes_stmt); // 3. Handle schedules. isl_map* sched = build_schedule (scop, s, sp, ctxt); sched = isl_map_set_tuple_name (sched, isl_dim_in, stmt_names[stmt_id]); if (all_scheds == NULL) all_scheds = isl_union_map_from_map (isl_map_copy (sched)); else all_scheds = isl_union_map_union (all_scheds, isl_union_map_from_map (isl_map_copy (sched))); // Store the schedule of statement i. stmt_schedule.push_back (sched); // 4. Finalize info about the statement. stmt_body.push_back (((SgNode*)(s->body))->unparseToCompleteString()); stmt_body_ir.push_back ((SgNode*)(s->body)); } // // Debug. // isl_printer* pr = isl_printer_to_file (ctxt, stdout); // std::cout << "UNION MAP READS" << std::endl; // isl_printer_print_union_map(pr, all_reads); // printf ("\n"); // std::cout << "UNION MAP WRITES" << std::endl; // isl_printer_print_union_map(pr, all_writes); // printf ("\n"); // std::cout << "UNION MAP SCHEDULES" << std::endl; // isl_printer_print_union_map(pr, all_scheds); // printf ("\n"); for (std::vector<std::string>::iterator i = stmt_body.begin(); i != stmt_body.end(); ++i) std::cout << "stmt body: " << *i << std::endl; // Finalize SCoP representation. scop_nb_arrays = scop->nb_arrays; scop_nb_statements = stmt_schedule.size(); scop_reads = all_reads; scop_writes = all_writes; scop_scheds = all_scheds; return EXIT_SUCCESS; }