//============================================================================== MainAppWindow::MainAppWindow() : DocumentWindow (JUCEApplication::getInstance()->getApplicationName(), Colours::darkgrey, DocumentWindow::allButtons) { LookAndFeel::setDefaultLookAndFeel (&lookAndFeel); setupColours(); setContentOwned (new MainComponent, false); centreWithSize (800, 600); setVisible (true); setResizable (true, true); }
int main(int argc, char *argv[]) { int rank, nprocs, x, y; Window win; // initialization for a window GC gc; // graphics context Display *display = NULL; Colormap screenColourmap; XColor colours[15]; unsigned int width = X_RESN, height = Y_RESN; /* window size */ clock_t start, end, elapsed; int pixelToDraw[3]; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &nprocs); MPI_Comm_rank(MPI_COMM_WORLD, &rank); ComplexNumber c; ComplexNumber z; int depth = 1000; int cSize = 4; double cX = -2; double cY = -2; double cMinR = cX; double cMinI = cY; double cMaxR = cMinR + cSize; double cMaxI = cMinI + cSize; double increaseX = (cMaxR - cMinR) / X_RESN; double increaseY = (cMaxI - cMinI) / Y_RESN; int drawable[X_RESN][Y_RESN]; if(rank==0) { display = x11setup(&win, &gc, width, height); screenColourmap = DefaultColormap(display, DefaultScreen(display)); setupColours(display, colours, screenColourmap); int probeFlag = 0; MPI_Status status; int count = 0; int start = 1; for (int i = 1; i < nprocs; i++) { MPI_Send(&start, 1, MPI_INT, i, 98, MPI_COMM_WORLD); } for (int y = 0; y < Y_RESN; y++) { for (int x = 0; x < X_RESN; x++) { while (!probeFlag) { MPI_Iprobe(MPI_ANY_SOURCE, 99, MPI_COMM_WORLD, &probeFlag, &status); if (probeFlag) { int coords[2] = {x, y}; int slave = status.MPI_SOURCE; MPI_Recv(&pixelToDraw, 3, MPI_INT, MPI_ANY_SOURCE, 99, MPI_COMM_WORLD, MPI_STATUS_IGNORE); MPI_Send(&coords, 2, MPI_INT, slave, 99, MPI_COMM_WORLD); drawable[pixelToDraw[0]][pixelToDraw[1]] = pixelToDraw[2]; count++; } else { MPI_Iprobe(MPI_ANY_SOURCE, 98, MPI_COMM_WORLD, &probeFlag, &status); if (probeFlag) { int slave = status.MPI_SOURCE; int coords[2] = {x, y}; MPI_Recv(&start, 1, MPI_INT, MPI_ANY_SOURCE, 98, MPI_COMM_WORLD, MPI_STATUS_IGNORE); MPI_Send(&coords, 2, MPI_INT, slave, 99, MPI_COMM_WORLD); } } } probeFlag = 0; } } MPI_Recv(&pixelToDraw, 3, MPI_INT, MPI_ANY_SOURCE, 99, MPI_COMM_WORLD, MPI_STATUS_IGNORE); drawable[pixelToDraw[0]][pixelToDraw[1]] = pixelToDraw[2]; for (int y = 0; y < Y_RESN; y++) { for (int x = 0; x < X_RESN; x++) { drawPoint(display, win, gc, colours, x, y, depth, drawable[x][y]); } } } else { int flag = 1; int coords[2]; MPI_Recv(&start, 1, MPI_INT, 0, 98, MPI_COMM_WORLD, MPI_STATUS_IGNORE); MPI_Send(&start, 1, MPI_INT, 0, 98, MPI_COMM_WORLD); while (flag) { MPI_Recv(&coords, 2, MPI_INT, 0, 99, MPI_COMM_WORLD, MPI_STATUS_IGNORE); c.r = coords[0] * increaseX - 2; c.i = coords[1] * increaseY - 2; resetComplexNumber(&z); int limit = seriesDiverges(depth, &z, &c); pixelToDraw[0] = coords[0]; pixelToDraw[1] = coords[1]; pixelToDraw[2] = limit; MPI_Send(&pixelToDraw, 3, MPI_INT, 0, 99, MPI_COMM_WORLD); } } // main loop int running = 1; // loop variable start = clock(); while(running) { // checks to see if there have been any events, // will exit the main loop if any key is pressed if(rank==0) { if(XPending(display)) { XEvent ev; XNextEvent(display, &ev); switch(ev.type) { case KeyPress: running = 0; break; } } } end = clock(); elapsed = end - start; // only update the display if > 1 millisecond has passed since the last update if(elapsed / (CLOCKS_PER_SEC/1000) > 1 && rank==0) { //XClearWindow(display, win); start = end; XFlush(display); } } if(rank==0 && display) { XCloseDisplay(display); // close the display window printf("Display closed\n"); } else { MPI_Finalize(); return 0; } MPI_Finalize(); return 0; }
//============================================================================== ProjucerLookAndFeel::ProjucerLookAndFeel() { setupColours(); }