示例#1
0
/* The real work */
static void do_work(void)
{
	int c;
#ifndef _WIN32
	struct timespec time_to_sleep;
#endif

	while ((c = fgetc(infile)) != EOF)
	{
		DC_ClientEvent *event;

		c = toupper(c);
		if (fputc(c, outfile) == EOF)
		{
			perror("APP: fputc");
			DC_finishClient(1);
		}
		frac_current_pos++;

		/* Real applications do real computation here that takes time. Here
		 * we will emulate waiting a second at the end of each line */

		if (c == '\n')
#ifdef _WIN32
			::Sleep(1000);
#else
		{
			time_to_sleep.tv_sec=1;
			time_to_sleep.tv_nsec=0;
			while (0 > nanosleep(&time_to_sleep, &time_to_sleep))
				if (errno != EINTR) break;
		}
#endif

		/* Check if either the master or the BOINC core client asked
		 * us to do something */
		event = DC_checkClientEvent();
		if (!event)
			continue;

		/* If it is time, do a checkpoint */
		if (event->type == DC_CLIENT_CHECKPOINT)
			do_checkpoint();

		/* Make sure we do not leak memory */
		DC_destroyClientEvent(event);
	}

	if (fclose(outfile))
	{
		perror("APP: Closing the output file has failed");
		DC_finishClient(1);
	}
}
示例#2
0
int main(int argc, char** argv)
{
	
	int ret_val = boinc_init();
	bool ignore_part_file_load = false;
	CHECK_FOR_FAIL_IN_MAIN(ret_val)

	//open input file
	//ret_val = open_input_file();
	if (argc != 4)
		ret_val = BAD_CMD_LINE_PARAMS;

	CHECK_FOR_FAIL_IN_MAIN(ret_val)

	max_n = atoi(argv[1]);
	FAIL_IS_ZERO_IN_MAIN(max_n)

	k_reg = atoi(argv[2]);
	FAIL_IS_ZERO_IN_MAIN(k_reg)
	
	m = atoi(argv[3]);
	FAIL_IS_ZERO_IN_MAIN(m)
	
	//init p_vals with 0s
	p_vals = new short[max_n];
	b_kvals = new short[max_n];
    for (int i = 0; i < max_n; i++)
    {
        p_vals[i] = -1;
		b_kvals[i] = -1;
    }
	
    p_vals[0] = 1;
    p_vals[1] = 1;
	b_kvals[0] = 1;
	/*first check to see if the partition file has been written
		if it hasn't the checkpoint will have p_vals

	*/
	//we just ran finished the part file so no need to load it
	
	/*if the part file hasn't been written, the checkpoint will have b_kvals*/
	if (!part_file_exists())
	{
		//open checkpoint and load from there if it exists
		ret_val = open_part_checkpoint();
		CHECK_FOR_FAIL_IN_MAIN(ret_val)


		for (; current_n < max_n; current_n++)
		{
			if (boinc_time_to_checkpoint() )
			{
				do_checkpoint(p_vals, current_n);
				boinc_checkpoint_completed();
			}

			#if _DEBUG && defined(CHECKPOINTS)
			if (current_n % 100 == 0)
				do_checkpoint(p_vals, current_n);
			#endif

			p(current_n);
			boinc_fraction_done((double)current_n/((double)max_n *2));
		}
		
		//write finalresults
		ret_val = write_part_results();
		CHECK_FOR_FAIL_IN_MAIN(ret_val);
		
		#if _DEBUG && defined(CHECKPOINTS)
		for (int i =0; i < 100; i++)
		{
			cout << i << " = " << (unsigned int) p_vals[i] << "\r\n";
		}
		#endif

		//delete old checkpoint file
		delete_checkpoint();

		current_n = 0;
		ignore_part_file_load = true;
	}