diff --git a/test/makefile b/test/makefile index b02d46b..f889091 100644 --- a/test/makefile +++ b/test/makefile @@ -9,7 +9,6 @@ define uniq = $(foreach _,$1,$(if $(filter $_,${seen}),,$(eval seen += $_))) ${seen} endef -rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d)) # Path setup BLDPATH:=bin @@ -24,21 +23,18 @@ DEBUG:= FC:=emfc.sh CC:=emcc WLD:=emcc -FCFLAGS:=$(DEBUG) $(OPT) -Wall -I$(BLDPATH) +FCFLAGS:=$(DEBUG) $(OPT) -Wall -I$(BLDPATH) -I$(BLDPATH)/lapack_test CCFLAGS:=$(DEBUG) --target=wasm32-unknown-emscripten $(OPT) -c -flto -emit-llvm -m32 -Isrc -Wall EMSFLAGS:=$(OPT) $(DEBUG) -m32 --cache /project/bin/.emscripten_cache -Wall -flto -WLDFLAGS:=-s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]' -s MODULARIZE=1 -s ERROR_ON_UNDEFINED_SYMBOLS=1 +WLDFLAGS:=-s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]' -s MODULARIZE=1 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -s USE_SDL=2 -s LEGACY_GL_EMULATION=1 # Project config NAME:=assembly -EXPORTS:=test_MOD_add test_MOD_eigen -# EXPORTS:=test_MOD_add -LIBS:=/app/lib/libgfortran.a /app/lib/liblapack.a -# /app/lapack/librefblas.a -# LIBS:= +EXPORTS:=test_MOD_add lapack_prb_MOD_lapack_prb_main test_eigen_MOD_test_eigen_main +LIBS:=/app/lib/libgfortran.a /app/lib/liblapack.a /app/lib/librefblas.a EXPORTSD:=$(EXPORTS:%="___%") -EXPORTFLAGS:=-s LINKABLE=1 -s EXPORT_ALL=1 -# EXPORTFLAGS:=-s EXPORTED_FUNCTIONS='[$(subst $(space),$(comma),$(strip $(EXPORTSD)))]' +# EXPORTFLAGS:=-s LINKABLE=1 -s EXPORT_ALL=1 +EXPORTFLAGS:=-s EXPORTED_FUNCTIONS='[$(subst $(space),$(comma),$(strip $(EXPORTSD)))]' # Define sources and dependencies # IOlib @@ -46,11 +42,11 @@ FSRCS_IOLIB:=$(SRCPATH)/iolib/iolib.f90 CSRCS_IOLIB:=$(SRCPATH)/iolib/iolib.c MOD_IOLIB:=$(CSRCS_IOLIB:$(SRCPATH)/%=$(BLDPATH)/%.bc) # User project files -FSRCS_USER:=$(SRCPATH)/test.f90 $(SRCPATH)/test_eigen.f90 +FSRCS_USER:=$(SRCPATH)/test.f90 $(SRCPATH)/lapack_test/test_eigen.f90 $(SRCPATH)/lapack_test/lapack_prb.f90 CSRCS_USER:= -MOD_USER:=$(BLDPATH)/test.f90.bc +MOD_USER:= # Define dependencies -$(FSRCS_USER): $(MOD_IOLIB) $(BLDPATH)/test_eigen.f90.bc +$(FSRCS_USER): $(MOD_IOLIB) # Aggregate sources FSRCS:=$(FSRCS_IOLIB) $(FSRCS_USER) CSRCS:=$(CSRCS_IOLIB) $(CSRCS_USER) diff --git a/test/src/lapack_prb.f90 b/test/src/lapack_test/lapack_prb.f90 similarity index 99% rename from test/src/lapack_prb.f90 rename to test/src/lapack_test/lapack_prb.f90 index 9d0069b..7d28827 100644 --- a/test/src/lapack_prb.f90 +++ b/test/src/lapack_test/lapack_prb.f90 @@ -1,3 +1,5 @@ +module lapack_prb + contains subroutine lapack_prb_main !*****************************************************************************80 @@ -56,7 +58,6 @@ subroutine lapack_prb_main write ( *, '(a)' ) ' ' call timestamp ( ) - stop end subroutine subroutine test01 ( ) @@ -325,7 +326,7 @@ subroutine test03 ( ) ! ! Compute the L-Infinity norm of the matrix. ! - anorm = r8mat_norm_li ( n, n, a ) + anorm = r8mat_norm_li_func ( n, n, a ) write ( *, '(a)' ) ' ' write ( *, '(a,g14.6)' ) ' Matrix L-infinity norm is ', anorm @@ -2209,7 +2210,7 @@ subroutine dgeqrs ( m, n, nrhs, a, lda, tau, b, ldb, work, lwork, info ) return end - function r8mat_norm_li ( m, n, a ) + function r8mat_norm_li_func ( m, n, a ) !*****************************************************************************80 ! @@ -2258,12 +2259,12 @@ function r8mat_norm_li ( m, n, a ) real ( kind = 8 ) a(m,n) integer ( kind = 4 ) i - real ( kind = 8 ) r8mat_norm_li + real ( kind = 8 ) r8mat_norm_li_func - r8mat_norm_li = 0.0D+00 + r8mat_norm_li_func = 0.0D+00 do i = 1, m - r8mat_norm_li = max ( r8mat_norm_li, sum ( abs ( a(i,1:n) ) ) ) + r8mat_norm_li_func = max ( r8mat_norm_li_func, sum ( abs ( a(i,1:n) ) ) ) end do return @@ -2681,4 +2682,4 @@ subroutine timestamp ( ) return end - \ No newline at end of file + end module \ No newline at end of file diff --git a/test/src/test_eigen.f90 b/test/src/lapack_test/test_eigen.f90 similarity index 99% rename from test/src/test_eigen.f90 rename to test/src/lapack_test/test_eigen.f90 index 699357f..39b0378 100644 --- a/test/src/test_eigen.f90 +++ b/test/src/lapack_test/test_eigen.f90 @@ -40,8 +40,6 @@ subroutine test_eigen_main() write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) ' ' call timestamp ( ) - - stop 0 end subroutine r8symm_gen_test ( ) diff --git a/test/src/test.f90 b/test/src/test.f90 index fdcd51d..89c5d03 100644 --- a/test/src/test.f90 +++ b/test/src/test.f90 @@ -1,8 +1,6 @@ module test use iolib - use test_eigen - use, intrinsic :: iso_c_binding implicit none @@ -12,85 +10,10 @@ function add(a, b) result(res) integer, value, intent(in) :: a, b integer :: res - real :: foo - integer :: test + write(*,*) "Hello from Fortran!" + call iolib_write("Hello from Fortran via libc!"//char(10)) - ! real, dimension(100) :: x, y - ! ! real, dimension(100) :: p, q - ! integer :: i, fpid - - ! fpid = 42 - - ! ! data - ! do i=1,100 - ! x(i) = i * 0.1 - ! y(i) = sin(x(i)) * (1-cos(x(i)/3.0)) - ! end do - - ! write(*,*) "before write" - - ! ! output data into a file - ! open(fpid, file = 'data1.dat', status = 'new') - ! do i=1,100 - ! write(fpid,*) x(i), y(i) - ! end do - - ! close(fpid) - - ! write(*,*) "after write" - ! write(*,*) "hallo welt tada", 12, (/ 12.5, 14.5 /) - - ! call iolib_write("Hello from Fortran!"//char(10)) - ! test = iolib_test(5) - ! call iolib_printf("test int: 0x%x"//char(10), test) - - ! call iolib_printf("a float: %f"//char(10), 144523.4556) - ! call iolib_printf("a double: %f"//char(10), 123.456) - ! call iolib_printf("a 64bit int: %lld"//char(10), 21474836471234567_c_int64_t) - call test_eigen_main() - ! call lapack_prb_main() - - res = a * b + int(sin(foo) * 12.5) + res = a * b + iolib_test(a) end function - ! function eigen() result(res) - ! integer :: res - ! ! Source: http://sites.science.oregonstate.edu/~landaur/nacphy/lapack/codes/eigen-f.html - ! ! finding the eigenvalues of a complex matrix using LAPACK declarations, notice double precision - ! ! dont notice it tho cus wasm32 is shite m9 - ! complex*8 A(3,3), b(3), DUMMY(1,1), WORK(6) - ! integer i, ok - ! ! define matrix A - ! A(1,1)=(3.1, -1.8) - ! A(1,2)=(1.3, 0.2) - ! A(1,3)=(-5.7, -4.3) - ! A(2,1)=(1.0, 0) - ! A(2,2)=(-6.9, 3.2) - ! A(2,3)=(5.8, 2.2) - ! A(3,1)=(3.4, -4.0) - ! A(3,2)=(7.2, 2.9) - ! A(3,3)=(-8.8, 3.2) - - ! ! find the solution using the LAPACK routine ZGEEV - ! call CGEEV('N', 'N', 3, A, 3, b, DUMMY, 1, DUMMY, 1, WORK, 6, WORK, ok) - - ! ! parameters in the order as they appear in the function call - ! ! no left eigenvectors, no right eigenvectors, order of input matrix A, - ! ! input matrix A, leading dimension of A, array for eigenvalues, - ! ! array for left eigenvalue, leading dimension of DUMMY, - ! ! array for right eigenvalues, leading dimension of DUMMY, - ! ! workspace array dim>=2*order of A, dimension of WORK - ! ! workspace array dim=2*order of A, return value - - ! ! output of eigenvalues - ! if (ok .eq. 0) then - ! do i=1, 3 - ! write(*,*) b(i) - ! enddo - ! else - ! write (*,*) "An error occured" - ! endif - ! res = 0 - ! end function - end module diff --git a/test/static/index.html b/test/static/index.html index c4bfdcc..fc685f3 100644 --- a/test/static/index.html +++ b/test/static/index.html @@ -11,7 +11,10 @@ module.onRuntimeInitialized = _ => { const add = module.cwrap('__test_MOD_add', 'number', ['number', 'number']); console.log("call from javascript: " + add(5, 7)); - module.ccall('__test_MOD_eigen', null, []); + console.log("Calling lapack_prb"); + module.ccall('__lapack_prb_MOD_lapack_prb_main', null, []); + console.log("Calling test_eigen"); + module.ccall('__test_eigen_MOD_test_eigen_main', null, []); }; diff --git a/tools/f90wasm/Dockerfile b/tools/f90wasm/Dockerfile index 5cbb248..eed0f07 100644 --- a/tools/f90wasm/Dockerfile +++ b/tools/f90wasm/Dockerfile @@ -33,10 +33,12 @@ RUN cd gcc-build && \ ./patch.sh && \ make -j$(nproc) build -# lapack +# lapack and blas RUN git clone --depth=1 https://github.com/Reference-LAPACK/lapack.git COPY vendor/LAPACK/make.inc lapack/make.inc RUN cd lapack/SRC && \ + emmake make -j$(nproc) single double && \ + cd ../BLAS/SRC && \ emmake make -j$(nproc) single double