Exemplo n.º 1
0
// manual iterations
void RunExplicit()
{
  Work(&List[0]);
  Work(&List[1]);
  Work(&List[2]);
  Work(&List[3]);
  Work(&List[4]);
}
Exemplo n.º 2
0
	void solve(void) {
		Input();
		int Ans = 0;
		for (int i = 1; i <= k; i++)
			Ans += Work();
		printf("%d\n", (n - 1) * 2 - Ans + k);
	}
Exemplo n.º 3
0
	void WorkerThread::Run(Thread*, void*)
	{
		// set the thread-local-storage pointer to "this"
		LocalWorkerThread_ = this;
		//ThisThread_.reset( (const_cast<Worker *>(this)) ); // TODO: Fix this.

		// infinitely loop
		for(;;)
		{
			// go idle
			Idle();

			// check to see if the pool wants to exit
			//	- if so, break out of the loop
			if( Pool_->IsDone_ )
				break;

			// loop and check to see if the pool thinks there is work to be done
			while(Pool_->CurrentCompletion_ != nullptr)
			{
				// do work
				Work(nullptr);	// -> null is passed to designate that this is not a call from within a task

				// check to see if the pool wants to exit
				// - if so, break out of the loop
				if(Pool_->IsDone_)
					break;
			}
		}

		// release the thread-local-storage
		LocalWorkerThread_ = nullptr;
		//ThisThread_.release();	// TODO: Fix this.
	}
Exemplo n.º 4
0
    void do_resolve (std::vector <std::string> const& names,
        HandlerType const& handler, CompletionCounter)
    {
        check_precondition (! names.empty());

        if (m_called_stop.load () == 0)
        {
            // TODO NIKB use emplace_back once we move to C++11
            m_work.push_back(Work(names, handler));

            m_journal.debug <<
                "Queued new job with " << names.size() <<
                " tasks. " << m_work.size() << " jobs outstanding.";

            if (m_work.size() == 1)
            {
                check_precondition (m_idle);

                m_journal.trace << "Waking up";
                m_idle = false;

                m_io_service.post (m_strand.wrap (boost::bind (
                    &NameResolverImpl::do_work, this,
                    CompletionCounter(this))));
            }
        }
    }
Exemplo n.º 5
0
void solve() {
  int K;
  scanf("%d%d%d", &n, &m, &K);
  if(n == 0 && m == 0 && K == 0) exit(0);
  Init();
  Work();
}
int main(int argc, char **argv)
{
	MPI_Init(&argc, &argv);
	double start_time, end_time;

    int i;
 
	// Init default values.
    Init_Default();

	// Read arguments.
    Read_Options(argc, argv);

	// Init the matrix.
    Init_Matrix();

	// Start timer.
	start_time = MPI_Wtime();

	// Do guassian elimination.
    Work();

	// Stop timer.
	end_time = MPI_Wtime();

    if(PRINT == 1)
	{
		printf("===== AFTER GUASSIAN ELIMINATION ======\n");
		Print_Matrix();
		printf("=======================================\n\n");
	}

	double time_taken = (end_time - start_time);
	printf("Execution time: %f\n", time_taken);
}
Exemplo n.º 7
0
int main(int argc, char *argv[])
{
    setIO("sample");
    init();Work();
    closeIO();
    return EXIT_SUCCESS;
}
Exemplo n.º 8
0
int main()
{
	while (scanf("%d",&N),N)
	{
		Work();
	}
	return 0;
}
Exemplo n.º 9
0
bool CMusicLibraryJob::DoWork()
{
  CMusicDatabase db;
  if (!db.Open())
    return false;

  return Work(db);
}
Exemplo n.º 10
0
bool CVideoLibraryJob::DoWork()
{
  CVideoDatabase db;
  if (!db.Open())
    return false;

  return Work(db);
}
Exemplo n.º 11
0
	void solve(void) {
		Input();
		Cut();
		Bfs(vs[1][0], vs[1][1]);
		Work(vs[0][0], vs[0][1]);
		int t1 = tim[vt[0]][vt[1]];
		puts(t1?"YES":"NO");
	}
Exemplo n.º 12
0
main ()
{
        int     step = 0;
        while ( 1 ) {
                if ( !init() ) break;
                step ++;
                printf ( "Case %d: %d\n" , step , Work () );
        }
}
Exemplo n.º 13
0
int main()
{
  StopWatch TotalTimer;
  TotalTimer.StartTimer();
  int i = 0;
  Work(i);
  TotalTimer.StopTimer();
  std::cout << "Time_Total: " << TotalTimer.GetElapsedSeconds() << std::flush << std::endl;
}
Exemplo n.º 14
0
	inline void solve(void) {
		Input();
		if (abs(a[n] - a[1]) > (Int64) d * (n - 1)) {
			puts("impossible");
			return;
		}
		Int64 Ans = Work();
		printf("%lld\n", Ans);
	}
