g***i 发帖数: 90 | 1 有很多函数的
f77下(应该)可以
program when
integer*4 today(3), now(3)
call idate(today) ! today(1)=day, (2)=month, (3)=year
call itime(now) ! now(1)=hour, (2)=minute, (3)=second
write ( *, 1000 ) today(2), today(1), today(3), now
1000 format ( 'Date ', i2.2, '/', i2.2, '/', i4.4, '; time ',
& i2.2, ':', i2.2, ':', i2.2 )
stop
end
f90下:date_and_time()
这里是一个例子:输出当前一时间点(有点象cputime)
subroutine comp_time(tm)
real*16 tm
|
|
b*****y 发帖数: 163 | 2 You can use subroutines in CLAPACK.
Dense LS-problem is usually solved using:
1. Normal equation
2. QR factorization
3. SVD |
|
g***i 发帖数: 90 | 3 finally got some algorithm and programmed in fortran
using lapack. but it turns out that the block CG doesn't
work well
here is the program if someone is interested:
subroutine bcg(A,B,X,n,r,eps,kmax)
implicit none
integer n,r,k,kmax,i,j,INFO,LWORK
real(8) A(n,n),B(n,r), X(n,r), R0(n,r), D0(r,r), D1(r,r), &
Al(r,r), Be(r,r), P(n,r), &
Q(n,r), RR(r,r), IPIV(r), NR(n,r), &
eps,errm,err(r),err0(r)
real(8), dimen |
|
s*****l 发帖数: 167 | 4 Thanks guys!
But suppose that you have quite a few variables
and probably one of them has the same name as
another in the main program, it could be dangerous.
I guess I better off writing a module to gather all
the subroutines.
There is no way to claim LOCAL variable? |
|
n**a 发帖数: 9 | 5 Anyone can help me on this?
I need to use a fortran 77 subroutine in matlab. But i do not know much about
interface and mex....
so can anybody give me an example or something related
thanks |
|
g***i 发帖数: 90 | 6 //copied from matlab
A First Example -- Passing a ScalarLet's look at a simple example of Fortran
code and its MEX-file equivalent. Here is a Fortran computational routine t
hat takes a scalar and doubles it. subroutine timestwo(y, x)
real*8 x, y
C
y = 2.0 * x
return
end
Below is the same function written in the MEX-file format. C================
==============================================
=
C timestwo.f
C Multiply the input argument by 2.
C
C This is |
|
w*w 发帖数: 3 | 7 I ever tested this for a small program. No big difference. |
|
s*****r 发帖数: 9 | 8 Fortran is not C,
So there is almost no overhead for pass arguments.
All arguments are passed by address. |
|
s*****r 发帖数: 9 | 9 The compiler will treat almost everything subroutine as inline functions in
Fortran.
-O0 should give smaller executable.
Or you can try f2c and then use a c compiler. |
|
i******t 发帖数: 127 | 10 what if writing user subroutines to describe the relationship |
|
y***r 发帖数: 1845 | 11 不用cray pointer也可以,可以使用libU77中的MALLOC和FREE,可惜不是所有系统都
支持。但假如自己用C做一个EXTENSION,就可以了。
下面的程序的编译方法:
cc -c alloc.c
f77 memtest.f alloc.o
>>>>>>> memtest.f <<<<<<<<<<<
implicit none
integer*4 n, i
integer*4 addr
integer*4 offset
real*8 work(1)
C common /works/ work
n = 10
call cmalloc(N*N, 8, 0, work, addr, offset)
call test(N, WORK(offset+1))
call cfree(addr)
end
C
subroutine test(N,R)
implicit none
integer*4 |
|
t****n 发帖数: 39 | 12 Well, I wrote a code myself, with a house-cooked matrix manipulation
subroutine. Recently I tried the Intel Math Kernel's BLAS and LAPACK
souboutine. Unfortunately, no gain. |
|
S***y 发帖数: 186 | 13 I think most optimizations turn out to be the efficient use of the CACHE.
So, knowing the cache structure of a specific machine is the starting point.
If not an expert, I think it would be better trying not to spend too much
time on this. Trust the optimization options of the compilers, such as
-O, -arch, -tp ... They really help.
Another point, try to call optimized library subroutines whenever possible,
such as, linear algebric manipulations, fast Fourier transforms ...
Profile utilities are a |
|
t*****o 发帖数: 74 | 14 using FFT
it should be a standard scientific subroutine avaible at each workstation or
supercomputer
in |
|
S***y 发帖数: 186 | 15 mpif77, mpif90 ... are just so-called "wrapper" compiler.
They are practically not "real" compilers.
They need to call some background Fortran compilers to
carry out a complete compilation.
So, when installing the MPI, if the mpif77 is linked to
a Fortran90 compiler, such as pgf90 under Linux,
even mpif77 can compiler Fortran 90 programs in which
the MPI subroutines are called. |
|
s*****l 发帖数: 167 | 16 mpich,
my program is rather simple: send Ns independent subroutines to each node, and
collect them
afterwards, and there is no communications between them until they are
finished.
program
each
and
also |
|
p*w 发帖数: 124 | 17 all unlimited. I kind of feel I may exceed some boudary but use big
matrix in common block.
I have thought all subroutines share the same common block variable,
maybe I am wrong? Need test it. |
|
x*y 发帖数: 364 | 18 It's weird. I also have array declared as a(0:node) and passed around several
subroutines. It works fine on sun machine.
probelm |
|
l**g 发帖数: 5 | 19 "If a program gets a bus error (SIGBUS), it usually has some problems with
misaligned data."
可能是caller传递的数组的类型和subroutine中的数组a的类型不一致引起的。
比如说前者是byte,a是word.如果a(i)的地址没对齐成奇数就有bus error。
这大概是自动数组a(0:node)和a(1:node)结果不同的原因。
去年为什么可以?也许今年f77升级,default不一样了;
或者有其它影响complier行为的原因。参考:
Bus Error--Finding the Line Number
http://docs.sun.com/db/doc/802-2997/6i6u2n7rt?a=view#07.Debugging-27
several |
|
h***o 发帖数: 539 | 20 有个程序在sun下面用f77编得好好得,放到linux下面用g77就报错了
amie.f: In subroutine `genpnm':
amie.f:356:
REAL*16 PNMD,DPNMDTD,PNME,DPNMDTE,AK,AKE
1 2
Invalid kind at (2) for type at (1) -- unsupported or not permitted
请问这玩艺怎么修改?
谢了 |
|
x*y 发帖数: 364 | 21 If there's segment fault, then there must be some inappropriate point in the
code. Unix can discard some trivial inappropriate points while linux can't, so
you'd better track to the point to fix it. You might check if there's array
that exceeds it's dimension, if the passed variables between subroutines match
or not, etc. |
|
w*****g 发帖数: 47 | 22 How to make draws which follow multivariate normal distribution? used the
subroutine to decompose the covariance matrix into cholesky factor. but can
not guarantee the matrix is positive definite. is all covariance matrix
positive definite? |
|
s*****l 发帖数: 167 | 23 I have a simple MPI-Fortran 90 program and I want each individual
to write data to a different file: so I am expecting:
processor 1 to pos001.dat
processor 2 to pos002.dat
... ...
So I convert the rank to a string by subroutine 'num2str' then
put it in the filename. But strangely I always have some files missing.
I might have all the file pos001.dat to pos020.dat except pos003.dat
Can anyone tell me what is wrong. Is there a better way to deal with
situation?
|
|
h***o 发帖数: 539 | 24 subroutine RefineGrid(a, b, c, d)
...
...
call RefineGrid(a1, b1, c1, d1)
...
...
end
行吗? |
|
s*****l 发帖数: 167 | 25 f90 allows pointer and recursive subroutines (I never used them)
you can also use module.
There may have been some improvement on matrix
operation. |
|
x*y 发帖数: 364 | 26 I need to implement CSC format matrix + another CSC format matrix which has
same row and column sizes. Does anybody know if there exists any subroutine
that can realize this? Thanks |
|
b********e 发帖数: 109 | 27 我在Fortran PowerStation 4 下使用一个程序,发现不能debug,可以设置断点,但是程
序并不停。于是考虑移植到Visaul Fortran 6.6下,发现可以调试,也可以编译通过,但
是执行是却遇到stack overflow的问题,后来发现是一个子程序的数组定义有问题,但是
在Powerstation4 下却可以执行。那个子程序数组定义如下:
SUBROUTINE GHMAT7(NE,CONE,TUINV,TDLDA)
COMPLEX TUINV(NROWS,NROWS),TDLDA(NROWS)
INTEGER CONE(NE,4),VB_ID
COMMON N,NP,INP,IPR,ITX
COMMON /GEOMET/NROWS,NCOLM
结果发现程序运行到第一行和第二行是均发现溢出,为什么Powerstation中可以通过运
行呢?
BTW, NROWS值为600。 |
|
S***y 发帖数: 186 | 28
直接返回数组没那么直接,要用到F90的东西。
可是我自己认为没必要非要用function,
Fortran里还有个东西叫subroutine。
Program testing
real A(2,2),B(2,2)
A(1,1)=0.0
A(1,2)=1.0
A(2,1)=-1.0
A(2,2)=0.0
1000 Format('Matrix A:')
1100 Format('Transpose of Matrix A:')
Write(*,1000)
Write(*,'(2F5.1)') A(1,1),A(1,2)
Write(*,'(2F5.1)') A(2,1),A(2,2)
Call Transpose(A,B)
Write(*,1100)
Write(*,'(2F5.1)') B(1,1),B(1,2)
Write(*,'(2F5.1)') B(2,1),B(2,2)
End
Subrouti |
|
b*****h 发帖数: 25 | 29 【 以下文字转载自 Mathematics 讨论区,原文如下 】
发信人: benhigh (benhigh), 信区: Mathematics
标 题: 偶看不懂这道linear programming题目叫俺干吗?
发信站: Unknown Space - 未名空间 (Wed Oct 13 16:01:16 2004) WWW-POST
题目如下:
The purpose of this problem is to show that solving linear programming
problems is no harder than solving systems of linear inequalities.
Suppose that we are given a subroutine which, given a system of linear
inequality constraints, either produces a solution or decides that no solution
exists. Construct a simple algori |
|
r**********e 发帖数: 28 | 30 Hi,
I am in troubles to figure out a correct mex-file to call a Fortran
code. I made a code is named as test_mex.f to test the process of
mex, but it won't work at all. Here is my code. Could someone please
take a look and help me out of this.
subroutine mexFunction(prhs, nrhs, plhs, nlhs)
integer prhs(*), plhs(*)
integer nrhs, nlhs ! pointer between Matlab and For
integer mxGetPr, mxCreateDoubleMatrix
integer x1_pr, x2_pr, y_pr
real*8 x1, x2, y
C------------------------------------------ |
|
l*******G 发帖数: 1191 | 31 sigh,,you should use your own random number generator,, otherwise, your code
is not portable coz it depends on compiler.. Here are two codes copied from
ROMS model:
SUBROUTINE nrng (ix, a, n, ierr)
!
!=======================================================================
! !
! Gaussian random-number generator from the NSWC Library. It calls !
! the NSWC uniform random-number generator, URNG. !
! |
|
t*******y 发帖数: 637 | 32 确实方便一些
一般用subroutine用的多得多吧 |
|
t***l 发帖数: 533 | 33 一般复杂的用subroutine,
简单的用function。
对于返回简单值,频繁使用的时候
function用起来简单一点 |
|
c****w 发帖数: 565 | 34 没事的时候作了一个IMSL的例子玩,是BCLSF函数。完全按照它给的例子写的代码,然
后run,结果是和例子一样的。我在ROSBCK subroutine里面加了个counter, start
from 0,然后再主程序里,再把这个counter给打印出来(也就是进行完BCLSF优化后)
,发现counter=52,而例子里的number of iteration =15, number of function
evaluation = 20。我有点晕。。。 |
|
l******n 发帖数: 9344 | 35 module XXX(name you like)
contains
all you subroutine here
end module
Then ok |
|
m********n 发帖数: 71 | 36 问题解决了, 还是用的subroutine, 呵呵
谢谢longtian! |
|
O******e 发帖数: 734 | 37 If you really need to handle general signals using native Fortran,
you will need a compiler that supports the PXFSIG* subroutines
defined in the POSIX Fortran binding standard IEEE 1003.9-1992.
It might be easier to use mixed Fortran/C++ compilation to do
what you want, if your compiler supports mixed language calling.
If you only want to deal with numerical exceptions, check whether
your compiler supports the Fortran 2003 ieee_exceptions intrinsic
module. |
|
m******2 发帖数: 4 | 38 Or try SVD based algorithm. Matlab has subroutines for it. |
|
O******e 发帖数: 734 | 39
For
This depends on the Abaqus user Fortran interface. Check their
documentation.
If you already have programming experience in some other language such as
C/C++ and you are good at it, I would suggest that you use Numerical Recipes
as a reference because there are a lot of practical examples given in the
book, and you can cross-reference the C, C++, Fortran 77, and Fortran 95
editions (the same function/subroutine written in four different languages).
The "Fortran 77 Explained", "Fortran 90/9 |
|
g********d 发帖数: 4174 | 40 对FORTRAN不熟,请教各位:
我想用别人写的一个程序,里面有用genunf,gennor gengam来generate random
numbers from uniform, normal and gamma distribution.但是我得到“unresolved
external symbol"的错误,这是为什么? FORTRAN里没有这些function吗?
我以前用过IMSL STAT/LIBRARY里的subroutines (RNUNF, RNNOR, RNGAM),可以。但我
尽量不想改现成的程序。
谢谢。 |
|
g********d 发帖数: 4174 | 41 Thank you so much for your anwser.
It seems that I will have to replace the functions with the subroutines in
IMSL libraries.
generator
distribution
is |
|
l******n 发帖数: 9344 | 42 you do not use the fftw right, the compilor could not fined the definition
of fftw subroutines
check your makefile and directory of fftw3.la
destroy |
|
h*******s 发帖数: 11 | 43 I don't think there is a general way to retain the
symbolic name of a parameter constant--the value of
constant is resolved at compile time and the name is
lost forever. Even if you save the value of a parameter
in a regular variable, as in the example I gave above
using n_gdb, if you do not actually use n_gdb in your
program, the Fortran compiler could optimize away
n_gdb and you would lose the hook to peek at the value
of n in the debugger.
Another way might be to include a subroutine that
co |
|
j**u 发帖数: 6059 | 44 藕的博士论文程序只用了4个左右的很简短的subroutine,就完成了“并行计算”,效
果是:8个processors,速度是8倍;
这个是你写的还是转贴的?很有意思.开始我还以为你自己开发了并行计算的东西,结果
还是用的mpi。其实那些程序用fortran一样很容易实现,不知道贴这个对你想说明的观
点有什么作用?另外你的speedup最高,是因为processor之间的commonication很少,这
个和语言没有任何关系,是和你的问题直接相关的。
10 |
|
j**u 发帖数: 6059 | 45 藕的博士论文程序只用了4个左右的很简短的subroutine,就完成了“并行计算”,效
果是:8个processors,速度是8倍;
这个是你写的还是转贴的?很有意思.开始我还以为你自己开发了并行计算的东西,结果
还是用的mpi。其实那些程序用fortran一样很容易实现,不知道贴这个对你想说明的观
点有什么作用?另外你的speedup最高,是因为processor之间的commonication很少,这
个和语言没有任何关系,是和你的问题直接相关的。
10 |
|
x********g 发帖数: 47 | 46 我有如下程序,但是编译出错,请高手指教:
subroutine intensity(m_int, res, px, py, k, int_i, scatfact_e, istat)
!USE, intrinsic :: iso_c_binding
USE MPI_C_BINDING !mpi
IMPLICIT NONE
type(model), intent(in) :: m_int
real, intent(in) :: res, px, py
real, dimension(nk), intent(in) :: k
real, dimension(nk), intent(out) :: int_i
real, dimension(:,:), pointer, intent(in) :: scatfact_e
integer, intent(out) :: istat
! C-compatible variables for the model data
integer(C_INT), dimen |
|
j**f 发帖数: 7403 | 47 假如,主程序中调用了 call suba(a, b, c, na, nb, nx) 一共6个变量,
分别为REAL,INT等类型。
而子程序的动议里 subroutine suba(a,b,na,nb,nx)和主程序不对应,差一点点。
怎么样,能让系统自动的告诉我出错?好像我的程序不告诉我出错,类似的
BUG需要好长时间才能发现。怎么办呢?是要改MAKEFILE么?
多谢回答! |
|
b*********n 发帖数: 56 | 48 可以。另外,如果你Fortran module 这个结构本身并不重要的话,你可以把你所有的
subroutines 放在一个文件里,f2py会给你生成一个Python module. |
|
b****z 发帖数: 337 | 49 我知道Gfortran是个Free的Compiler
但是我还需要许多的其它Functions or Subroutines来进行运算,比如Matrix
operations
Random variable generations,Gfortran下用什么Library库函数 吗?
谢谢 |
|
|