根据Fortran标准:
非指针伪参数的INTENT(OUT)属性指定在调用过程时伪参数变为未定义
然而,这个简单的代码将我5作为输出,所以看起来参数在程序开始时没有变得不确定(在这种情况下是一个子程序).
subroutine useless(a)
integer, intent(out) :: a
print *,a
end subroutine useless
program test
integer :: n=5
call useless(n)
end program test
Run Code Online (Sandbox Code Playgroud)
我错了什么?看起来intent(inout)和intent(out)都是一样的.
我正在编写一些代码,我有一个占位符matmul,似乎工作得很好,但我想使用一个LAPACK dgemm实现.我现在只使用gfortran并获得非常好的速度matmul,但我想知道我是否可以变得更好.
目前的电话是:
C = transpose(matmul( transpose(A), B))
Run Code Online (Sandbox Code Playgroud)
where A,B和C,是非正方形的double precision矩阵.我可以轻松地为dgemm当前的gfortran实现编写一个包装器LAPACK,但我喜欢我可以将所有这些作为一个函数(而不是担心call一个surbroutine并且必须处理transpose).
我想知道如果我编译ifort和包含MKL,这将matmul神奇地改变MKL dgemm为我没有包装的功能?
我一直在使用下划线将一个整数定义为fortran中的特定类型.
这是一段代码片段,用于演示具体1_8含义,例如:
program main
implicit none
integer(2) :: tiny
integer(4) :: short
integer(8) :: long
tiny = 1
short = 1
long = 1
print*, huge(tiny)
print*, huge(1_2)
print*, huge(short)
print*, huge(1_4)
print*, huge(long)
print*, huge(1_8)
end program main
Run Code Online (Sandbox Code Playgroud)
返回(使用PGI或gfortran):
32767
32767
2147483647
2147483647
9223372036854775807
9223372036854775807
Run Code Online (Sandbox Code Playgroud)
我正在使用huge内部函数返回给定类型的最大数量.所以1_8显然与整数(8)相同.这也适用于实数,虽然我没有在这里显示.
但是,我一直无法找到这个功能的任何文档,我不记得我在哪里学到它.我的问题是:
使用_KIND标准的fortran?有没有人有这个来源?
编辑:有人指出我使用的类型值(2,4,8)不可移植 - 例如,不同的编译器/机器可能为巨大的(1_4)提供不同的值.
我正在使用 awk 进行一些基本计算,并希望强制我的输出采用科学计数法。我正在用它OFMT="%.15e"来完成这个任务。在大多数机器上,我得到了预期的输出:
$ awk 'BEGIN { OFMT = "%.15e"; print 4.483923595133619e+29 / 1000 }'
4.483923595133619e+26
Run Code Online (Sandbox Code Playgroud)
但是我的集群上的 awk 版本给出了:
$ awk --version | head --lines=2
GNU Awk 4.0.2
Copyright (C) 1989, 1991-2012 Free Software Foundation.
$ awk 'BEGIN { OFMT = "%.15e"; print 4.483923595133619e+29 / 1000 }'
448392359513361882871234560
Run Code Online (Sandbox Code Playgroud)
为什么 awk 的这个版本/配置没有按照要求输出为科学计数法?我怎样才能便携地得到我想要的结果( 4.483923595133619e+26 )?
我试图在每次运行后保存并重用一个2D变量但我得到一些错误,如自动对象无法保存等.这是子程序:
subroutine dust_sum_test(ngrid,count,dust_in,dust_out)
!Subroutine to accumulate and release dust in timely manner
implicit none
integer,intent(in)::ngrid
integer,intent(in)::count
real,intent(in)::dust_in(ngrid)
real,intent(out)::dust_out(ngrid)
real,save::dmsdust(ngrid,99999) ! dummy local variable
integer::i
if (count.gt.1) then
dmsdust(:,count)=dmsdust(:,count-1)+dust_in
dust_out=dmsdust(:,count)
else
dust_out=dust_in
dmsdust(:,count)=0.0
endif
write(*,*)'The current count is = ', count
end subroutine dust_sum_test
Run Code Online (Sandbox Code Playgroud)
我需要使用以前的dmsdust值添加当前值.请让我知道如何解决这个问题.
我有一个编译时问题,我已经减少到以下测试用例.我想从fortran调用一个C++例程,让C++例程知道MPI.
请考虑以下示例代码,
Fortran主要:
! -- main.f90
program main
implicit none
external return_three
integer return_three
write(*,*) return_three()
end program main
Run Code Online (Sandbox Code Playgroud)
C++子程序:
// -- subs.cpp
#include <mpi.h>
extern "C"
{
int return_three_();
}
int return_three_()
{
return 3;
}
Run Code Online (Sandbox Code Playgroud)
请注意,为了重现问题,我只需要包括mpi.h.
使用GCC 5.3和OpenMPI 1.10.1进行编译(我也检查了GCC 4.8和PGI 15.10)在链接期间出现以下问题:
% mpic++ -c subs.cpp
% mpifort -c main.f90
% mpifort -o main subs.o main.o -lstdc++ -lgcc_s
subs.o: In function `MPI::Intracomm::Intracomm()':
subs.cpp:(.text._ZN3MPI9IntracommC2Ev[_ZN3MPI9IntracommC5Ev]+0x14): undefined reference to `MPI::Comm::Comm()'
subs.o: In function `MPI::Intracomm::Intracomm(ompi_communicator_t*)':
subs.cpp:(.text._ZN3MPI9IntracommC2EP19ompi_communicator_t[_ZN3MPI9IntracommC5EP19ompi_communicator_t]+0x19): undefined reference to `MPI::Comm::Comm()'
subs.o: …Run Code Online (Sandbox Code Playgroud) 我正在构建的程序包(SPRNG,链接在这里,但对于该问题不是必需的)在我不熟悉的某些地方使用了调用语法。对于我以前的依赖项堆栈(具有OpenMPI 1.10.1的Intel 16.0),它可以工作。不幸的是,我当前的堆栈(带有OpenMPI 3.1.3的Intel 19)不喜欢它。我不是一个c++人,除非有必要,否则我也不想大幅修改软件包。
示例代码是:
#include <mpi.h>
int main(int argc, char *argv[]) {
int myid;
MPI::Init(argc, argv);
myid = MPI::COMM_WORLD.Get_rank();
}
Run Code Online (Sandbox Code Playgroud)
在以前的堆栈中,这似乎很好:
$ mpic++ --version
icpc (ICC) 16.0.0 20150815
Copyright (C) 1985-2015 Intel Corporation. All rights reserved.
$ mpirun --version
mpirun (Open MPI) 1.10.1
Report bugs to http://www.open-mpi.org/community/help/
$ mpic++ sprng_issue.cpp
<no errors>
Run Code Online (Sandbox Code Playgroud)
但是有了新的堆栈:
$ mpic++ --version
icpc (ICC) 19.0.1.144 20181018
Copyright (C) 1985-2018 Intel Corporation. All rights reserved.
$ mpirun --version
mpirun (Open MPI) …Run Code Online (Sandbox Code Playgroud) 我想通过矩阵并检查它的任何块是否与预定义单位相同.这是我的代码.'sd5'是2乘2的预定义单位.
ALLOCATE (fList((n-1)**2,3))
fList = 0
p = 1
DO i = 1, n-1, 1
DO j = 1, n-1, 1
IF (TEST(i:i+1, j:j+1) == sd5) THEN
fList(p,1:3) = (i, j+1, 101) ! 101 should be replaced by submatrix number
END IF
p = p+1
END DO
END DO
Run Code Online (Sandbox Code Playgroud)
问题似乎在IF声明中,因为返回了四个逻辑语句TEST(i:i+1, j:j+1) == sd5.我收到此错误:
Error: IF clause at (1) requires a scalar LOGICAL expression
Run Code Online (Sandbox Code Playgroud)
我收到另一个错误:
fList(p,1:3) = (i, j+1, 101) ! 101 should be replaced by sub …Run Code Online (Sandbox Code Playgroud) 是否有可能在 Fortran 中实现非常小的数字1E-1200?我知道如何用 python 来做,但是我的硕士论文代码运行得太慢了。我的主管推荐我使用 Fortran,但我不确定这是否是一个问题。
我试图将fortran 77代码复制到C#.这是引起麻烦的线(至少我认为):
real acl,c(0:10)
Run Code Online (Sandbox Code Playgroud)
如何c在C#中的某些方法下声明这个新列表?像这样:
float acl;
float[] c = new float[0:10];
Run Code Online (Sandbox Code Playgroud)
?
感谢您的答复.