int main() { Init(); CustomKernel mandelbrot; MODULE_INT_START(mandelbrot) MOUDLE_INPUT_FLOAT(x) MOUDLE_INPUT_FLOAT(y) MODULE_INPUT_INT(maxItt) MODULE_MAIN FLOAT(a = 0.0f) FLOAT(b = 0.0f) INT(i = 0) INT(j = 0) WHILE(i < maxItt) BEGIN IF( a * a + b * b > 4) BEGIN STATEMENT(j = 1) BREAK END FLOAT(aTemp = a) STATEMENT(a = a * a - b * b + x) STATEMENT(b = 2 * aTemp * b + y) STATEMENT(i++) END MODULE_RETURN(i) MODULE_END CustomKernel mandelbrotRun; KERNEL_START(mandelbrotRun) KERNEL_INPUT_INT(itt) INCLUDE(mandelbrot) KERNEL_MAIN INT(val) FLOAT(x = (MYCOORD.x - 0.5) * 4) FLOAT(y = (MYCOORD.y - 0.5) * 4) CALL(val, mandelbrot, x, y, itt) KERNEL_OUTPUT(1.5 / float(val)) KERNEL_END DeviceVector dVOut(1024, 1024); HostVector hVOut; mandelbrotRun.Input(500); mandelbrotRun.Output(dVOut); mandelbrotRun.Execute(); hVOut = dVOut; ImageProcessing::SaveImageFile("mandelbrot.bmp", hVOut); getchar(); return 0; }
int main() { Init(); CustomKernel pow; MODULE_FLOAT_START(pow) MOUDLE_INPUT_FLOAT(in0) MODULE_MAIN MODULE_RETURN(in0 * in0) MODULE_END CustomKernel run; KERNEL_START(run) KERNEL_INPUT_DVEC(vec) INCLUDE(pow) KERNEL_MAIN FLOAT(outp) GET(outp, vec) CALL(outp, pow, outp) KERNEL_OUTPUT(outp) KERNEL_END DeviceVector dV0; DeviceVector dVOut(100); HostVector hV0(100); HostVector hVOut; for(int i = 0; i < 100; i++) hV0[i] = (float)i; dV0 = hV0; run.Input(dV0); run.Output(dVOut); run.Execute(); hVOut = dVOut; for(int i = 0; i < 100; i++) { printf("%f, ", hVOut[i]); } printf("\n"); getchar(); return 0; }
/* Main function * Fills the box with accepted parts and then transmits it to the printer */ void* doBox(void*a) { /* INIT *******************************************************************/ INCLUDE(Box) INCLUDE(Valve) INIT_LOGGER(); INIT_CONTROL(); INIT_CHECK_FOR_APP_END(); extern int PARTS_BY_BOX; extern int MAX_REFUSED_PARTS_BY_BOX; extern int CurrentBatchProdMax; extern int CurrentProducedBoxes; extern int CurrentBatchRefusedPartsNumber; extern int BOXES_BY_PALETTE; extern sem_t SemSyncBoxPrint; extern sem_t SemPushBoxPrint; extern sem_t SemNewPart; int refusedPartsCount = 0; /* Number of parts that have been refused for the current box (not to be higher than MAX_REFUSED_PARTS_BY_BOX) */ int currentBoxPartsNumber = 0; #ifdef DBG printf("%d\n", (int) getpid()); #endif /* MAIN LOOP **************************************************************/ for (;;) { CHECK_WAIT_BOOL(Box); CHECK_FOR_APP_END_AND_STOP("Box"); DBGPRINT("doBox", "Main", "Task is unlocked."); bool boxIsMissing = TRUE; #ifdef SIMU_MODE boxIsMissing = simu_missing_box(); #endif if (boxIsMissing) { /* Closing the valve */ LOCK(Valve); DBGPRINT("doBox", "Main", "Closing valve."); LOG("doBox: Missing box, ERROR."); LOCK(Box); /* Forbidding ourself to do another loop before the green * light has been set by the doControl thread */ /* Sending error message */ ERR_MSG(ERR_BOX); /* Going back to the beginning of the loop and standing still until * the doControl thread says otherwise */ continue; } /* At the end of the loop (and thus at its beginning, the other way * around), we are basically just waiting for a new part * This part will come as a unlocking the sempahore SemSimuNewPart * (supposed to be an IT) */ sem_wait(&SemNewPart); bool refused = TRUE; #ifdef SIMU_MODE refused = simu_refusal(); #endif if (!refused) /* Part is accepted */ { DBGPRINT("doBox", "Main", "New accepted part."); LOG("doBox: New accepted part."); /* There's a new part to put in that freaking box: */ currentBoxPartsNumber = (currentBoxPartsNumber + 1) % PARTS_BY_BOX; DBGPRINT("doBox", "Main", "currentBoxPartsNumber="); #ifdef DBG printf("%d\n", currentBoxPartsNumber); #endif if (!currentBoxPartsNumber) /* Is the box full? */ { DBGPRINT("doBox", "Main", "The box is full"); refusedPartsCount = 0; /* Reset refused parts by box counter */ CurrentProducedBoxes++; if ((CurrentProducedBoxes / BOXES_BY_PALETTE) >= CurrentBatchProdMax) { /* The current batch is over, so close the valve */ LOCK(Valve); /* And send a log so that the client is able to know that * the production of the current batch is over * (important call, not to be deleted or changed) */ LOG(PRODUCTION_IS_OVER_MSG); } /* **** "READY TO GO TO PRINTER" SEMAPHORE CHECK */ sem_wait(&SemSyncBoxPrint); sem_post(&SemPushBoxPrint); } } else { DBGPRINT("doBox", "Main", "New REFUSED part."); LOG("doBox: New REFUSED part."); refusedPartsCount++; CurrentBatchRefusedPartsNumber++; if (refusedPartsCount >= MAX_REFUSED_PARTS_BY_BOX) { /* Closing the valve */ refusedPartsCount = 0; /* Resetting the counter, so that when * the error is marked as "solved" we * don't go back into error mode */ LOCK(Valve); DBGPRINT("doBox", "Main", "Closing valve."); LOG("doBox: Refused rate is too high, ERROR."); LOCK(Box); /* Forbidding ourself to do another loop before the * green light has been set by the doControl thread */ /* Sending error message */ ERR_MSG(ERR_BOX_REFUSED_RATE); } } } }