diff --git a/src/main/c/includes/fluid/env/environment.h b/src/main/c/includes/fluid/env/environment.h index 7a7d3a65..d7247564 100644 --- a/src/main/c/includes/fluid/env/environment.h +++ b/src/main/c/includes/fluid/env/environment.h @@ -72,6 +72,8 @@ typedef struct { double existingDensity; double newDensity; double normalizationRatio; + double densityTime; + double velocityTime; int frame; } FluidSimState; diff --git a/src/main/c/src/fluid/sim/grid2/grid2.c b/src/main/c/src/fluid/sim/grid2/grid2.c index 4782b572..0077e342 100644 --- a/src/main/c/src/fluid/sim/grid2/grid2.c +++ b/src/main/c/src/fluid/sim/grid2/grid2.c @@ -1,6 +1,7 @@ #include #include #include +#include //native interfaces #include "native/electrosphere_server_fluid_simulator_FluidAcceleratedSimulator.h" @@ -43,6 +44,11 @@ float * fluid_grid2_neighborArr_v0; float * fluid_grid2_neighborArr_w0; float * fluid_grid2_neighborArr_bounds; +/** + * Used for storing timings + */ +static struct timeval tv; + LIBRARY_API void fluid_grid2_simulate( int numChunks, Chunk ** passedInChunks, @@ -50,8 +56,11 @@ LIBRARY_API void fluid_grid2_simulate( jfloat timestep ){ Chunk ** chunks = passedInChunks; + double start, end, perMilli; + gettimeofday(&tv,NULL); + start = 1000000.0 * tv.tv_sec + tv.tv_usec; // //Velocity step // @@ -110,7 +119,12 @@ LIBRARY_API void fluid_grid2_simulate( } - + //get time at end + gettimeofday(&tv,NULL); + end = 1000000.0 * tv.tv_sec + tv.tv_usec; + perMilli = (end - start) / 1000.0f; + environment->state.velocityTime = perMilli; + start = end; ///------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ///------------------------------------------------------------------------------------------------------------------------------------------------------------------------ @@ -144,6 +158,12 @@ LIBRARY_API void fluid_grid2_simulate( fluid_grid2_advectDensity(currentChunk->d,currentChunk->d0,currentChunk->u,currentChunk->v,currentChunk->w,timestep); } + //get time at end + gettimeofday(&tv,NULL); + end = 1000000.0 * tv.tv_sec + tv.tv_usec; + perMilli = (end - start) / 1000.0f; + environment->state.densityTime = perMilli; + // //mirror densities diff --git a/src/test/c/fluid/sim/grid2/speed_tests.c b/src/test/c/fluid/sim/grid2/speed_tests.c index 2520cda8..0b9cfba6 100644 --- a/src/test/c/fluid/sim/grid2/speed_tests.c +++ b/src/test/c/fluid/sim/grid2/speed_tests.c @@ -110,6 +110,8 @@ int fluid_sim_grid2_speed_test1(){ printf("Frame time per chunk (micro): %lf \n",avgPerChunk); printf("Frame time per chunk (milli): %lf \n",perMilli); printf("Target time (milli): %f \n",TIME_PER_CHUNK); + printf("Velocity time (milli): %f \n",env->state.velocityTime); + printf("Density time (milli): %f \n",env->state.densityTime); printf("\n"); rVal++; } @@ -162,6 +164,8 @@ int fluid_sim_grid2_speed_test2(){ printf("Frame time per chunk (micro): %lf \n",avgPerChunk); printf("Frame time per chunk (milli): %lf \n",perMilli); printf("Target time (milli): %f \n",TIME_PER_CHUNK); + printf("Velocity time (milli): %f \n",env->state.velocityTime); + printf("Density time (milli): %f \n",env->state.densityTime); printf("\n"); rVal++; } @@ -214,6 +218,8 @@ int fluid_sim_grid2_speed_test3(){ printf("Frame time per chunk (micro): %lf \n",avgPerChunk); printf("Frame time per chunk (milli): %lf \n",perMilli); printf("Target time (milli): %f \n",TIME_PER_CHUNK); + printf("Velocity time (milli): %f \n",env->state.velocityTime); + printf("Density time (milli): %f \n",env->state.densityTime); printf("\n"); rVal++; }