使用Emscripten与Fortran语言:LAPACK结合 [英] Use Emscripten with Fortran: LAPACK binding

查看:486
本文介绍了使用Emscripten与Fortran语言:LAPACK结合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是使用LAPACK与Emscripten。

My goal is to use LAPACK with Emscripten.

我的问题是:如何移植到LAPACK JS?该两种方式我能想到的:CLAPACK到JS那里我的问题是:没有任何人知道一个非官方的版本是晚于3.2.1?而另一种方式去思考的是:如何移植到FORTRAN JS

My question is: how to port LAPACK to JS? The are two ways I can think of: CLAPACK to JS where my question is: does anybody know an unofficial version that is later than 3.2.1? And the other way to think of is: how to port FORTRAN to JS?

Emscripten能够转化C code到的JavaScript。但不幸的是,LAPACK 3.5.0( http://www.netlib.org/lapack/ )仅在FORTRAN95用。

Emscripten is capable of transforming C code to JavaScript. But unfortunately, LAPACK 3.5.0 (http://www.netlib.org/lapack/) is only available in FORTRAN95.

该项目CLAPACK( http://www.netlib.org/clapack/ )基本上是我想要的东西:一个C版LAPACK的。但是,这一次是过时的;最新的是3.2.1。

The CLAPACK project (http://www.netlib.org/clapack/) is basically what I want: a C version of LAPACK. But this one is outdated; the latest is 3.2.1.

F2C只能达到Fortran 77中LAPACK 3.5.0写在FORTRAN 95。

F2C only works up to FORTRAN 77. LAPACK 3.5.0 was written in FORTRAN 95.

所以,我现在的问题是:为什么会出现LAPACK的为C没有新的端口?

So my question now is: why is there no newer port of LAPACK to C?

最佳的方法是直接将LAPACK的FORTRAN95 code到JavaScript的铿锵和emscripten。但我只是不知道从哪里开始。

The optimal way would be to directly transform the FORTRAN95 code of LAPACK to javascript with clang and emscripten. But I just don't know where to start.

Emscripten目前不支持FORTRAN。但它处理LLVM位code,所以它不应该是使用铛从FORTRAN文件生成LLVM BC的一个问题。

Emscripten currently does not support FORTRAN. But it handles LLVM bitcode, so it should not be a problem to use clang to generate LLVM bc from a FORTRAN file.

有关测试目的,我有这个文件:

For testing purpose, I have this file:

      program hello
      print *, "Hello World!"
      end program hello

它编译只是罚款铛hello.f -o你好-lgfortran。我不能够转变成有效位code这一点。

It compiles just fine with "clang hello.f -o hello -lgfortran". I am not capable of transforming this into valid bitcode.

clang -c -emit-llvm hello.f      
clang -S -emit-llvm hello.f -o hello.bc -lgfortran

这些方法都没有奏效,因为emscripten不断告诉我

None of these approaches works, because emscripten keeps telling me

emcc -c hello.o -o hello.js
hello.o is not valid LLVM bitcode

我不知道,反正,如果这会更可能的,因为LAPACK显然需要libgfortran工作。我不能合并库为JavaScript code ...

I am not sure anyways if this would be even possible, because LAPACK obviously needs libgfortran to work. And I can't merge a library into javascript code...

在此先感谢!

编辑:

我几乎设法它BLAS LAPACK从3.5.0转换为JS。我用dragonegg做到这一点。

I almost managed it to convert BLAS from LAPACK 3.5.0 to JS. I used dragonegg to accomplish this.

gfortran caxpy.f -flto -S -fplugin=/usr/lib/gcc/x86_64-linux-gnu/4.6/plugin/dragonegg.so 
gfortran cgerc.f ...
...

从获得LLVM位code之后:

After gaining LLVM bitcode from that:

emcc caxpy.s.ll cgerc.s.ll cher.s.ll ... -o blas.js -s EXPORTED_FUNCTIONS="['_caxpy_', ... , '_ztpsv_']"

但仍然emscripten让我有以下错误:

But emscripten still leaves me with the following errors:

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?

问题是,lgfortran是precompiled我想。

The problem is that lgfortran is precompiled I think.

推荐答案

感谢您的回复!
事实上,我没有就这个进展。最后,这是工作。我非常接近,只要按照下列步骤操作:

Thank you for your reply! Indeed I did make progress on this. Finally it is working. I was very close, just follow these steps:

gfortran caxpy.f -S -flto -m32 -fplugin=dragonegg.so
mv caxpy.s caxpy.ll
llvm-as caxpy.ll -o caxpy.o

请注意了M32标志,我之前错过了。

Note the "m32" flag which I missed earlier.

警告像

warning: unresolved symbol: _gfortran_st_write

可以安全地忽略。 Emscripten会在JavaScript的空函数与此文件的文件名,所以如果这些功能不叫都没有问题。如果他们被调用,您可以轻松地与您自己的函数替换他们。名字有些描述。另外,你可以看看在libgfortran源$ C ​​$ C(要知道这是GPL)。

can be ignored safely. Emscripten creates empty functions in the JavaScript file with this name so if these functions are not called at all there is no problem. If they get called you can easily substitute them with your own functions; the names are somewhat descriptive. Additionally you can have a look at the libgfortran source code (be aware it is GPL).

有了这个Emscripten源可以用手扩展,以支持Fortran文件。有一天,我可能会发布这个在GitHub上!

With this Emscripten source can be extended by hand to support Fortran files. Someday I may publish this on github!

这篇关于使用Emscripten与Fortran语言:LAPACK结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