Skip to content

Commit

Permalink
move tests, add BLAS
Browse files Browse the repository at this point in the history
  • Loading branch information
StarGate01 committed Apr 21, 2020
1 parent 9fe2159 commit 727d7e8
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 104 deletions.
22 changes: 9 additions & 13 deletions test/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,33 +23,30 @@ 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
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)
Expand Down
15 changes: 8 additions & 7 deletions test/src/lapack_prb.f90 → test/src/lapack_test/lapack_prb.f90
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module lapack_prb
contains
subroutine lapack_prb_main

!*****************************************************************************80
Expand Down Expand Up @@ -56,7 +58,6 @@ subroutine lapack_prb_main
write ( *, '(a)' ) ' '
call timestamp ( )

stop
end subroutine
subroutine test01 ( )

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
!
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2681,4 +2682,4 @@ subroutine timestamp ( )

return
end

end module
Original file line number Diff line number Diff line change
Expand Up @@ -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 ( )

Expand Down
83 changes: 3 additions & 80 deletions test/src/test.f90
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module test

use iolib
use test_eigen
use, intrinsic :: iso_c_binding

implicit none

Expand All @@ -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
5 changes: 4 additions & 1 deletion test/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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, []);
};
</script>
</body>
Expand Down
4 changes: 3 additions & 1 deletion tools/f90wasm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 727d7e8

Please sign in to comment.