int mycudaCompute() { // ri scrivo la funzione di update presente in dll "seriale" // utilizzando "GPUCompute(boidSet)" come chiamata cuda anzichè la normale "compute()" unsigned int simulationLenght,progress; int exitValue; int test=0; progress=0; simulationLenght=(unsigned int)ceil(simParameters.fps * simParameters.lenght); _Output(&cacheFileOption); while((!abortSimulation) && (progress<=simulationLenght)) { Channel *channels; channels=(Channel*)malloc(sizeof(Channel)*info.option); GPUCompute(boidSet); // data management cachingData(channels); // write data writeData(progress,channels); // update the index job progress simulationProgress = ((int)(100*progress)/simulationLenght); //advance to the next frame progress++; test++; // free channels memory freeChannel(channels); } simulationProgress=100; closeMethod(); if(abortSimulation) { printf("Simulation interrupted\n"); deleteData(); exitValue=INTERRUPTED_SIM; } // restoring abortSimulation flag abortSimulation=FALSE; exitValue=SUCCESS_SIM; // free resources free(boidSet); return exitValue; }
// update simulation void update() { unsigned int simulationLenght,progress; progress=0; simulationLenght=(unsigned int)ceil(simParameters.fps * simParameters.lenght); _Output(&cacheFileOption); while((!abortSimulation) && (progress<=simulationLenght)) { Channel *channels; channels=(Channel*)malloc(sizeof(Channel)*info.option); // compute Boids' new positions, velocities, accelerations compute(); // data management cachingData(channels); // write data writeData(progress,channels); // update Boids properties and kdtree updateBoids(); // update the index job progress simulationProgress = ((int)(100*progress)/simulationLenght); //advance to the next frame progress++; // free channels memory freeChannel(channels); } simulationProgress=100; closeMethod(); if(abortSimulation) { printf("Simulation interrupted\n"); deleteData(); } // restoring abortSimulation flag abortSimulation=FALSE; // free resources free(boidSet); kd_free(k3); }