悲催的科学匠人 - 冷水's blog
fortran数组shape和范围的转换
http://chasm-interop.sourceforge.net/
http://software.intel.com/en-us/forums/showthread.php?t=40376&wapkw=%28%2Bfortran...%29
http://coding.derkeiler.com/Archive/Fortran/comp.lang.fortran/2004-06/0500.html
http://publib.boulder.ibm.com/infocenter/cellcomp/v9v111/index.jsp?topic=/com.ibm.xlf111.cell.doc/xlflr/f90pass.htm
gfortran 4.5不行, ifort 12可以
program tt use iso_c_binding implicit none integer,target :: a(100),n,i,j integer,pointer,dimension(:) :: ptr integer,pointer,dimension(:,:) :: p2d,p2d2 type(c_ptr) :: cptr do n=1,100; a(n)=n;enddo ptr(0:29) => a(71:100) write(*,*) ptr p2d2(0:9,0:9) => a do j=0,9;do i=0,9 write(*,*) i,j,p2d2(i,j) enddo;enddo end
指针类型转换
采用fortran 2003标准iso_c_binding模块完成
program test
use iso_c_binding
implicit none
interface getptr
function fgetptr(string,ilen,ni,nj)
use iso_c_binding
implicit none
real,pointer,dimension(:,:) :: fgetptr
integer :: ilen,ni,nj
character ::string(ilen)
end function
function ggetptr(string,ilen,irank,ishape)
use iso_c_binding
implicit none
real,pointer,dimension(:,:) :: ggetptr
integer :: ilen,irank
integer :: ishape(irank)
character ::string(ilen)
end function
function hgetptr(string,ilen,ishape)
use iso_c_binding
implicit none
real,pointer,dimension(:,:) :: hgetptr
integer :: ilen
integer,dimension(:) :: ishape
character ::string(ilen)
end function
end interface
interface
function getchar(string)
character,pointer,dimension(:) :: getchar,string
end function
end interface
type(c_ptr) :: p
!character,target :: string(400)
character,pointer,dimension(:) :: string,pp
real,pointer,dimension(:,:) :: idata
integer :: ishape(2)
ishape(1) = 25
ishape(2) = 4
allocate(string(400))
call convt1(string, 25,4,idata)
write(*,*) '============================='
idata => fgetptr(string,400,25,4)
write(*,*) idata
write(*,*) '============================='
idata => ggetptr(string,400,2,ishape)
write(*,*) idata
write(*,*) '============================='
idata => getptr(getchar(string),400,ishape)
write(*,*) idata
end
function getchar(string)
character,pointer,dimension(:) :: getchar,string
getchar => string
end function
function fgetptr(string,ilen,ni,nj)
use iso_c_binding
implicit none
real,pointer,dimension(:,:) :: fgetptr
integer :: ilen,ni,nj
character ::string(ilen)
!
type(c_ptr) :: p
write(*,*) size(string)
p = c_loc(string)
CALL c_f_pointer(p,fgetptr,(/ni,nj/))
end function
function ggetptr(string,ilen,irank,ishape)
use iso_c_binding
implicit none
real,pointer,dimension(:,:) :: ggetptr
integer :: ilen,irank
integer :: ishape(irank)
character ::string(ilen)
!
type(c_ptr) :: p
write(*,*) size(string)
p = c_loc(string)
CALL c_f_pointer(p,ggetptr,ishape)
end function
function hgetptr(string,ilen,ishape)
use iso_c_binding
implicit none
real,pointer,dimension(:,:) :: hgetptr
integer :: ilen
integer,dimension(:) :: ishape
character ::string(ilen)
!
type(c_ptr) :: p
integer :: irank
irank = size(shape(hgetptr))
write(*,*) size(string),irank
p = c_loc(string)
CALL c_f_pointer(p,hgetptr,ishape(1:irank))
end function
subroutine convt1(odata, ni,nj,tdata)
implicit none
integer :: ni,nj
real,target :: odata(ni,nj)
real,pointer,dimension(:,:) :: tdata
integer :: i,j
real :: n
n=1.
do j=1,nj
do i=1,ni
odata(i,j) = n
n=n+1.
enddo
enddo
return
end subroutine
101-Loci框架的编译
需要安装如下的库
1 petsc-2.3.3-p13-02
2 openmpi
3 sundials-2.3.0
export PETSC_DIR=/opt/petsc-2.3.3-p13-02
export PETSC_ARCH=linux-gnu-c-opt
export PATH=/opt/Loci/Loci-Linux-x86_64-mpic++-rel-3-2-beta-12:$PATH
export LD_LIBRARY_PATH=/opt/sundials-2.3.0/lib:/opt/Loci/Loci-Linux-x86_64-mpic++-rel-3-2-beta-12/lib:$LD_LIBRARY_PATH
Bird-Meertens Formalism
设计与实现分离
自动化实现
设计规则,不考虑实现效率
规则是局部的,不必定义全局的执行规则
规则是相互依赖的,隐式的构成一个全局执行规则
相互依赖的规则被BFM自动连接成为规则图
规则图可进行变形和优化,而具有各种不同的执行效率,但是基础规则相同
设计人员的关注点从错综复杂的全局设计中解放
搞定局部则全局搞定!