jap*_*edo 5 javascript c fortran lapack emscripten
我的目标是使用LAPACK和Emscripten.
我的问题是:如何将LAPACK移植到JS?这是我能想到的两种方式:CLAPACK到JS我的问题是:有人知道一个晚于3.2.1的非官方版本吗?另一种想法是:如何将FORTRAN移植到JS?
Emscripten能够将C代码转换为JavaScript.但遗憾的是,LAPACK 3.5.0(http://www.netlib.org/lapack/)仅适用于FORTRAN95.
CLAPACK项目(http://www.netlib.org/clapack/)基本上就是我想要的:LAPACK的C版本.但是这个已经过时了; 最新的是3.2.1.
F2C仅适用于FORTRAN 77.LAPACK 3.5.0是用FORTRAN 95编写的.
所以现在我的问题是:为什么没有更新的LAPACK端口到C?
最佳方法是使用clang和emscripten直接将LAPACK的FORTRAN95代码转换为javascript.但我只是不知道从哪里开始.
Emscripten目前不支持FORTRAN.但它处理LLVM bitcode,因此使用clang从FORTRAN文件生成LLVM bc应该不是问题.
出于测试目的,我有这个文件:
program hello
print *, "Hello World!"
end program hello
Run Code Online (Sandbox Code Playgroud)
用"clang hello.f -o hello -lgfortran"编译就好了.我无法将其转换为有效的bitcode.
clang -c -emit-llvm hello.f
clang -S -emit-llvm hello.f -o hello.bc -lgfortran
Run Code Online (Sandbox Code Playgroud)
这些方法都不起作用,因为emscripten一直告诉我
emcc -c hello.o -o hello.js
hello.o is not valid LLVM bitcode
Run Code Online (Sandbox Code Playgroud)
我不确定是否可能这样做,因为LAPACK显然需要libgfortran才能工作.而且我无法将库合并到javascript代码中......
提前致谢!
编辑:
我几乎设法将BLAS从LAPACK 3.5.0转换为JS.我用dragonegg来完成这个.
gfortran caxpy.f -flto -S -fplugin=/usr/lib/gcc/x86_64-linux-gnu/4.6/plugin/dragonegg.so
gfortran cgerc.f ...
...
Run Code Online (Sandbox Code Playgroud)
从中获得LLVM bitcode之后:
emcc caxpy.s.ll cgerc.s.ll cher.s.ll ... -o blas.js -s EXPORTED_FUNCTIONS="['_caxpy_', ... , '_ztpsv_']"
Run Code Online (Sandbox Code Playgroud)
但是emscripten仍然给我留下了以下错误:
warning: unresolved symbol: _gfortran_st_write
warning: unresolved symbol: _gfortran_string_len_trim
warning: unresolved symbol: _gfortran_transfer_character_write
warning: unresolved symbol: _gfortran_transfer_integer_write
warning: unresolved symbol: _gfortran_st_write_done
warning: unresolved symbol: _gfortran_stop_string
warning: unresolved symbol: cabs
warning: unresolved symbol: cabsf
AssertionError: Did not receive forwarded data in an output - process failed?
Run Code Online (Sandbox Code Playgroud)
问题是我认为lgfortran是预编译的.
谢谢您的回复!确实,我确实在这方面取得了进展.最后它正在运作.我非常接近,只需按照以下步骤操作:
gfortran caxpy.f -S -flto -m32 -fplugin=dragonegg.so
mv caxpy.s caxpy.ll
llvm-as caxpy.ll -o caxpy.o
Run Code Online (Sandbox Code Playgroud)
注意我之前错过的"m32"标志.
警告如
warning: unresolved symbol: _gfortran_st_write
Run Code Online (Sandbox Code Playgroud)
可以安全地忽略.Emscripten使用此名称在JavaScript文件中创建空函数,因此如果根本不调用这些函数则没有问题.如果它们被调用,您可以轻松地用自己的功能替换它们; 名字有点描述性.另外,您可以查看libgfortran源代码(请注意它是GPL).
使用此Emscripten源可以手动扩展以支持Fortran文件.总有一天我可以在github上发布这个!