Exemplo n.º 15
0
// linked list iteration
void RunThoughLinkedList()
{
  node *pHead = Head;
  while(pHead != NULL)
  {
    Work(pHead);
    pHead = pHead->next;
  }
}
Exemplo n.º 16
0
int main()
{
	if (!Init())
	{
		return 0;
	}
	Work();	
	return 0;
};
Exemplo n.º 17
0
int main(int argc,char* argv[])
{
	printf("Input .."); Input(); printf("OK\n");
	int i;
//	for(i=0;i!=N;++i) print(i);
	while(Work());
	printf("Bye~\n");
	return 0;
}
Exemplo n.º 18
0
void Work(int i)
{
  if(i > 4)
    return;
  printf("S%d\n",i);
  cilk_spawn Work(i + 1);
  Delay();
  printf("E %d\n",i);
}
Exemplo n.º 19
0
int main(int argc, char** argv) {
	#ifdef Debug
		freopen("1.in", "r", stdin);
	#endif

	for(long i = 0; i <= 9; i++)
		f[1][i] = 1;
	for(long i = 2; i <= 10; i++)
		for (long j = 0; j <= 9; j++)
			for (long k = 0; k <= 9; k++)
				if( abs(k - j) >= 2)
					f[i][j] += f[i - 1][k];
	long l1, l2;
	scanf("%ld %ld", &l1, &l2);
	long A = Work(l2);
	long B = Work(l1 - 1);
	printf("%ld", abs( A - B ));
	return 0;
}
Exemplo n.º 20
0
static rc_t Run(const CmdLine* args)
{
    rc_t rc = 0;

    Db db;
    SpotIterator it;

    assert(args);

    if (!SpotIteratorFileExists(args->file)) {
        rc = RC(rcExe, rcFile, rcOpening, rcFile, rcNotFound);
        PLOGERR(klogErr,
            (klogErr, rc, "Cannot find '$(path)'", "path=%s", args->file));
    }
    else if (!SpotIteratorFileExists(args->table)) {
        rc = RC(rcExe, rcTable, rcOpening, rcTable, rcNotFound);
        PLOGERR(klogErr,
            (klogErr, rc, "Cannot find '$(path)'", "path=%s", args->table));
    }

    {
        rc_t rc2 = DbInit(rc, args, &db);
        if (rc == 0)
        {   rc = rc2; }
    }

    if (rc == 0) {
        rc = SpotIteratorInit(args->file, &db, &it);
    }

    if (rc == 0) {
        rc = Work(&db, &it);
    }

    if (rc == 0) {
        PLOGMSG(klogInfo, (klogInfo,
            "Success: redacted $(redacted) spots out of $(all)",
            "redacted=%d,all=%d", db.redactedSpots, db.nSpots));
    }

    {
        rc_t rc2 = SpotIteratorDestroy(&it);
        if (rc == 0)
        {   rc = rc2; }
    }

    {
        rc_t rc2 = DbDestroy(&db);
        if (rc == 0)
        {   rc = rc2; }
    }

    return rc;
}
Exemplo n.º 21
0
int main()
{
	
	bool bRet = Init();
	if (!bRet)
	{
		return 0;
	}
	Work();
	return 0;
};
Exemplo n.º 22
0
void Connection::ThreadStarter()
{
    log_trace();
    while (threadRunning_ && !CheckClose())
    {
        Work(100);
    }
    log_debug("Connection thread exiting, fd=" << socket_.GetFileDescriptor());
    // force the close to close since the thread may not be deleted right away
    socket_.Close();
    threadRunning_ = false;
}
Exemplo n.º 23
0
void RunThoughLinkedList()
{
  tbb::task_group g;
  node *pHead = Head;
  printf("Starting Linked List\n");
  while(pHead != NULL)
  {
    g.run([=]{Work(pHead);});
    pHead = pHead->next;
  }
  g.wait();
}
Exemplo n.º 24
0
int main()
{
    setIO("sample");
    Prime();
    for (scanf("%d",&ca);ca--;)
    {
        scanf("%d",&n);
        Work();
    }
    closeIO();
    return 0;
} 
Exemplo n.º 25
0
GLDEF_C TInt E32Main()
	{
	CActiveScheduler* shed = new(ELeave) CActiveScheduler();
	CActiveScheduler::Install(shed);
	__UHEAP_MARK;
	CTrapCleanup* cleanup = CTrapCleanup::New();
	TRAPD(error,Work());
	__ASSERT_ALWAYS(!error,SavePanic(error));
	delete cleanup;
	__UHEAP_MARKEND;
	delete shed;
	return 0;
	}
Exemplo n.º 26
0
	void WorkerThread::YieldUntil( Completion * flag )
	{
		// while the task that we're waiting on is not finished, do some work
		while( !flag->Done() )
			Work( flag );

		// if the flag is owned by the current root task, then since it's done the Pool should be notified
		// NOTE: Eventually other workers will see that there is no current main task to do, and after they are
		//	done chewing through their own internal shit they will go idle waiting for the main thread to assign
		//	them more work.
		if( Pool_->CurrentCompletion_ == flag )
			Pool_->CurrentCompletion_ = nullptr;
	}
Exemplo n.º 27
0
int main(int argc, char **argv)
{
    struct DTDesc *TheDTDesc;

    if(Init(argc, argv, &TheDTDesc))
    {
        Work(TheDTDesc);
    }

    Cleanup(TheDTDesc);

    return(0);
}
Exemplo n.º 28
0
int main (int argc, char **argv){

	int myid;
	int i, j;
	int numWorkers; // assume number of body is multiple of number of workers

	MPI_Init (&argc, &argv);
	MPI_Comm_rank (MPI_COMM_WORLD, &myid);
	MPI_Comm_size (MPI_COMM_WORLD, &numWorkers);	// process 0 is coordinator process and also a worker process
	
	// work
	Work (myid, numWorkers);

	MPI_Finalize ();
}
Exemplo n.º 29
0
NS_IMETHODIMP
FileSystemTaskBase::Run()
{
  if (!NS_IsMainThread()) {
    // Run worker thread tasks
    Work();
    // Dispatch itself to main thread
    NS_DispatchToMainThread(this);
    return NS_OK;
  }

  // Run main thread tasks
  HandleResult();
  return NS_OK;
}
Exemplo n.º 30
0
main()
{
int part;


order[0]=1;
for (int i=1;i<5;i++) order[i]=order[i-1]*10;

cin>>part;
for (;part>0;part--) {
        init();
        cin>>start>>goal;
        Work();
}
}