int main(int argc, char *argv[]) { initTracer(); scene *curscene = sceneLoad(); TGAFILE *tga = openTGA(curscene); clock_t start = clock(); int i, j; for (j = 0; j < (int)curscene->resolution; j++) { printf("Scanning horizontal line %d.\n", j); for (i = 0; i < (int)curscene->resolution; i++) { vector color = pixelraytrace(curscene, i, j); writeTGAColor(tga, curscene, i, j, color.x, color.y, color.z); } } clock_t end = clock(); printf("Entire process took %.4f seconds.\n", ((double)(end - start)) / CLOCKS_PER_SEC); sceneFree(curscene); closeTGA(tga); return 0; }
int main(int argc, char *argv[]) { initTracer(); int i; int rank, size; scene *curscene; int res; TGAFILE* tga = NULL; vector *scanline; MPI_Status status; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); if (rank == 0) { curscene = sceneLoad(); tga = openTGA(curscene); } else curscene = calloc(1, sizeof(scene)); MPI_Bcast((void*)curscene, sizeof(scene) / sizeof(float), MPI_FLOAT, 0, MPI_COMM_WORLD); res = sceneResolution(curscene); scanline = calloc(res, sizeof(vector)); int line = 0; float aaweight = 1.0f / size; for (line = 0; line < res; line++) { if (rank == size - 1) { printf("Starting scan of horizontal line %d.\n", line); } else { MPI_Recv(scanline, (sizeof(vector) / sizeof(float)) * res, MPI_FLOAT, rank + 1, MPI_ANY_TAG, MPI_COMM_WORLD, &status); } for (i = 0; i <res; i++) { if (rank == size - 1) scanline[i] = smul(pixelraytraceaa(curscene, line, i, rank), aaweight); else scanline[i] = add(scanline[i], smul(pixelraytraceaa(curscene, line, i, rank), aaweight)); } if (rank == 0) { for (i = 0; i < res; i++) writeTGAColor(tga, curscene, line, i, scanline[i].x, scanline[i].y, scanline[i].z); } else { MPI_Send(scanline, (sizeof(vector) / sizeof(float)) * res, MPI_FLOAT, rank - 1, 0, MPI_COMM_WORLD); } } free(curscene); MPI_Finalize(); return 0; }
/* make sure that the xvalues and yvalues contain enough values to go tracers deep */ void drawTracerGraph(HWND hwnd, long *xvalues, long *yvalues, int maxval, int tracers) { //void drawTracerGraph(HWND hwnd, float nx, float ny) { HDC hdc; RECT rect; HPEN pen; int x,y; int w,h,fw,fh; int c; if (hdcTracer == NULL) initTracer(hwnd); /* get attributes */ GetClientRect(hwnd, &rect); hdc = GetDC(hwnd); fw = rect.right - rect.left; fh = rect.bottom - rect.top; w = rect.right - rect.left - (XHAIR_HALF*2|1); h = rect.bottom - rect.top - (XHAIR_HALF*2|1); /* copy over the trace graph */ BitBlt(hdc, 0, 0, fw, fh, hdcTracer, 0, 0, SRCCOPY); /* draw the xhair */ for (c=tracers; c>0; c--) { pen = CreatePen(PS_SOLID, 1, RGB(255-(128/tracers*c),255-(255/tracers*c),0)); SelectPen(hdc, pen); x = (int) (w*((float)xvalues[c] / maxval + 1)/2.0f) + XHAIR_HALF; y = (int) (h*((float)yvalues[c] / maxval + 1)/2.0f) + XHAIR_HALF; centerLine(hdc, x, y, (XHAIR_HALF|1)-2, LINE_XAXIS); centerLine(hdc, x, y, (XHAIR_HALF|1)-2, LINE_YAXIS); DeletePen(pen); } //special case of very first xhair pen = CreatePen(PS_SOLID, 1, RGB(255,0,0)); SelectPen(hdc, pen); x = (int) (w*((float)xvalues[c] / maxval + 1)/2.0f) + XHAIR_HALF; y = (int) (h*((float)yvalues[c] / maxval + 1)/2.0f) + XHAIR_HALF; centerLine(hdc, x, y, XHAIR_HALF*2|1, LINE_XAXIS); centerLine(hdc, x, y, XHAIR_HALF*2|1, LINE_YAXIS); DeletePen(pen); GdiFlush(); ReleaseDC(hwnd, hdc); }
int main(int argc, char *argv[]) { initTracer(); int i, p; int rank, size; scene *curscene; int res; TGAFILE* tga = NULL; vector *scanline; MPI_Status status; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); if (rank == 0) { curscene = sceneLoad(); tga = openTGA(curscene); } else curscene = calloc(1, sizeof(scene)); double start, end; start = MPI_Wtime(); MPI_Bcast((void*)curscene, sizeof(scene) / sizeof(float), MPI_FLOAT, 0, MPI_COMM_WORLD); res = sceneResolution(curscene); scanline = calloc(res, sizeof(vector)); if (rank == 0) { int lastline = 0; int waiting = res; for (lastline = 0; lastline < size - 1; lastline++) { MPI_Send(&lastline, 1, MPI_INT, lastline + 1, 0, MPI_COMM_WORLD); } int flag; while(1) { if (waiting == 0) break; MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, &status); if (flag) { MPI_Recv(scanline, (sizeof(vector) / sizeof(float)) * res, MPI_FLOAT, status.MPI_SOURCE, status.MPI_TAG, MPI_COMM_WORLD, &status); if (lastline < res) { MPI_Send(&lastline, 1, MPI_INT, status.MPI_SOURCE, 0, MPI_COMM_WORLD); lastline++; } for (i = 0; i < res; i++) writeTGAColor(tga, curscene, status.MPI_TAG, i, scanline[i].x, scanline[i].y, scanline[i].z); waiting--; } } flag = -1; for (p = 1; p < size; p++) { MPI_Send(&flag, 1, MPI_INT, p, 0, MPI_COMM_WORLD); } } else { int line; while(1) { MPI_Recv(&line, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &status); if (line < 0) { break; } printf("Process %d scanning horizontal line %d.\n", rank, line); for (i = 0; i < res; i++) scanline[i] = pixelraytrace(curscene, line, i); MPI_Send(scanline, (sizeof(vector) / sizeof(float)) * res, MPI_FLOAT, 0, line, MPI_COMM_WORLD); } } free(curscene); end = MPI_Wtime(); if (rank == 0) printf("Entire process took %.4f seconds.\n", end - start); MPI_Finalize(); return 0; }