int hpx_main(boost::program_options::variables_map& vm) { // find locality info std::vector<hpx::naming::id_type> locs = hpx::find_all_localities(); // create data std::vector<unsigned int> vec; for (unsigned long j=0; j < 300000; j++) { vec.push_back(1); } // send out data for (unsigned int j = 0; j < 8; j++) { std::vector<hpx::future<void> > fut1; for (std::size_t i = 0; i < locs.size(); i++) { typedef out_action out_act; fut1.push_back(hpx::async<out_act>(locs.at(i), vec)); hpx::cout << "Scheduled out to " << i+1 << std::endl; } wait_all(fut1); hpx::cout << j+1 << ". round finished " << std::endl; } hpx::cout << "program finished!!!" << std::endl; return hpx::finalize(); }
static void process(std::vector<std::string> const& input) { // job for first stage auto grep = [](std::string const& re, std::string const& item) { boost::regex regex(re); if (boost::regex_match(item, regex)) { auto trim = [](std::string const& s) { return boost::algorithm::trim_copy(s); }; hpx::async(trim, std::move(item)) .then(hpx::util::unwrapping( [](std::string const& tc) { std::cout << "->" << tc << std::endl; })); } }; std::vector<hpx::future<void> > tasks; for(auto s: input) { tasks.push_back(hpx::async(grep, "Error.*", std::move(s))); } wait_all(tasks); }
std::vector<std::vector<double> > operator()() const { namespace naming = hpx::naming; namespace lcos = hpx::lcos; // create the overall result vector std::vector<std::vector<double> > overall_results; overall_results.resize(size); // asynchronously invoke the interpolation on the different partitions std::vector<lcos::future<void> > lazy_results; lazy_results.reserve(partitions->size()); typedef std::map<naming::id_type, context_data>::value_type value_type; for (value_type& p : *partitions) { typedef sheneos::server::partition3d::interpolate_bulk_action action_type; context_data& d = p.second; lazy_results.push_back( hpx::async<action_type>( p.first, std::move(d.coords_), eosvalues ).then( on_completed_bulk(partitions, d, overall_results) ) ); } // wait for all asynchronous operations to complete wait_all(lazy_results); return overall_results; }
Matrix* balanceWork(Matrix* m1, Matrix* m2, int numThreads) { int i, amountOfWorkToEach = 0, workLeft = 0, aditionalWork = 0, start, end, lastStartIndex = 0; Matrix* result = (Matrix*) malloc(sizeof(Matrix)); pthread_t* threads = (pthread_t*) calloc(numThreads, sizeof(pthread_t)); result->data = initMatrix(m1->rows, m2->columns); result->rows = m1->rows; result->columns = m2->columns; amountOfWorkToEach = (m1->rows / numThreads); workLeft = m1->rows % numThreads; aditionalWork = (workLeft > 0) ? 1 : 0; workLeft--; for (i = 0; i < numThreads; i++) { start = lastStartIndex; end = start + amountOfWorkToEach + aditionalWork; lastStartIndex = end; threads[i] = startWorker(m1, m2, result, start, end); aditionalWork = (workLeft > 0) ? 1 : 0; workLeft--; } wait_all(threads, numThreads); return result; }
main() { int nprocs = 4; //tempo struct timeval iniciotmp, finaltmp; int tempogasto; int pidf,id_wait; void dt_shareG(); mc_var_inic (); def_task (0, "inicializa_matriz", sizeof (__inicializa_matriz__)); def_task (1, "multiplica_matriz", sizeof (__multiplica_matriz__)); id_wait=sem_wait_inic(2); alloc_proc(nprocs); pidf = exec_task (0, nprocs); /* --- rs30() - create --- */ if (pidf == 0) { inicializa_matriz(); end_task(); /* --- rs31() - create --- */ } wait_all(); gettimeofday(&iniciotmp, NULL); pidf = exec_task (1, nprocs); /* --- rs30() - create --- */ if (pidf == 0) { multiplica_matriz(); end_task(); /* --- rs31() - create --- */ } wait_all(); gettimeofday(&finaltmp, NULL); tempogasto = (int) (1000 * (finaltmp.tv_sec - iniciotmp.tv_sec) + (finaltmp.tv_usec - iniciotmp.tv_usec) / 1000); printf("Tempo decorrido: %d\n", tempogasto); wait_all(); /* --- rs307() */ end_program(); remove_semaforo(id_wait); return 0; }
void EstimatorManager::collectBlockAverages(int num_threads) { if(Options[COLLECT]) { //copy cached data to RemoteData[0] int n1=AverageCache.size(); int n2=n1+AverageCache.size(); int n3=n2+PropertyCache.size(); { BufferType::iterator cur(RemoteData[0]->begin()); std::copy(AverageCache.begin(),AverageCache.end(),cur); std::copy(SquaredAverageCache.begin(),SquaredAverageCache.end(),cur+n1); std::copy(PropertyCache.begin(),PropertyCache.end(),cur+n2); } #if defined(QMC_ASYNC_COLLECT) if(Options[MANAGE]) { //wait all the message but we can choose to wait one-by-one with a timer wait_all(myRequest.size(),&myRequest[0]); for(int is=1; is<myComm->size(); is++) accumulate_elements(RemoteData[is]->begin(),RemoteData[is]->end(), RemoteData[0]->begin()); } else //not a master, pack and send the data myRequest[0]=myComm->isend(0,myComm->rank(),*RemoteData[0]); #else myComm->reduce(*RemoteData[0]); #endif if(Options[MANAGE]) { BufferType::iterator cur(RemoteData[0]->begin()); std::copy(cur,cur+n1, AverageCache.begin()); std::copy(cur+n1,cur+n2, SquaredAverageCache.begin()); std::copy(cur+n2,cur+n3, PropertyCache.begin()); RealType nth=1.0/static_cast<RealType>(myComm->size()); AverageCache *= nth; SquaredAverageCache *= nth; //do not weight weightInd for(int i=1; i<PropertyCache.size(); i++) PropertyCache[i] *= nth; } } //add the block average to summarize energyAccumulator(AverageCache[0]); varAccumulator(SquaredAverageCache[0]-AverageCache[0]*AverageCache[0]); if(Archive) { *Archive << setw(10) << RecordCount; int maxobjs=std::min(BlockAverages.size(),max4ascii); for(int j=0; j<maxobjs; j++) *Archive << setw(FieldWidth) << AverageCache[j]; for(int j=0; j<PropertyCache.size(); j++) *Archive << setw(FieldWidth) << PropertyCache[j]; *Archive << endl; for(int o=0; o<h5desc.size(); ++o) h5desc[o]->write(AverageCache.data(),SquaredAverageCache.data()); H5Fflush(h_file,H5F_SCOPE_LOCAL); } RecordCount++; }
void mpijob_manager::stop_all() { #ifdef __MPI__ cout << "master: ordering all slaves to stop." << endl; boost::mpi::request *reqs = new boost::mpi::request[world.size()]; for (int i = 1; i < world.size(); ++i) { reqs[i] = world.isend(i, CMD_STOP, 0); } wait_all(reqs + 1, reqs + world.size()); cout << "master: all slaves stopped." << endl; // deleting reqs makes the program crash // delete reqs; #endif }
ThreadPool::~ThreadPool() { std::unique_lock<std::mutex> lck(mt); running = false; lck.unlock(); wait_all(); for (auto& cv : cvv) cv.notify_all(); for (auto& w : workers) { w.join(); } }
void parfor(std::size_t idx_start, std::size_t idx_end, Lambda &&loopBody, TaskScheduler &scheduler, std::size_t blockSize = 32) { static_assert(std::is_same<void, typename std::result_of<Lambda(std::size_t)>::type>::value, "Loop body must return void"); auto loopLen = (idx_end - idx_start); //Execute short loops in serial if(loopLen < 10*blockSize) { for(std::size_t i=idx_start; i<idx_end; ++i) { loopBody(i); } return; } auto full_blocks = loopLen / blockSize; auto cleanup_start = full_blocks * blockSize + idx_start; auto Nblocks = full_blocks + ((cleanup_start < idx_end) ? 1 : 0); std::vector<std::future<void>> futs; futs.reserve(Nblocks); for (std::size_t iblock = 0; iblock < Nblocks; ++iblock) { std::size_t i_start = idx_start + iblock * blockSize; std::size_t i_end = i_start + blockSize; i_end = (i_end < idx_end) ? i_end : idx_end; auto [task, fut] = scheduler.createTask([&loopBody, i_start, i_end]() { for (auto i = i_start; i < i_end; ++i) { loopBody(i); } }); scheduler.enqueue(task); futs.push_back(std::move(fut)); } wait_all(futs); //return futs; }
void xexit(int exit_value) /* exit after having freed memory and removed lock file */ { cf_t *f = NULL; now = time(NULL); /* we save all files now and after having waiting for all * job being executed because we might get a SIGKILL * if we don't exit quickly */ save_file(NULL); #ifdef FCRONDYN close_socket(); #endif f = file_base; while (f != NULL) { if (f->cf_running > 0) { /* */ debug("waiting jobs for %s ...", f->cf_user); /* */ wait_all(&f->cf_running); save_file(f); } delete_file(f->cf_user); /* delete_file remove the f file from the list : * next file to remove is now pointed by file_base. */ f = file_base; } remove(pidfile); exe_list_destroy(exe_list); lavg_list_destroy(lavg_list); free_conf(); Free_safe(orig_tz_envvar); explain("Exiting with code %d", exit_value); exit(exit_value); }
/* process command within a request */ static int process_command( int new_sockfd, struct server_ctx* ctx, const char* param, size_t plen ) { int rc = 0; const int STAT_OPTIONS = 0; const int RESTART_OPTIONS = MSO_SKIP_CLIENTS | MSO_RESTART; assert( (new_sockfd > 0) && ctx && param ); if( 0 == strncmp( ctx->cmd, CMD_UDP, sizeof(ctx->cmd) ) || 0 == strncmp( ctx->cmd, CMD_RTP, sizeof(ctx->cmd) ) ) { if( ctx->clfree ) { rc = udp_relay( new_sockfd, param, plen, &(ctx->mcast_inaddr), ctx ); } else { send_http_response( new_sockfd, 401, "Bad request" ); (void)tmfprintf( g_flog, "Client limit [%d] has been reached.\n", ctx->clmax); } } else if( 0 == strncmp( ctx->cmd, CMD_STATUS, sizeof(ctx->cmd) ) ) { rc = report_status( new_sockfd, ctx, STAT_OPTIONS ); } else if( 0 == strncmp( ctx->cmd, CMD_RESTART, sizeof(ctx->cmd) ) ) { (void) report_status( new_sockfd, ctx, RESTART_OPTIONS ); terminate_all_clients( ctx ); wait_all( ctx ); } else { TRACE( (void)tmfprintf( g_flog, "Unrecognized command [%s]" " - ignoring.\n", ctx->cmd) ); send_http_response( new_sockfd, 401, "Unrecognized request" ); } return rc; }
/* process client requests */ int srv_loop( const char* ipaddr, int port, const char* mcast_addr ) { int rc, maxfd, err, nrdy, i; fd_set rset; struct timeval tmout, idle_tmout, *ptmout = NULL; tmfd_t *asock = NULL; size_t n = 0, nasock = 0, max_nasock = LQ_BACKLOG; sigset_t oset, bset; static const long IDLE_TMOUT_SEC = 30; assert( (port > 0) && mcast_addr && ipaddr ); (void)tmfprintf( g_flog, "Server is starting up, max clients = [%u]\n", g_uopt.max_clients ); asock = calloc (max_nasock, sizeof(*asock)); if (!asock) { mperror (g_flog, ENOMEM, "%s: calloc", __func__); return ERR_INTERNAL; } init_server_ctx( &g_srv, g_uopt.max_clients, (ipaddr[0] ? ipaddr : "0.0.0.0") , (uint16_t)port, mcast_addr ); g_srv.rcv_tmout = (u_short)g_uopt.rcv_tmout; g_srv.snd_tmout = RLY_SOCK_TIMEOUT; /* NB: server socket is non-blocking! */ if( 0 != (rc = setup_listener( ipaddr, port, &g_srv.lsockfd, g_uopt.lq_backlog )) ) { return rc; } sigemptyset (&bset); sigaddset (&bset, SIGINT); sigaddset (&bset, SIGQUIT); sigaddset (&bset, SIGCHLD); sigaddset (&bset, SIGTERM); (void) sigprocmask (SIG_BLOCK, &bset, &oset); TRACE( (void)tmfprintf( g_flog, "Entering server loop [%s]\n", SLOOP_TAG) ); while (1) { FD_ZERO( &rset ); FD_SET( g_srv.lsockfd, &rset ); FD_SET( g_srv.cpipe[0], &rset ); maxfd = (g_srv.lsockfd > g_srv.cpipe[0] ) ? g_srv.lsockfd : g_srv.cpipe[0]; for (i = 0; (size_t)i < nasock; ++i) { assert (asock[i].fd >= 0); FD_SET (asock[i].fd, &rset); if (asock[i].fd > maxfd) maxfd = asock[i].fd; } /* if there are accepted sockets - apply specified time-out */ tmout.tv_sec = g_uopt.ssel_tmout; tmout.tv_usec = 0; idle_tmout.tv_sec = IDLE_TMOUT_SEC; idle_tmout.tv_usec = 0; /* enforce *idle* select(2) timeout to alleviate signal contention */ ptmout = ((nasock > 0) && (g_uopt.ssel_tmout > 0)) ? &tmout : &idle_tmout; TRACE( (void)tmfprintf( g_flog, "Waiting for input from [%ld] fd's, " "%s timeout\n", (long)(2 + nasock), (ptmout ? "with" : "NO"))); if (ptmout && ptmout->tv_sec) { TRACE( (void)tmfprintf (g_flog, "select() timeout set to " "[%ld] seconds\n", ptmout->tv_sec) ); } (void) sigprocmask (SIG_UNBLOCK, &bset, NULL); if( must_quit() ) { TRACE( (void)tmfputs( "Must quit now\n", g_flog ) ); rc = 0; break; } nrdy = select (maxfd + 1, &rset, NULL, NULL, ptmout); err = errno; (void) sigprocmask (SIG_BLOCK, &bset, NULL); if( must_quit() ) { TRACE( (void)tmfputs( "Must quit now\n", g_flog ) ); rc = 0; break; } wait_terminated( &g_srv ); if( nrdy < 0 ) { if (EINTR == err) { TRACE( (void)tmfputs ("INTERRUPTED, yet " "will continue.\n", g_flog) ); rc = 0; continue; } mperror( g_flog, err, "%s: select", __func__ ); break; } TRACE( (void)tmfprintf (g_flog, "Got %ld requests\n", (long)nrdy) ); if (0 == nrdy) { /* time-out */ tmout_requests (asock, &nasock); rc = 0; continue; } if( FD_ISSET(g_srv.cpipe[0], &rset) ) { (void) tpstat_read( &g_srv ); if (--nrdy <= 0) continue; } if ((0 < nasock) && (0 < (nrdy - (FD_ISSET(g_srv.lsockfd, &rset) ? 1 : 0)))) { process_requests (asock, &nasock, &rset, &g_srv); /* n now contains # (yet) unprocessed accepted sockets */ } if (FD_ISSET(g_srv.lsockfd, &rset)) { if (nasock >= max_nasock) { (void) tmfprintf (g_flog, "Cannot accept sockets beyond " "the limit [%ld/%ld], skipping\n", (long)nasock, (long)max_nasock); } else { n = max_nasock - nasock; /* append asock */ accept_requests (g_srv.lsockfd, &(asock[nasock]), &n); nasock += n; } } } /* server loop */ TRACE( (void)tmfprintf( g_flog, "Exited server loop [%s]\n", SLOOP_TAG) ); for (i = 0; (size_t)i < nasock; ++i) { if (asock[i].fd > 0) (void) close (asock[i].fd); } free (asock); /* receive additional (blocked signals) */ (void) sigprocmask (SIG_SETMASK, &oset, NULL); wait_terminated( &g_srv ); terminate_all_clients( &g_srv ); wait_all( &g_srv ); if (0 != close( g_srv.lsockfd )) { mperror (g_flog, errno, "server socket close"); } free_server_ctx( &g_srv ); (void)tmfprintf( g_flog, "Server exits with rc=[%d]\n", rc ); return rc; }
/* Check all file systems, using the /etc/fstab table. */ static int check_all(NOARGS) { struct fs_info *fs = NULL; int status = EXIT_OK; int not_done_yet = 1; int passno = 1; int pass_done; if (verbose) printf(_("Checking all file systems.\n")); /* * Do an initial scan over the filesystem; mark filesystems * which should be ignored as done, and resolve LABEL= and * UUID= specifications to the real device. */ for (fs = filesys_info; fs; fs = fs->next) { if (ignore(fs)) fs->flags |= FLAG_DONE; else fs->device = interpret_device(fs->device); } /* * Find and check the root filesystem. */ if (!parallel_root) { for (fs = filesys_info; fs; fs = fs->next) { if (!strcmp(fs->mountpt, "/")) break; } if (fs) { if (!skip_root && !ignore(fs)) { fsck_device(fs->device, 1); status |= wait_all(0); if (status > EXIT_NONDESTRUCT) return status; } fs->flags |= FLAG_DONE; } } /* * This is for the bone-headed user who enters the root * filesystem twice. Skip root will skep all root entries. */ if (skip_root) for (fs = filesys_info; fs; fs = fs->next) if (!strcmp(fs->mountpt, "/")) fs->flags |= FLAG_DONE; while (not_done_yet) { not_done_yet = 0; pass_done = 1; for (fs = filesys_info; fs; fs = fs->next) { if (cancel_requested) break; if (fs->flags & FLAG_DONE) continue; /* * If the filesystem's pass number is higher * than the current pass number, then we don't * do it yet. */ if (fs->passno > passno) { not_done_yet++; continue; } /* * If a filesystem on a particular device has * already been spawned, then we need to defer * this to another pass. */ if (device_already_active(fs->device)) { pass_done = 0; continue; } /* * Spawn off the fsck process */ fsck_device(fs->device, serialize); fs->flags |= FLAG_DONE; /* * Only do one filesystem at a time, or if we * have a limit on the number of fsck's extant * at one time, apply that limit. */ if (serialize || (max_running && (num_running >= max_running))) { pass_done = 0; break; } } if (cancel_requested) break; if (verbose > 1) printf(_("--waiting-- (pass %d)\n"), passno); status |= wait_all(pass_done ? 0 : WNOHANG); if (pass_done) { if (verbose > 1) printf("----------------------------------\n"); passno++; } else not_done_yet++; } if (cancel_requested && !kill_sent) { kill_all(SIGTERM); kill_sent++; } status |= wait_all(0); return status; }
int main(int argc, char *argv[]) { int i; int status = 0; int interactive = 0; char *oldpath = getenv("PATH"); const char *fstab; #ifdef ENABLE_NLS setlocale(LC_MESSAGES, ""); setlocale(LC_CTYPE, ""); bindtextdomain(NLS_CAT_NAME, LOCALEDIR); textdomain(NLS_CAT_NAME); #endif PRS(argc, argv); if (!notitle) printf("fsck %s (%s)\n", E2FSPROGS_VERSION, E2FSPROGS_DATE); fstab = getenv("FSTAB_FILE"); if (!fstab) fstab = _PATH_MNTTAB; load_fs_info(fstab); /* Update our search path to include uncommon directories. */ if (oldpath) { fsck_path = malloc (strlen (fsck_prefix_path) + 1 + strlen (oldpath) + 1); strcpy (fsck_path, fsck_prefix_path); strcat (fsck_path, ":"); strcat (fsck_path, oldpath); } else { fsck_path = string_copy(fsck_prefix_path); } if ((num_devices == 1) || (serialize)) interactive = 1; /* If -A was specified ("check all"), do that! */ if (doall) return check_all(); if (num_devices == 0) { serialize++; interactive++; return check_all(); } for (i = 0 ; i < num_devices; i++) { if (cancel_requested) { if (!kill_sent) { kill_all(SIGTERM); kill_sent++; } break; } fsck_device(devices[i], interactive); if (serialize || (max_running && (num_running >= max_running))) { struct fsck_instance *inst; inst = wait_one(0); if (inst) { status |= inst->exit_status; free_instance(inst); } if (verbose > 1) printf("----------------------------------\n"); } } status |= wait_all(0); free(fsck_path); return status; }
void op_par_loop_adt_calc(char const *name, op_set set, op_arg arg0, op_arg arg1, op_arg arg2, op_arg arg3, op_arg arg4, op_arg arg5 ){ int nargs = 6; op_arg args[6] = {arg0,arg1,arg2,arg3,arg4,arg5}; int ninds = 1; int inds[6] = {0,0,0,0,-1,-1}; int sent[6] = {0,0,0,0,0,0}; if(ninds > 0) //indirect loop { for(int i = 0; i<nargs; i++) { if(args[i].argtype == OP_ARG_DAT) { if (OP_diags==1) reset_halo(args[i]); sent[0] = exchange_halo(args[i]); if(sent[0] == 1)wait_all(args[i]); } } } if (OP_diags>2) { printf(" kernel routine with indirection: adt_calc \n"); } // get plan #ifdef OP_PART_SIZE_1 int part_size = OP_PART_SIZE_1; #else int part_size = OP_part_size; #endif op_plan *Plan = op_plan_get(name,set,part_size,nargs,args,ninds,inds); // initialise timers double cpu_t1, cpu_t2, wall_t1, wall_t2; op_timers(&cpu_t1, &wall_t1); // set number of threads #ifdef _OPENMP int nthreads = omp_get_max_threads( ); #else int nthreads = 1; #endif // execute plan int block_offset = 0; for (int col=0; col < Plan->ncolors; col++) { int nblocks = Plan->ncolblk[col]; #pragma omp parallel for for (int blockIdx=0; blockIdx<nblocks; blockIdx++) op_x86_adt_calc( blockIdx, (double *)arg0.data, Plan->ind_maps[0], Plan->loc_maps[0], Plan->loc_maps[1], Plan->loc_maps[2], Plan->loc_maps[3], (double *)arg4.data, (double *)arg5.data, Plan->ind_sizes, Plan->ind_offs, block_offset, Plan->blkmap, Plan->offset, Plan->nelems, Plan->nthrcol, Plan->thrcol); block_offset += nblocks; } //set dirty bit on direct/indirect datasets with access OP_INC,OP_WRITE, OP_RW for(int i = 0; i<nargs; i++) if(args[i].argtype == OP_ARG_DAT) set_dirtybit(args[i]); //performe any global operations // - NONE // update kernel record op_timers(&cpu_t2, &wall_t2); op_timing_realloc(1); OP_kernels[1].name = name; OP_kernels[1].count += 1; OP_kernels[1].time += wall_t2 - wall_t1; OP_kernels[1].transfer += Plan->transfer; OP_kernels[1].transfer2 += Plan->transfer2; }
int cmd_grep(int argc, const char **argv, const char *prefix) { int hit = 0; int cached = 0, untracked = 0, opt_exclude = -1; int seen_dashdash = 0; int external_grep_allowed__ignored; const char *show_in_pager = NULL, *default_pager = "dummy"; struct grep_opt opt; struct object_array list = OBJECT_ARRAY_INIT; struct pathspec pathspec; struct string_list path_list = STRING_LIST_INIT_NODUP; int i; int dummy; int use_index = 1; int pattern_type_arg = GREP_PATTERN_TYPE_UNSPECIFIED; int allow_revs; struct option options[] = { OPT_BOOL(0, "cached", &cached, N_("search in index instead of in the work tree")), OPT_NEGBIT(0, "no-index", &use_index, N_("find in contents not managed by git"), 1), OPT_BOOL(0, "untracked", &untracked, N_("search in both tracked and untracked files")), OPT_SET_INT(0, "exclude-standard", &opt_exclude, N_("ignore files specified via '.gitignore'"), 1), OPT_BOOL(0, "recurse-submodules", &recurse_submodules, N_("recursively search in each submodule")), OPT_GROUP(""), OPT_BOOL('v', "invert-match", &opt.invert, N_("show non-matching lines")), OPT_BOOL('i', "ignore-case", &opt.ignore_case, N_("case insensitive matching")), OPT_BOOL('w', "word-regexp", &opt.word_regexp, N_("match patterns only at word boundaries")), OPT_SET_INT('a', "text", &opt.binary, N_("process binary files as text"), GREP_BINARY_TEXT), OPT_SET_INT('I', NULL, &opt.binary, N_("don't match patterns in binary files"), GREP_BINARY_NOMATCH), OPT_BOOL(0, "textconv", &opt.allow_textconv, N_("process binary files with textconv filters")), { OPTION_INTEGER, 0, "max-depth", &opt.max_depth, N_("depth"), N_("descend at most <depth> levels"), PARSE_OPT_NONEG, NULL, 1 }, OPT_GROUP(""), OPT_SET_INT('E', "extended-regexp", &pattern_type_arg, N_("use extended POSIX regular expressions"), GREP_PATTERN_TYPE_ERE), OPT_SET_INT('G', "basic-regexp", &pattern_type_arg, N_("use basic POSIX regular expressions (default)"), GREP_PATTERN_TYPE_BRE), OPT_SET_INT('F', "fixed-strings", &pattern_type_arg, N_("interpret patterns as fixed strings"), GREP_PATTERN_TYPE_FIXED), OPT_SET_INT('P', "perl-regexp", &pattern_type_arg, N_("use Perl-compatible regular expressions"), GREP_PATTERN_TYPE_PCRE), OPT_GROUP(""), OPT_BOOL('n', "line-number", &opt.linenum, N_("show line numbers")), OPT_NEGBIT('h', NULL, &opt.pathname, N_("don't show filenames"), 1), OPT_BIT('H', NULL, &opt.pathname, N_("show filenames"), 1), OPT_NEGBIT(0, "full-name", &opt.relative, N_("show filenames relative to top directory"), 1), OPT_BOOL('l', "files-with-matches", &opt.name_only, N_("show only filenames instead of matching lines")), OPT_BOOL(0, "name-only", &opt.name_only, N_("synonym for --files-with-matches")), OPT_BOOL('L', "files-without-match", &opt.unmatch_name_only, N_("show only the names of files without match")), OPT_BOOL('z', "null", &opt.null_following_name, N_("print NUL after filenames")), OPT_BOOL('c', "count", &opt.count, N_("show the number of matches instead of matching lines")), OPT__COLOR(&opt.color, N_("highlight matches")), OPT_BOOL(0, "break", &opt.file_break, N_("print empty line between matches from different files")), OPT_BOOL(0, "heading", &opt.heading, N_("show filename only once above matches from same file")), OPT_GROUP(""), OPT_CALLBACK('C', "context", &opt, N_("n"), N_("show <n> context lines before and after matches"), context_callback), OPT_INTEGER('B', "before-context", &opt.pre_context, N_("show <n> context lines before matches")), OPT_INTEGER('A', "after-context", &opt.post_context, N_("show <n> context lines after matches")), OPT_INTEGER(0, "threads", &num_threads, N_("use <n> worker threads")), OPT_NUMBER_CALLBACK(&opt, N_("shortcut for -C NUM"), context_callback), OPT_BOOL('p', "show-function", &opt.funcname, N_("show a line with the function name before matches")), OPT_BOOL('W', "function-context", &opt.funcbody, N_("show the surrounding function")), OPT_GROUP(""), OPT_CALLBACK('f', NULL, &opt, N_("file"), N_("read patterns from file"), file_callback), { OPTION_CALLBACK, 'e', NULL, &opt, N_("pattern"), N_("match <pattern>"), PARSE_OPT_NONEG, pattern_callback }, { OPTION_CALLBACK, 0, "and", &opt, NULL, N_("combine patterns specified with -e"), PARSE_OPT_NOARG | PARSE_OPT_NONEG, and_callback }, OPT_BOOL(0, "or", &dummy, ""), { OPTION_CALLBACK, 0, "not", &opt, NULL, "", PARSE_OPT_NOARG | PARSE_OPT_NONEG, not_callback }, { OPTION_CALLBACK, '(', NULL, &opt, NULL, "", PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_NODASH, open_callback }, { OPTION_CALLBACK, ')', NULL, &opt, NULL, "", PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_NODASH, close_callback }, OPT__QUIET(&opt.status_only, N_("indicate hit with exit status without output")), OPT_BOOL(0, "all-match", &opt.all_match, N_("show only matches from files that match all patterns")), { OPTION_SET_INT, 0, "debug", &opt.debug, NULL, N_("show parse tree for grep expression"), PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1 }, OPT_GROUP(""), { OPTION_STRING, 'O', "open-files-in-pager", &show_in_pager, N_("pager"), N_("show matching files in the pager"), PARSE_OPT_OPTARG, NULL, (intptr_t)default_pager }, OPT_BOOL(0, "ext-grep", &external_grep_allowed__ignored, N_("allow calling of grep(1) (ignored by this build)")), OPT_END() }; init_grep_defaults(); git_config(grep_cmd_config, NULL); grep_init(&opt, prefix); /* * If there is no -- then the paths must exist in the working * tree. If there is no explicit pattern specified with -e or * -f, we take the first unrecognized non option to be the * pattern, but then what follows it must be zero or more * valid refs up to the -- (if exists), and then existing * paths. If there is an explicit pattern, then the first * unrecognized non option is the beginning of the refs list * that continues up to the -- (if exists), and then paths. */ argc = parse_options(argc, argv, prefix, options, grep_usage, PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_STOP_AT_NON_OPTION); grep_commit_pattern_type(pattern_type_arg, &opt); if (use_index && !startup_info->have_repository) { int fallback = 0; git_config_get_bool("grep.fallbacktonoindex", &fallback); if (fallback) use_index = 0; else /* die the same way as if we did it at the beginning */ setup_git_directory(); } /* * skip a -- separator; we know it cannot be * separating revisions from pathnames if * we haven't even had any patterns yet */ if (argc > 0 && !opt.pattern_list && !strcmp(argv[0], "--")) { argv++; argc--; } /* First unrecognized non-option token */ if (argc > 0 && !opt.pattern_list) { append_grep_pattern(&opt, argv[0], "command line", 0, GREP_PATTERN); argv++; argc--; } if (show_in_pager == default_pager) show_in_pager = git_pager(1); if (show_in_pager) { opt.color = 0; opt.name_only = 1; opt.null_following_name = 1; opt.output_priv = &path_list; opt.output = append_path; string_list_append(&path_list, show_in_pager); } if (!opt.pattern_list) die(_("no pattern given.")); /* * We have to find "--" in a separate pass, because its presence * influences how we will parse arguments that come before it. */ for (i = 0; i < argc; i++) { if (!strcmp(argv[i], "--")) { seen_dashdash = 1; break; } } /* * Resolve any rev arguments. If we have a dashdash, then everything up * to it must resolve as a rev. If not, then we stop at the first * non-rev and assume everything else is a path. */ allow_revs = use_index && !untracked; for (i = 0; i < argc; i++) { const char *arg = argv[i]; struct object_id oid; struct object_context oc; struct object *object; if (!strcmp(arg, "--")) { i++; break; } if (!allow_revs) { if (seen_dashdash) die(_("--no-index or --untracked cannot be used with revs")); break; } if (get_oid_with_context(arg, GET_OID_RECORD_PATH, &oid, &oc)) { if (seen_dashdash) die(_("unable to resolve revision: %s"), arg); break; } object = parse_object_or_die(&oid, arg); if (!seen_dashdash) verify_non_filename(prefix, arg); add_object_array_with_path(object, arg, &list, oc.mode, oc.path); free(oc.path); } /* * Anything left over is presumed to be a path. But in the non-dashdash * "do what I mean" case, we verify and complain when that isn't true. */ if (!seen_dashdash) { int j; for (j = i; j < argc; j++) verify_filename(prefix, argv[j], j == i && allow_revs); } parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD | (opt.max_depth != -1 ? PATHSPEC_MAXDEPTH_VALID : 0), prefix, argv + i); pathspec.max_depth = opt.max_depth; pathspec.recursive = 1; pathspec.recurse_submodules = !!recurse_submodules; #ifndef NO_PTHREADS if (list.nr || cached || show_in_pager) num_threads = 0; else if (num_threads == 0) num_threads = GREP_NUM_THREADS_DEFAULT; else if (num_threads < 0) die(_("invalid number of threads specified (%d)"), num_threads); if (num_threads == 1) num_threads = 0; #else if (num_threads) warning(_("no threads support, ignoring --threads")); num_threads = 0; #endif if (!num_threads) /* * The compiled patterns on the main path are only * used when not using threading. Otherwise * start_threads() below calls compile_grep_patterns() * for each thread. */ compile_grep_patterns(&opt); #ifndef NO_PTHREADS if (num_threads) { if (!(opt.name_only || opt.unmatch_name_only || opt.count) && (opt.pre_context || opt.post_context || opt.file_break || opt.funcbody)) skip_first_line = 1; start_threads(&opt); } #endif if (show_in_pager && (cached || list.nr)) die(_("--open-files-in-pager only works on the worktree")); if (show_in_pager && opt.pattern_list && !opt.pattern_list->next) { const char *pager = path_list.items[0].string; int len = strlen(pager); if (len > 4 && is_dir_sep(pager[len - 5])) pager += len - 4; if (opt.ignore_case && !strcmp("less", pager)) string_list_append(&path_list, "-I"); if (!strcmp("less", pager) || !strcmp("vi", pager)) { struct strbuf buf = STRBUF_INIT; strbuf_addf(&buf, "+/%s%s", strcmp("less", pager) ? "" : "*", opt.pattern_list->pattern); string_list_append(&path_list, buf.buf); strbuf_detach(&buf, NULL); } } if (recurse_submodules && (!use_index || untracked)) die(_("option not supported with --recurse-submodules.")); if (!show_in_pager && !opt.status_only) setup_pager(); if (!use_index && (untracked || cached)) die(_("--cached or --untracked cannot be used with --no-index.")); if (!use_index || untracked) { int use_exclude = (opt_exclude < 0) ? use_index : !!opt_exclude; hit = grep_directory(&opt, &pathspec, use_exclude, use_index); } else if (0 <= opt_exclude) { die(_("--[no-]exclude-standard cannot be used for tracked contents.")); } else if (!list.nr) { if (!cached) setup_work_tree(); hit = grep_cache(&opt, the_repository, &pathspec, cached); } else { if (cached) die(_("both --cached and trees are given.")); hit = grep_objects(&opt, &pathspec, the_repository, &list); } if (num_threads) hit |= wait_all(); if (hit && show_in_pager) run_pager(&opt, prefix); clear_pathspec(&pathspec); free_grep_patterns(&opt); return !hit; }
void Syncer::terminate() { storage->terminate(); wait_all(); }
int cmd_wait(tok_t arg[]) { wait_all(); return 1; }
void EstimatorManager::collectBlockAverages(int num_threads) { #if defined(DEBUG_ESTIMATOR_ARCHIVE) if(DebugArchive) { if(CompEstimators) CompEstimators->print(*DebugArchive); *DebugArchive << setw(10) << RecordCount; for(int j=0; j<AverageCache.size(); j++) *DebugArchive << setw(16) << AverageCache[j]; for(int j=0; j<PropertyCache.size(); j++) *DebugArchive << setw(16) << PropertyCache[j]; *DebugArchive << endl; } #endif if(Options[COLLECT]) { //copy cached data to RemoteData[0] BufferType::iterator cur(RemoteData[0]->begin()); std::copy(AverageCache.begin(),AverageCache.end(),cur); cur+=AverageCache.size(); std::copy(PropertyCache.begin(),PropertyCache.end(),cur); cur+=PropertyCache.size(); if(CompEstimators) CompEstimators->putMessage(cur); #if defined(QMC_ASYNC_COLLECT) if(Options[MANAGE]) { //wait all the message but we can choose to wait one-by-one with a timer wait_all(myRequest.size(),&myRequest[0]); for(int is=1; is<myComm->size(); is++) accumulate_elements(RemoteData[is]->begin(),RemoteData[is]->end(), RemoteData[0]->begin()); } else //not a master, pack and send the data myRequest[0]=myComm->isend(0,myComm->rank(),*RemoteData[0]); #else myComm->reduce(*RemoteData[0]); #endif if(Options[MANAGE]) { int n1=AverageCache.size(); int n2=AverageCache.size()+PropertyCache.size(); std::copy(RemoteData[0]->begin(),RemoteData[0]->begin()+n1, AverageCache.begin()); std::copy(RemoteData[0]->begin()+n1,RemoteData[0]->begin()+n2, PropertyCache.begin()); if(CompEstimators) CompEstimators->getMessage(RemoteData[0]->begin()+n2); RealType nth=1.0/static_cast<RealType>(myComm->size()); AverageCache *= nth; //do not weight weightInd for(int i=1; i<PropertyCache.size(); i++) PropertyCache[i] *= nth; } } //add the block average to summarize energyAccumulator(AverageCache[0]); if(num_threads==1) varAccumulator(MainEstimator->variance()); if(Archive) { *Archive << setw(10) << RecordCount; for(int j=0; j<AverageCache.size(); j++) *Archive << setw(16) << AverageCache[j]; for(int j=0; j<PropertyCache.size(); j++) *Archive << setw(16) << PropertyCache[j]; *Archive << endl; if(CompEstimators) CompEstimators->recordBlock(); } RecordCount++; }
int main(int argc, char *argv[]) { int i; int status = 0; int interactive = 0; char *oldpath = getenv("PATH"); const char *fstab; #ifdef ENABLE_NLS setlocale(LC_MESSAGES, ""); bindtextdomain(NLS_CAT_NAME, LOCALEDIR); textdomain(NLS_CAT_NAME); #endif PRS(argc, argv); if (!notitle) printf("fsck %s (%s)\n", E2FSPROGS_VERSION, E2FSPROGS_DATE); fstab = getenv("FSTAB_FILE"); if (!fstab) fstab = _PATH_MNTTAB; load_fs_info(fstab); /* Update our search path to include uncommon directories. */ if (oldpath) { fsck_path = malloc (strlen (fsck_prefix_path) + 1 + strlen (oldpath) + 1); strcpy (fsck_path, fsck_prefix_path); strcat (fsck_path, ":"); strcat (fsck_path, oldpath); } else { fsck_path = string_copy(fsck_prefix_path); } if ((num_devices == 1) || (serialize)) interactive = 1; /* If -A was specified ("check all"), do that! */ if (doall) return check_all(); if (num_devices == 0) { fprintf(stderr, _("\nNo devices specified to be checked!\n")); exit(EXIT_ERROR); } for (i = 0 ; i < num_devices; i++) { fsck_device(devices[i], interactive); if (serialize) { struct fsck_instance *inst; inst = wait_one(); if (inst) { status |= inst->exit_status; free_instance(inst); } } } status |= wait_all(); free(fsck_path); return status; }
int cmd_grep(int argc, const char **argv, const char *prefix) { int hit = 0; int cached = 0; int seen_dashdash = 0; int external_grep_allowed__ignored; struct grep_opt opt; struct object_array list = { 0, 0, NULL }; const char **paths = NULL; int i; int dummy; int nongit = 0, use_index = 1; struct option options[] = { OPT_BOOLEAN(0, "cached", &cached, "search in index instead of in the work tree"), OPT_BOOLEAN(0, "index", &use_index, "--no-index finds in contents not managed by git"), OPT_GROUP(""), OPT_BOOLEAN('v', "invert-match", &opt.invert, "show non-matching lines"), OPT_BOOLEAN('i', "ignore-case", &opt.ignore_case, "case insensitive matching"), OPT_BOOLEAN('w', "word-regexp", &opt.word_regexp, "match patterns only at word boundaries"), OPT_SET_INT('a', "text", &opt.binary, "process binary files as text", GREP_BINARY_TEXT), OPT_SET_INT('I', NULL, &opt.binary, "don't match patterns in binary files", GREP_BINARY_NOMATCH), { OPTION_INTEGER, 0, "max-depth", &opt.max_depth, "depth", "descend at most <depth> levels", PARSE_OPT_NONEG, NULL, 1 }, OPT_GROUP(""), OPT_BIT('E', "extended-regexp", &opt.regflags, "use extended POSIX regular expressions", REG_EXTENDED), OPT_NEGBIT('G', "basic-regexp", &opt.regflags, "use basic POSIX regular expressions (default)", REG_EXTENDED), OPT_BOOLEAN('F', "fixed-strings", &opt.fixed, "interpret patterns as fixed strings"), OPT_GROUP(""), OPT_BOOLEAN('n', NULL, &opt.linenum, "show line numbers"), OPT_NEGBIT('h', NULL, &opt.pathname, "don't show filenames", 1), OPT_BIT('H', NULL, &opt.pathname, "show filenames", 1), OPT_NEGBIT(0, "full-name", &opt.relative, "show filenames relative to top directory", 1), OPT_BOOLEAN('l', "files-with-matches", &opt.name_only, "show only filenames instead of matching lines"), OPT_BOOLEAN(0, "name-only", &opt.name_only, "synonym for --files-with-matches"), OPT_BOOLEAN('L', "files-without-match", &opt.unmatch_name_only, "show only the names of files without match"), OPT_BOOLEAN('z', "null", &opt.null_following_name, "print NUL after filenames"), OPT_BOOLEAN('c', "count", &opt.count, "show the number of matches instead of matching lines"), OPT_SET_INT(0, "color", &opt.color, "highlight matches", 1), OPT_GROUP(""), OPT_CALLBACK('C', NULL, &opt, "n", "show <n> context lines before and after matches", context_callback), OPT_INTEGER('B', NULL, &opt.pre_context, "show <n> context lines before matches"), OPT_INTEGER('A', NULL, &opt.post_context, "show <n> context lines after matches"), OPT_NUMBER_CALLBACK(&opt, "shortcut for -C NUM", context_callback), OPT_BOOLEAN('p', "show-function", &opt.funcname, "show a line with the function name before matches"), OPT_GROUP(""), OPT_CALLBACK('f', NULL, &opt, "file", "read patterns from file", file_callback), { OPTION_CALLBACK, 'e', NULL, &opt, "pattern", "match <pattern>", PARSE_OPT_NONEG, pattern_callback }, { OPTION_CALLBACK, 0, "and", &opt, NULL, "combine patterns specified with -e", PARSE_OPT_NOARG | PARSE_OPT_NONEG, and_callback }, OPT_BOOLEAN(0, "or", &dummy, ""), { OPTION_CALLBACK, 0, "not", &opt, NULL, "", PARSE_OPT_NOARG | PARSE_OPT_NONEG, not_callback }, { OPTION_CALLBACK, '(', NULL, &opt, NULL, "", PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_NODASH, open_callback }, { OPTION_CALLBACK, ')', NULL, &opt, NULL, "", PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_NODASH, close_callback }, OPT_BOOLEAN('q', "quiet", &opt.status_only, "indicate hit with exit status without output"), OPT_BOOLEAN(0, "all-match", &opt.all_match, "show only matches from files that match all patterns"), OPT_GROUP(""), OPT_BOOLEAN(0, "ext-grep", &external_grep_allowed__ignored, "allow calling of grep(1) (ignored by this build)"), { OPTION_CALLBACK, 0, "help-all", &options, NULL, "show usage", PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, help_callback }, OPT_END() }; prefix = setup_git_directory_gently(&nongit); /* * 'git grep -h', unlike 'git grep -h <pattern>', is a request * to show usage information and exit. */ if (argc == 2 && !strcmp(argv[1], "-h")) usage_with_options(grep_usage, options); memset(&opt, 0, sizeof(opt)); opt.prefix = prefix; opt.prefix_length = (prefix && *prefix) ? strlen(prefix) : 0; opt.relative = 1; opt.pathname = 1; opt.pattern_tail = &opt.pattern_list; opt.regflags = REG_NEWLINE; opt.max_depth = -1; strcpy(opt.color_match, GIT_COLOR_RED GIT_COLOR_BOLD); opt.color = -1; git_config(grep_config, &opt); if (opt.color == -1) opt.color = git_use_color_default; /* * If there is no -- then the paths must exist in the working * tree. If there is no explicit pattern specified with -e or * -f, we take the first unrecognized non option to be the * pattern, but then what follows it must be zero or more * valid refs up to the -- (if exists), and then existing * paths. If there is an explicit pattern, then the first * unrecognized non option is the beginning of the refs list * that continues up to the -- (if exists), and then paths. */ argc = parse_options(argc, argv, prefix, options, grep_usage, PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_STOP_AT_NON_OPTION | PARSE_OPT_NO_INTERNAL_HELP); if (use_index && nongit) /* die the same way as if we did it at the beginning */ setup_git_directory(); /* * skip a -- separator; we know it cannot be * separating revisions from pathnames if * we haven't even had any patterns yet */ if (argc > 0 && !opt.pattern_list && !strcmp(argv[0], "--")) { argv++; argc--; } /* First unrecognized non-option token */ if (argc > 0 && !opt.pattern_list) { append_grep_pattern(&opt, argv[0], "command line", 0, GREP_PATTERN); argv++; argc--; } if (!opt.pattern_list) die("no pattern given."); if (!opt.fixed && opt.ignore_case) opt.regflags |= REG_ICASE; if ((opt.regflags != REG_NEWLINE) && opt.fixed) die("cannot mix --fixed-strings and regexp"); #ifndef NO_PTHREADS if (online_cpus() == 1 || !grep_threads_ok(&opt)) use_threads = 0; if (use_threads) start_threads(&opt); #else use_threads = 0; #endif compile_grep_patterns(&opt); /* Check revs and then paths */ for (i = 0; i < argc; i++) { const char *arg = argv[i]; unsigned char sha1[20]; /* Is it a rev? */ if (!get_sha1(arg, sha1)) { struct object *object = parse_object(sha1); if (!object) die("bad object %s", arg); add_object_array(object, arg, &list); continue; } if (!strcmp(arg, "--")) { i++; seen_dashdash = 1; } break; } /* The rest are paths */ if (!seen_dashdash) { int j; for (j = i; j < argc; j++) verify_filename(prefix, argv[j]); } if (i < argc) paths = get_pathspec(prefix, argv + i); else if (prefix) { paths = xcalloc(2, sizeof(const char *)); paths[0] = prefix; paths[1] = NULL; } if (!use_index) { int hit; if (cached) die("--cached cannot be used with --no-index."); if (list.nr) die("--no-index cannot be used with revs."); hit = grep_directory(&opt, paths); if (use_threads) hit |= wait_all(); return !hit; } if (!list.nr) { int hit; if (!cached) setup_work_tree(); hit = grep_cache(&opt, paths, cached); if (use_threads) hit |= wait_all(); return !hit; } if (cached) die("both --cached and trees are given."); for (i = 0; i < list.nr; i++) { struct object *real_obj; real_obj = deref_tag(list.objects[i].item, NULL, 0); if (grep_object(&opt, paths, real_obj, list.objects[i].name)) { hit = 1; if (opt.status_only) break; } } if (use_threads) hit |= wait_all(); free_grep_patterns(&opt); return !hit; }
/* Check all file systems, using the /etc/fstab table. */ static int check_all(NOARGS) { struct fs_info *fs = NULL; struct fsck_instance *inst; int status = EXIT_OK; int not_done_yet = 1; int passno = 1; int pass_done; if (verbose) printf(_("Checking all file systems.\n")); /* * Do an initial scan over the filesystem; mark filesystems * which should be ignored as done, and resolve LABEL= and * UUID= specifications to the real device. */ for (fs = filesys_info; fs; fs = fs->next) { if (ignore(fs)) fs->flags |= FLAG_DONE; else fs->device = interpret_device(fs->device); } /* * Find and check the root filesystem. */ if (!parallel_root) { for (fs = filesys_info; fs; fs = fs->next) { if (!strcmp(fs->mountpt, "/")) break; } if (fs) { if (!skip_root && !ignore(fs)) { fsck_device(fs->device, 1); status |= wait_all(); if (status > EXIT_NONDESTRUCT) return status; } fs->flags |= FLAG_DONE; } } while (not_done_yet) { not_done_yet = 0; pass_done = 1; for (fs = filesys_info; fs; fs = fs->next) { if (fs->flags & FLAG_DONE) continue; /* * If the filesystem's pass number is higher * than the current pass number, then we don't * do it yet. */ if (fs->passno > passno) { not_done_yet++; continue; } /* * If a filesystem on a particular device has * already been spawned, then we need to defer * this to another pass. */ if (device_already_active(fs->device)) { pass_done = 0; continue; } /* * Spawn off the fsck process */ fsck_device(fs->device, serialize); fs->flags |= FLAG_DONE; if (serialize) { pass_done = 0; break; /* Only do one filesystem at a time */ } } if (verbose > 1) printf(_("--waiting-- (pass %d)\n"), passno); inst = wait_one(); if (inst) { status |= inst->exit_status; free_instance(inst); } if (pass_done) { status |= wait_all(); if (verbose > 1) printf("----------------------------------\n"); passno++; } else not_done_yet++; } status |= wait_all(); return status; }
void op_par_loop_res_calc(char const *name, op_set set, op_arg arg0, op_arg arg1, op_arg arg2, op_arg arg3, op_arg arg4, op_arg arg5, op_arg arg6, op_arg arg7 ){ int nargs = 8; op_arg args[8] = {arg0,arg1,arg2,arg3,arg4,arg5,arg6,arg7}; int ninds = 4; int inds[8] = {0,0,1,1,2,2,3,3}; int sent[8] = {0,0,0,0,0,0,0,0}; //array to set if halo is exchanged if(ninds > 0) //indirect loop { for(int i = 0; i<nargs; i++) { if(args[i].argtype == OP_ARG_DAT) { if (OP_diags==1) reset_halo(args[i]); sent[i] = exchange_halo(args[i]); //if(sent[i] == 1)wait_all(args[i]); } } } if (OP_diags>2) { printf(" kernel routine with indirection: res_calc \n"); } // get plan int block_offset; op_plan *Plan; #ifdef OP_PART_SIZE_2 int part_size = OP_PART_SIZE_2; #else int part_size = OP_part_size; #endif //get offsets int core_len = core_num[set->index]; int noncore_len = set->size + OP_import_exec_list[set->index]->size - core_len; double cpu_t1, cpu_t2, wall_t1, wall_t2; //process core set if (core_len>0) { if (OP_latency_sets[set->index].core_set == NULL) { op_set core_set = (op_set)malloc(sizeof(op_set_core)); core_set->index = set->index; core_set->name = set->name; core_set->size = core_len; core_set->exec_size = 0; core_set->nonexec_size = 0; OP_latency_sets[set->index].core_set = core_set; } Plan = op_plan_get_offset(name,OP_latency_sets[set->index].core_set, 0,part_size,nargs,args,ninds,inds); op_timers_core(&cpu_t1, &wall_t1); // set number of threads #ifdef _OPENMP int nthreads = omp_get_max_threads( ); #else int nthreads = 1; #endif // execute plan int block_offset = 0; for(int col=0; col < Plan->ncolors; col++) { int nblocks = Plan->ncolblk[col]; #pragma omp parallel for for (int blockIdx=0; blockIdx<nblocks; blockIdx++) op_x86_res_calc( blockIdx, (double *)arg0.data, Plan->ind_maps[0], (double *)arg2.data, Plan->ind_maps[1], (double *)arg4.data, Plan->ind_maps[2], (double *)arg6.data, Plan->ind_maps[3], Plan->loc_maps[0], Plan->loc_maps[1], Plan->loc_maps[2], Plan->loc_maps[3], Plan->loc_maps[4], Plan->loc_maps[5], Plan->loc_maps[6], Plan->loc_maps[7], Plan->ind_sizes, Plan->ind_offs, block_offset, Plan->blkmap, Plan->offset, Plan->nelems, Plan->nthrcol, Plan->thrcol); block_offset += nblocks; } op_timers_core(&cpu_t2, &wall_t2); OP_kernels[2].time += wall_t2 - wall_t1; OP_kernels[2].transfer += Plan->transfer; OP_kernels[2].transfer2 += Plan->transfer2; } if(ninds > 0) //indirect loop { for(int i = 0; i<nargs; i++) { if(args[i].argtype == OP_ARG_DAT) { if(sent[i] == 1)wait_all(args[i]); } } } if (noncore_len>0) { if (OP_latency_sets[set->index].noncore_set == NULL) { op_set noncore_set = (op_set)malloc(sizeof (op_set_core)); noncore_set->size = noncore_len; noncore_set->name = set->name; noncore_set->index = set->index; noncore_set->exec_size = 0; noncore_set->nonexec_size = 0; OP_latency_sets[set->index].noncore_set = noncore_set; } Plan = op_plan_get_offset(name,OP_latency_sets[set->index].noncore_set,core_len, part_size,nargs,args,ninds,inds); op_timers_core(&cpu_t1, &wall_t1); // set number of threads #ifdef _OPENMP int nthreads = omp_get_max_threads( ); #else int nthreads = 1; #endif // execute plan int block_offset = 0; for (int col=0; col < Plan->ncolors; col++) { int nblocks = Plan->ncolblk[col]; #pragma omp parallel for for (int blockIdx=0; blockIdx<nblocks; blockIdx++) op_x86_res_calc( blockIdx, (double *)arg0.data, Plan->ind_maps[0], (double *)arg2.data, Plan->ind_maps[1], (double *)arg4.data, Plan->ind_maps[2], (double *)arg6.data, Plan->ind_maps[3], Plan->loc_maps[0], Plan->loc_maps[1], Plan->loc_maps[2], Plan->loc_maps[3], Plan->loc_maps[4], Plan->loc_maps[5], Plan->loc_maps[6], Plan->loc_maps[7], Plan->ind_sizes, Plan->ind_offs, block_offset, Plan->blkmap, Plan->offset, Plan->nelems, Plan->nthrcol, Plan->thrcol); block_offset += nblocks; } op_timers_core(&cpu_t2, &wall_t2); OP_kernels[2].time += wall_t2 - wall_t1; OP_kernels[2].transfer += Plan->transfer; OP_kernels[2].transfer2 += Plan->transfer2; } //set dirty bit on direct/indirect datasets with access OP_INC,OP_WRITE, OP_RW for(int i = 0; i<nargs; i++) if(args[i].argtype == OP_ARG_DAT) set_dirtybit(args[i]); //performe any global operations // - NONE // update kernel record op_timing_realloc(3); OP_kernels[2].name = name; OP_kernels[2].count += 1; }
int cmd_grep(int argc, const char **argv, const char *prefix) { int hit = 0; int cached = 0, untracked = 0, opt_exclude = -1; int seen_dashdash = 0; int external_grep_allowed__ignored; const char *show_in_pager = NULL, *default_pager = "dummy"; struct grep_opt opt; struct object_array list = OBJECT_ARRAY_INIT; const char **paths = NULL; struct pathspec pathspec; struct string_list path_list = STRING_LIST_INIT_NODUP; int i; int dummy; int use_index = 1; int pattern_type_arg = GREP_PATTERN_TYPE_UNSPECIFIED; struct option options[] = { OPT_BOOLEAN(0, "cached", &cached, N_("search in index instead of in the work tree")), OPT_NEGBIT(0, "no-index", &use_index, N_("find in contents not managed by git"), 1), OPT_BOOLEAN(0, "untracked", &untracked, N_("search in both tracked and untracked files")), OPT_SET_INT(0, "exclude-standard", &opt_exclude, N_("search also in ignored files"), 1), OPT_GROUP(""), OPT_BOOLEAN('v', "invert-match", &opt.invert, N_("show non-matching lines")), OPT_BOOLEAN('i', "ignore-case", &opt.ignore_case, N_("case insensitive matching")), OPT_BOOLEAN('w', "word-regexp", &opt.word_regexp, N_("match patterns only at word boundaries")), OPT_SET_INT('a', "text", &opt.binary, N_("process binary files as text"), GREP_BINARY_TEXT), OPT_SET_INT('I', NULL, &opt.binary, N_("don't match patterns in binary files"), GREP_BINARY_NOMATCH), { OPTION_INTEGER, 0, "max-depth", &opt.max_depth, N_("depth"), N_("descend at most <depth> levels"), PARSE_OPT_NONEG, NULL, 1 }, OPT_GROUP(""), OPT_SET_INT('E', "extended-regexp", &pattern_type_arg, N_("use extended POSIX regular expressions"), GREP_PATTERN_TYPE_ERE), OPT_SET_INT('G', "basic-regexp", &pattern_type_arg, N_("use basic POSIX regular expressions (default)"), GREP_PATTERN_TYPE_BRE), OPT_SET_INT('F', "fixed-strings", &pattern_type_arg, N_("interpret patterns as fixed strings"), GREP_PATTERN_TYPE_FIXED), OPT_SET_INT('P', "perl-regexp", &pattern_type_arg, N_("use Perl-compatible regular expressions"), GREP_PATTERN_TYPE_PCRE), OPT_GROUP(""), OPT_BOOLEAN('n', "line-number", &opt.linenum, N_("show line numbers")), OPT_NEGBIT('h', NULL, &opt.pathname, N_("don't show filenames"), 1), OPT_BIT('H', NULL, &opt.pathname, N_("show filenames"), 1), OPT_NEGBIT(0, "full-name", &opt.relative, N_("show filenames relative to top directory"), 1), OPT_BOOLEAN('l', "files-with-matches", &opt.name_only, N_("show only filenames instead of matching lines")), OPT_BOOLEAN(0, "name-only", &opt.name_only, N_("synonym for --files-with-matches")), OPT_BOOLEAN('L', "files-without-match", &opt.unmatch_name_only, N_("show only the names of files without match")), OPT_BOOLEAN('z', "null", &opt.null_following_name, N_("print NUL after filenames")), OPT_BOOLEAN('c', "count", &opt.count, N_("show the number of matches instead of matching lines")), OPT__COLOR(&opt.color, N_("highlight matches")), OPT_BOOLEAN(0, "break", &opt.file_break, N_("print empty line between matches from different files")), OPT_BOOLEAN(0, "heading", &opt.heading, N_("show filename only once above matches from same file")), OPT_GROUP(""), OPT_CALLBACK('C', "context", &opt, N_("n"), N_("show <n> context lines before and after matches"), context_callback), OPT_INTEGER('B', "before-context", &opt.pre_context, N_("show <n> context lines before matches")), OPT_INTEGER('A', "after-context", &opt.post_context, N_("show <n> context lines after matches")), OPT_NUMBER_CALLBACK(&opt, N_("shortcut for -C NUM"), context_callback), OPT_BOOLEAN('p', "show-function", &opt.funcname, N_("show a line with the function name before matches")), OPT_BOOLEAN('W', "function-context", &opt.funcbody, N_("show the surrounding function")), OPT_GROUP(""), OPT_CALLBACK('f', NULL, &opt, N_("file"), N_("read patterns from file"), file_callback), { OPTION_CALLBACK, 'e', NULL, &opt, N_("pattern"), N_("match <pattern>"), PARSE_OPT_NONEG, pattern_callback }, { OPTION_CALLBACK, 0, "and", &opt, NULL, N_("combine patterns specified with -e"), PARSE_OPT_NOARG | PARSE_OPT_NONEG, and_callback }, OPT_BOOLEAN(0, "or", &dummy, ""), { OPTION_CALLBACK, 0, "not", &opt, NULL, "", PARSE_OPT_NOARG | PARSE_OPT_NONEG, not_callback }, { OPTION_CALLBACK, '(', NULL, &opt, NULL, "", PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_NODASH, open_callback }, { OPTION_CALLBACK, ')', NULL, &opt, NULL, "", PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_NODASH, close_callback }, OPT__QUIET(&opt.status_only, N_("indicate hit with exit status without output")), OPT_BOOLEAN(0, "all-match", &opt.all_match, N_("show only matches from files that match all patterns")), { OPTION_SET_INT, 0, "debug", &opt.debug, NULL, N_("show parse tree for grep expression"), PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1 }, OPT_GROUP(""), { OPTION_STRING, 'O', "open-files-in-pager", &show_in_pager, N_("pager"), N_("show matching files in the pager"), PARSE_OPT_OPTARG, NULL, (intptr_t)default_pager }, OPT_BOOLEAN(0, "ext-grep", &external_grep_allowed__ignored, N_("allow calling of grep(1) (ignored by this build)")), { OPTION_CALLBACK, 0, "help-all", &options, NULL, N_("show usage"), PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, help_callback }, OPT_END() }; /* * 'git grep -h', unlike 'git grep -h <pattern>', is a request * to show usage information and exit. */ if (argc == 2 && !strcmp(argv[1], "-h")) usage_with_options(grep_usage, options); init_grep_defaults(); git_config(grep_cmd_config, NULL); grep_init(&opt, prefix); /* * If there is no -- then the paths must exist in the working * tree. If there is no explicit pattern specified with -e or * -f, we take the first unrecognized non option to be the * pattern, but then what follows it must be zero or more * valid refs up to the -- (if exists), and then existing * paths. If there is an explicit pattern, then the first * unrecognized non option is the beginning of the refs list * that continues up to the -- (if exists), and then paths. */ argc = parse_options(argc, argv, prefix, options, grep_usage, PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_STOP_AT_NON_OPTION | PARSE_OPT_NO_INTERNAL_HELP); grep_commit_pattern_type(pattern_type_arg, &opt); if (use_index && !startup_info->have_repository) /* die the same way as if we did it at the beginning */ setup_git_directory(); /* * skip a -- separator; we know it cannot be * separating revisions from pathnames if * we haven't even had any patterns yet */ if (argc > 0 && !opt.pattern_list && !strcmp(argv[0], "--")) { argv++; argc--; } /* First unrecognized non-option token */ if (argc > 0 && !opt.pattern_list) { append_grep_pattern(&opt, argv[0], "command line", 0, GREP_PATTERN); argv++; argc--; } if (show_in_pager == default_pager) show_in_pager = git_pager(1); if (show_in_pager) { opt.color = 0; opt.name_only = 1; opt.null_following_name = 1; opt.output_priv = &path_list; opt.output = append_path; string_list_append(&path_list, show_in_pager); use_threads = 0; } if ((opt.binary & GREP_BINARY_NOMATCH)) use_threads = 0; if (!opt.pattern_list) die(_("no pattern given.")); if (!opt.fixed && opt.ignore_case) opt.regflags |= REG_ICASE; compile_grep_patterns(&opt); /* Check revs and then paths */ for (i = 0; i < argc; i++) { const char *arg = argv[i]; unsigned char sha1[20]; /* Is it a rev? */ if (!get_sha1(arg, sha1)) { struct object *object = parse_object(sha1); if (!object) die(_("bad object %s"), arg); add_object_array(object, arg, &list); continue; } if (!strcmp(arg, "--")) { i++; seen_dashdash = 1; } break; } #ifndef NO_PTHREADS if (list.nr || cached || online_cpus() == 1) use_threads = 0; #else use_threads = 0; #endif #ifndef NO_PTHREADS if (use_threads) { if (!(opt.name_only || opt.unmatch_name_only || opt.count) && (opt.pre_context || opt.post_context || opt.file_break || opt.funcbody)) skip_first_line = 1; start_threads(&opt); } #endif /* The rest are paths */ if (!seen_dashdash) { int j; for (j = i; j < argc; j++) verify_filename(prefix, argv[j], j == i); } paths = get_pathspec(prefix, argv + i); init_pathspec(&pathspec, paths); pathspec.max_depth = opt.max_depth; pathspec.recursive = 1; if (show_in_pager && (cached || list.nr)) die(_("--open-files-in-pager only works on the worktree")); if (show_in_pager && opt.pattern_list && !opt.pattern_list->next) { const char *pager = path_list.items[0].string; int len = strlen(pager); if (len > 4 && is_dir_sep(pager[len - 5])) pager += len - 4; if (opt.ignore_case && !strcmp("less", pager)) string_list_append(&path_list, "-i"); if (!strcmp("less", pager) || !strcmp("vi", pager)) { struct strbuf buf = STRBUF_INIT; strbuf_addf(&buf, "+/%s%s", strcmp("less", pager) ? "" : "*", opt.pattern_list->pattern); string_list_append(&path_list, buf.buf); strbuf_detach(&buf, NULL); } } if (!show_in_pager) setup_pager(); if (!use_index && (untracked || cached)) die(_("--cached or --untracked cannot be used with --no-index.")); if (!use_index || untracked) { int use_exclude = (opt_exclude < 0) ? use_index : !!opt_exclude; if (list.nr) die(_("--no-index or --untracked cannot be used with revs.")); hit = grep_directory(&opt, &pathspec, use_exclude); } else if (0 <= opt_exclude) { die(_("--[no-]exclude-standard cannot be used for tracked contents.")); } else if (!list.nr) { if (!cached) setup_work_tree(); hit = grep_cache(&opt, &pathspec, cached); } else { if (cached) die(_("both --cached and trees are given.")); hit = grep_objects(&opt, &pathspec, &list); } if (use_threads) hit |= wait_all(); if (hit && show_in_pager) run_pager(&opt, prefix); free_grep_patterns(&opt); return !hit; }
int main() { int i, j; int pidf,id_wait; void dt_shareG(); mc_var_inic (); def_task (0, "multiplicarAB", sizeof (__multiplicarAB__)); def_task (1, "multiplicarCD", sizeof (__multiplicarCD__)); def_task (2, "sumar", sizeof (__sumar__)); def_task (3, "print", sizeof (__print__)); id_wait=sem_wait_inic(4); for (i=0; i<100; i++){ for (j = 0; j < 100; j++) { /*A[i][j] = i + j; B[i][j] = i + 2*j; C[i][j] = i*2 + j*3; D[i][j] = i*2 + j;*/ sharedG->A[i][j] = 1; sharedG->B[i][j] = 1; sharedG->C[i][j] = 1; sharedG->D[i][j] = 1; } } alloc_proc(4); pidf = exec_task (0, 1); /* --- rs30() - create --- */ if (pidf == 0) { multiplicarAB(); end_task(); /* --- rs31() - create --- */ } pidf = exec_task (1, 1); /* --- rs30() - create --- */ if (pidf == 0) { multiplicarCD(); end_task(); /* --- rs31() - create --- */ } wait_all(); pidf = exec_task (2, 1); /* --- rs30() - create --- */ if (pidf == 0) { sumar(); end_task(); /* --- rs31() - create --- */ } wait_proc (2); /* --- wait_proc() --- */ pidf = exec_task (3, 1); /* --- rs30() - create --- */ if (pidf == 0) { print(); end_task(); /* --- rs31() - create --- */ } wait_all(); /* --- rs307() */ end_program(); remove_semaforo(id_wait); return 0; }