Ejemplo n.º 1
0
static void calc_lines(Uint32 start, Uint32 end, Uint32* lines,
                       double max_values_sq, Uint32 max_iter)
{
  Uint32 i, iter_wert, icolor;
  double cx, cy;

  double pd_x = 3.0 / (double)MAX_X;
  double pd_y = 2.0 / (double)MAX_Y;

#ifdef MANUAL
  VT_USER_START("calc_lines");
#endif

  for(i = start; i < end; i++)
  {
    cx = -2.0 + (i / MAX_Y) * pd_x;
    cy = -1.0 + (i % MAX_Y) * pd_y;

    iter_wert = mandelbrot_point(cx, cy, max_values_sq, max_iter);

    icolor = (double)iter_wert / (double)max_iter * (1u << 24);
    lines[i-start] = icolor;
  }

#ifdef MANUAL
  VT_USER_END("calc_lines");
#endif
}
Ejemplo n.º 2
0
// Splits the image in pieces and calls the corresponding algorithm
void *thread_launcher(void *arguments)
{
    piece_args *args;
    args = (piece_args *) arguments;

    int x,y, small_res_x, small_res_y, init_x, init_y, limit_x, limit_y;
    int split, piece_x, piece_y;

    if(args->total_threads > 2)
    {
        split = sqrt(args->total_threads);
    }
    else if (args->total_threads == 2)
    {
        split = 2;
    }
    else
    {
        split = 1;
    }

    if (args->thread_number > 0)
    {
        piece_x = args->thread_number % split;
        piece_y = floor((float)args->thread_number / (float)split);
    }
    else
    {
        piece_x = 0;
        piece_y = 0;
    }

    small_res_x = floor((float)args->res_x / (float)split);
    small_res_y = floor((float)args->res_y / (float)split);
    init_x = small_res_x * piece_x;
    init_y = small_res_y * piece_y;
    limit_x = init_x + small_res_x;
    limit_y = init_y + small_res_y;

    for (y = init_y; y < limit_y; y++)
    {
        for (x = init_x; x < limit_x; x++)
        {
            if(args->julia_mode == 0)
                iteration_pixels[x + (y * args->res_x)] = mandelbrot_point(args->res_x, args->res_y, x, y, args->zoom, args->max_iteration);
            else
                iteration_pixels[x + (y * args->res_x)] = julia_point(args->res_x, args->res_y, x, y, args->zoom, args->max_iteration);
        }
    }
}
Ejemplo n.º 3
0
static void calc_pixels(Uint32 start, Uint32 end, Uint32* pixels,
                       double max_values_sq, Uint32 max_iter)
{
  Uint32 i, iter, icolor;
  double cx, cy;

  double pd_x = 3.0 / (double)MAX_X;
  double pd_y = 2.0 / (double)MAX_Y;

  for(i = start; i < end; i++)
  {
    cx = -2.0 + (i / MAX_Y) * pd_x;
    cy = -1.0 + (i % MAX_Y) * pd_y;

    iter= mandelbrot_point(cx, cy, max_values_sq, max_iter);

    icolor = (double)iter/ (double)max_iter * (1u << 24);
    pixels[i-start] = icolor;
  }
}
Ejemplo n.º 4
0
int main (int argc, char * argv[])
{
	// TODO:
	// (see message_queue_test() in interprocess_basic.c)
	//  v open the two message queues (whose names are provided in the arguments)
	//  v repeatingly:
	//	  - read from a message queue the new job to do
	//	  - wait a random amount of time (e.g. rsleep(10000);)
	//	  - do that job (use mandelbrot_point() if you like)
	//	  - write the results to a message queue
	//	until there are no more jobs to do
	//  v close the message queues

	if (argc != 2) {
		printf("Wrong number of arguments.\n");
		exit(0);
	}
	
	mqd_t				mq_fd_request;	/* request message queue farmer -> worker */
	mqd_t				mq_fd_response; /* response message queue worker -> farmer */
	MQ_REQUEST_MESSAGE	req;			/* request message */
	MQ_RESPONSE_MESSAGE	rsp;			/* response message */
	
	// open message queues
	mq_fd_request = mq_open(argv[0], O_RDONLY);
	mq_fd_response = mq_open(argv[1], O_WRONLY);
	
	while (true)
	{
		// sleep a random amount of time
		rsleep(1000);
		
		// read a message from the message queue
		// this blocks the execution until the worker receives a message
		printf("worker: waiting for message...\n");
		mq_receive(mq_fd_request, (char *) &req, sizeof (req), NULL);
		// debug
		printf("worker: message received...\n");
		
		// if the message is a signal that the worker can finish..
		if (req.done) {
			//..break out of the loop
			break;
		}
		
		// build response message
		rsp.y = req.y;
		
		int x;
		for (x = 0; x < X_PIXEL; x += 1) {
			rsp.v[x] = mandelbrot_point(X_LOWERLEFT + ((double) x) * STEP, 
					Y_LOWERLEFT + ((double) req.y) * STEP);
		}
		
		printf("worker: sending response...\n");
		mq_send(mq_fd_response, (char *) &rsp, sizeof (rsp), 0);
		printf("worker: sent\n");
	}

	printf("worker: closing message queues\n");

	// close message queues
	mq_close(mq_fd_response);
	mq_close(mq_fd_request);
	
	printf("worker: stopped\n");
	
	return 0;
}