diff --git a/Makefile b/Makefile index 805297b..4a227be 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,3 @@ - install: source ./script_install.sh @@ -11,9 +10,15 @@ fftma: binaries: ./script_fortran.sh -test: binaries +test: binaries fftma cd tests/integration && python3 -m unittest test.py perf: binaries cd tests/performance && python3 generation.py - cd tests/performance && python3 connectivity.py \ No newline at end of file + cd tests/performance && python3 connectivity.py + +test-gen: fftma + cd tests/stages/generation && python3 -m unittest test.py + +time-gen: fftma + cd tests/performance/generation && python3 time.py $(N) \ No newline at end of file diff --git a/README.md b/README.md index f19a670..006055e 100644 --- a/README.md +++ b/README.md @@ -18,18 +18,32 @@ make binaries make run ``` -## Correr los casos de prueba +## Pruebas de integración ``` make test ``` +## Pruebas unitarias + +### Generacion + +``` +make test-gen +``` + ## Correr las pruebas de performance ``` make perf ``` +### Obtener tiempos de generacion + +``` +make time-gen N= +``` + ## Instalar el binario FFTMA ``` @@ -43,5 +57,3 @@ El sistema actualmente se encuentra migrado a Python3 por lo que no se recomiend ``` ./script_install_py2.sh ``` - - diff --git a/fftma_module/gen/example.py b/fftma_module/gen/example.py new file mode 100644 index 0000000..e2d7652 --- /dev/null +++ b/fftma_module/gen/example.py @@ -0,0 +1,34 @@ +from FFTMA import gen +import numpy as np +import sys + +def generate(n): + nx, ny, nz = n,n,n + dx, dy, dz = 1.0, 1.0, 1.0 + seed= 1548762 #rdi(10000,99999) + var=1 + vario=2 + alpha=1 + lcx=2 + lcy=4 + lcz=16 + ap1x=1 + ap1y=0 + ap1z=0 + ap2x=0 + ap2y=1 + ap2z=0 + + v1 = (var, vario, alpha, lcx, lcy, lcz, ap1x, ap1y, ap1z, ap2x, ap2y, ap2z) + variograms = [v1] + + mean=15.3245987 + variance=3.5682389 + typ=3 + + k=gen(nx, ny, nz, dx, dy, dz, seed, variograms, mean, variance, typ) + np.save(f"out_{n}.npy",k) + +if __name__ == '__main__': + N=int(sys.argv[1]) + generate(N) \ No newline at end of file diff --git a/fftma_module/gen/include/geostat.h b/fftma_module/gen/include/geostat.h index 9b4b6a7..d47239f 100644 --- a/fftma_module/gen/include/geostat.h +++ b/fftma_module/gen/include/geostat.h @@ -422,7 +422,7 @@ float gammp(float a, float x); /*and unit variance, using ran1(idum) as the source */ /*of uniform deviates */ /*idum: seed */ -double gasdev(long* idum, long* idum2, long* iy, long* iv, int* iset); +double gasdev(long* idum, long* idum2, long* iy, long* iv); /*gaussian covariance value for lag h*/ double gaussian(double h); diff --git a/fftma_module/gen/lib_src/generate.c b/fftma_module/gen/lib_src/generate.c index 99786e5..912351d 100644 --- a/fftma_module/gen/lib_src/generate.c +++ b/fftma_module/gen/lib_src/generate.c @@ -33,7 +33,7 @@ void generate(long* seed, int n, struct realization_mod* realization) /*Gaussian white noise generation*/ for (i = 0; i < n; i++) - (*realization).vector[i] = gasdev(seed, &idum2, &iy, iv, &iset); + (*realization).vector[i] = gasdev(seed, &idum2, &iy, iv); free(iv); } diff --git a/fftma_module/gen/lib_src/geostat.h b/fftma_module/gen/lib_src/geostat.h index 78b121a..fcc0066 100644 --- a/fftma_module/gen/lib_src/geostat.h +++ b/fftma_module/gen/lib_src/geostat.h @@ -423,7 +423,7 @@ float gammp(float a, float x); /*and unit variance, using ran1(idum) as the source */ /*of uniform deviates */ /*idum: seed */ -double gasdev(long* idum, long* idum2, long* iy, long* iv, int* iset); +double gasdev(long* idum, long* idum2, long* iy, long* iv); /*gaussian covariance value for lag h*/ double gaussian(double h); diff --git a/fftma_module/gen/mem_profile.py b/fftma_module/gen/mem_profile.py new file mode 100644 index 0000000..55d5cba --- /dev/null +++ b/fftma_module/gen/mem_profile.py @@ -0,0 +1,16 @@ +from sympy import N +from example import generate + +from memory_profiler import memory_usage + +from memory_profiler import memory_usage +import sys + +if __name__ == '__main__': + N=int(sys.argv[1]) + + def run_gen(): + generate(N) + + mem_usage = memory_usage(run_gen) + print('Maximum memory usage: %s' % max(mem_usage)) \ No newline at end of file diff --git a/fftma_module/gen/out_8.npy b/fftma_module/gen/out_8.npy new file mode 100644 index 0000000..03ee9a1 Binary files /dev/null and b/fftma_module/gen/out_8.npy differ diff --git a/fftma_module/gen/setup.py b/fftma_module/gen/setup.py index 36852cd..8349b3c 100644 --- a/fftma_module/gen/setup.py +++ b/fftma_module/gen/setup.py @@ -1,9 +1,10 @@ from distutils.core import setup, Extension +import numpy module_FFTMA = Extension( "FFTMA", - include_dirs=["./include"], + include_dirs=["./include", numpy.get_include()], extra_compile_args=["-g", "-std=c99", "-Wall", "-Wconversion", "-Wtype-limits", "-pedantic"], sources=[ "moduleFFTMA.c", diff --git a/fftma_module/gen/test.py b/fftma_module/gen/test.py deleted file mode 100644 index 6e537f4..0000000 --- a/fftma_module/gen/test.py +++ /dev/null @@ -1,36 +0,0 @@ -from FFTMA import gen -import numpy as np -import gc - -N=512 - -nx, ny, nz = N,N,N -dx, dy, dz = 1.0, 1.0, 1.0 -seed= 1548762 #rdi(10000,99999) -var=1 -vario=2 -alpha=1 -lcx=2 -lcy=4 -lcz=16 -ap1x=1 -ap1y=0 -ap1z=0 -ap2x=0 -ap2y=1 -ap2z=0 - -v1 = (var, vario, alpha, lcx, lcy, lcz, ap1x, ap1y, ap1z, ap2x, ap2y, ap2z) -variograms = [v1] - -mean=15.3245987 -variance=3.5682389 -typ=3 - -for i in range(2): - k=gen(nx, ny, nz, dx, dy, dz, seed, variograms, mean, variance, typ) - - np.save(f"out_{i}.npy",k) - - del k - gc.collect() \ No newline at end of file diff --git a/tests/performance/generation/time.py b/tests/performance/generation/time.py new file mode 100644 index 0000000..19eb542 --- /dev/null +++ b/tests/performance/generation/time.py @@ -0,0 +1,56 @@ +import numpy as np +#from tests.utils.gen_sample import generate + +import sys + +from FFTMA import gen +import time + +def generate(N): + start_time = time.time() + nx, ny, nz = N,N,N + dx, dy, dz = 1.0, 1.0, 1.0 + seed= 1548762 #rdi(10000,99999) + var=1 + vario=2 + alpha=1 + lcx=2 + lcy=4 + lcz=16 + ap1x=1 + ap1y=0 + ap1z=0 + ap2x=0 + ap2y=1 + ap2z=0 + + v1 = (var, vario, alpha, lcx, lcy, lcz, ap1x, ap1y, ap1z, ap2x, ap2y, ap2z) + variograms = [v1] + + mean=15.3245987 + variance=3.5682389 + typ=3 + + k = gen(nx, ny, nz, dx, dy, dz, seed, variograms, mean, variance, typ) + + duration = time.time() - start_time + return k, duration + +N=int(sys.argv[1]) +SAMPLE_SIZE=100 + +def time_measurement(n, sample_size): + sample = [] + + print(f"SAMPLE_SIZE = {SAMPLE_SIZE}") + for i in range(sample_size): + _, duration = generate(n) + print(i) + sample.append(duration) + + npsample = np.array(sample) + + print(f"AVG: {np.mean(npsample)} seconds") + print(f"MEDIAN: {np.median(npsample)} seconds") + +time_measurement(N, SAMPLE_SIZE) \ No newline at end of file diff --git a/tests/stages/generation/out_16.npy b/tests/stages/generation/out_16.npy new file mode 100644 index 0000000..7502530 Binary files /dev/null and b/tests/stages/generation/out_16.npy differ diff --git a/tests/stages/generation/out_32.npy b/tests/stages/generation/out_32.npy new file mode 100644 index 0000000..609251e Binary files /dev/null and b/tests/stages/generation/out_32.npy differ diff --git a/tests/stages/generation/out_64.npy b/tests/stages/generation/out_64.npy new file mode 100644 index 0000000..05c2c8a Binary files /dev/null and b/tests/stages/generation/out_64.npy differ diff --git a/tests/stages/generation/out_8.npy b/tests/stages/generation/out_8.npy new file mode 100644 index 0000000..03ee9a1 Binary files /dev/null and b/tests/stages/generation/out_8.npy differ diff --git a/tests/stages/generation/test.py b/tests/stages/generation/test.py new file mode 100644 index 0000000..5158d78 --- /dev/null +++ b/tests/stages/generation/test.py @@ -0,0 +1,53 @@ +from FFTMA import gen +import numpy as np +import unittest +import time + +def generate(N): + start_time = time.time() + nx, ny, nz = N,N,N + dx, dy, dz = 1.0, 1.0, 1.0 + seed= 1548762 #rdi(10000,99999) + var=1 + vario=2 + alpha=1 + lcx=2 + lcy=4 + lcz=16 + ap1x=1 + ap1y=0 + ap1z=0 + ap2x=0 + ap2y=1 + ap2z=0 + + v1 = (var, vario, alpha, lcx, lcy, lcz, ap1x, ap1y, ap1z, ap2x, ap2y, ap2z) + variograms = [v1] + + mean=15.3245987 + variance=3.5682389 + typ=3 + + k = gen(nx, ny, nz, dx, dy, dz, seed, variograms, mean, variance, typ) + + print(f"Generation with N = {N} time = {time.time() - start_time}s") + return k + + +def test(N): + k = generate(N) + k_correct = np.load(f"out_{N}.npy") + return np.allclose(k, k_correct, rtol=1e-10, atol=1e-10) + +class TestGeneration(unittest.TestCase): + def test_8(self): + self.assertTrue(test(8)) + + def test_16(self): + self.assertTrue(test(16)) + + def test_32(self): + self.assertTrue(test(32)) + + def test_64(self): + self.assertTrue(test(64)) \ No newline at end of file diff --git a/tests/utils/gen_sample.py b/tests/utils/gen_sample.py new file mode 100644 index 0000000..2c11992 --- /dev/null +++ b/tests/utils/gen_sample.py @@ -0,0 +1,32 @@ +from FFTMA import gen +import time + +def generate(N): + start_time = time.time() + nx, ny, nz = N,N,N + dx, dy, dz = 1.0, 1.0, 1.0 + seed= 1548762 #rdi(10000,99999) + var=1 + vario=2 + alpha=1 + lcx=2 + lcy=4 + lcz=16 + ap1x=1 + ap1y=0 + ap1z=0 + ap2x=0 + ap2y=1 + ap2z=0 + + v1 = (var, vario, alpha, lcx, lcy, lcz, ap1x, ap1y, ap1z, ap2x, ap2y, ap2z) + variograms = [v1] + + mean=15.3245987 + variance=3.5682389 + typ=3 + + k = gen(nx, ny, nz, dx, dy, dz, seed, variograms, mean, variance, typ) + + duration = time.time() - start_time + return k, duration \ No newline at end of file