Random gfortran与随机数

Random gfortran与随机数,random,fortran,gfortran,Random,Fortran,Gfortran,我正在尝试从mac ports(OS-X)使用Gfortran 4.7编译以下简单代码: 并有以下错误: gfortran-mp-4.7 tmp.f90 tmp.f90:17.23: call random_seed(PUT = iseed) 1 Error: Size of 'put' argument of 'random_seed' intrinsic at (1) too small (1/12) 我根本不使用FORTRAN(我是C++的人),

我正在尝试从mac ports(OS-X)使用Gfortran 4.7编译以下简单代码:

并有以下错误:

gfortran-mp-4.7  tmp.f90
tmp.f90:17.23:

call random_seed(PUT = iseed)
                   1
Error: Size of 'put' argument of 'random_seed' intrinsic at (1) too small (1/12)
我根本不使用FORTRAN(我是C++的人),所以如果有人能帮助和使它工作,我会非常感激。 p、 在一个类似的问题上,我发现了几个论坛帖子,当前的取消注释解决方案与中提到的类似

提到了带有
abs
的那一个(添加它时没有PID,因为我没有并行运行)

更新:

以下工作:

program main

implicit none

integer :: n = 12, clock, i

integer, dimension(:), allocatable :: iseed

! initialize the random number generator
allocate(iseed(n))
call random_seed(size = n)

call system_clock(COUNT=clock)

iseed = clock + 37 * [(i, i = 0,n-1)]
call random_seed(PUT = iseed)

end program main

为了对@Yossarian的评论稍作补充,以下是

call random_seed(size = n)
n
中返回要初始化RNG时必须使用的秩1整数数组的大小。我建议将
iseed
声明更改为可分配:

integer, dimension(:), allocatable :: iseed
然后,在获得
n
的值后,分配它:

allocate(iseed(n))
用您最喜欢的值填充它,然后
put
it

您可以在一条语句中分配和填充它,如下所示:

allocate(iseed(n), source = clock + 37 * [(i, i = 0,n-1)])
我可能会这样写,因为这取决于编译器的最新版本

编辑,在评论之后

不,你还没有完全理解我的建议

通过执行

call random_seed(size = n)
不要将
n
初始化为12

然后在一条语句(使用源分配)或
allocate
语句(后跟赋值)中分配并填充数组


操作顺序不正确。这将
iseed
设置为有12个元素(这是执行第一条语句时
n
的值),然后将
n
设置为RNG所需的数组大小。只要是12,您就不会看到任何问题,但只要将代码移植到另一个编译器,甚至可能是同一编译器的另一个版本,您就有可能遇到需要不同大小的整数数组的RNG。无需硬连线v你链接到的GCC错误报告有一个解决方案:你需要设置
n=12
整数,维度(12)::iseed
put
参数到
random\u seed
需要一个12个整数的数组。谢谢你的回复。我放了更新代码,这是你的意思吗?我编译得很好
call random_seed(size = n)
allocate(iseed(n))
call random_seed(size = n)