void set_texture() { alloc_tex(); int height_delta = BLOCK_SIZE / tex_w / 3; int i; /* Since the pcie hybrid version reuses the same memory to compute different portions of the image, the SW_ONLY executable should use a non-zero OFFSET*/ #ifdef SW_ONLY #define OFFSET (i*tex_w) #else #define OFFSET (0) #endif for (i = 0; i < height; i += height_delta) { calc_mandel(scale, cx, cy, SHARED_tex+OFFSET, tex_w, max_iter, width, i, MIN(i+height_delta,height), height); memcpy_from_shared(tex[i], SHARED_tex, height_delta * tex_w * 3); } glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture); glTexImage2D(GL_TEXTURE_2D, 0, 3, tex_w, tex_h, 0, GL_RGB, GL_UNSIGNED_BYTE, tex[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); render(); }
void slave() { int rn, i; int imag, real; Complex_type cx; do { do { /* receive the line number from the master process, if the line number is negtive, it indicates that a window is ready, it should wait*/ MPI_Recv(&rn, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status); if(rn == -1) break; /*calculate the mandelbrot numbers of points of the line.*/ cx.imag = imag_min + ((double)rn*imag_scale); for(i = 0; i < W; i++) { cx.real = real_min + ((double)i*real_scale); mans[i] = calc_mandel(cx); } mans[W] = rn; /*send the result back to the master process*/ MPI_Send(mans, W+1, MPI_INT, 0, tag, MPI_COMM_WORLD); } while(1); /*after a window is ready, the slave waits for the new lower left and upper right points, if the points are (-3, -3),(-3, -3), the slave terminates else it continues to calculate the mandelbrot numbers for new lines. */ MPI_Bcast(min_max, 4, MPI_DOUBLE, 0, MPI_COMM_WORLD); real_min = min_max[0]; real_max = min_max[1]; imag_min = min_max[2]; imag_max = min_max[3]; imag_scale = (imag_max-imag_min)/(double)H; real_scale = (real_max-real_min)/(double)W; } while(real_min!=-3&&real_max!=-3&&imag_min!=-3&&imag_max!=-3); }