假设我有一个foo()调用例程的例程bar(argument).Argument可以是"在堆栈上"的声明(绘制与C并行),也可以动态分配.bar()如果argument使用第一种或第二种方法分配内存,我如何查询内部?
这个fortran代码应该从txt文件中的简单矩阵表中复制数据,然后根据每行和每列的先前等级计算等级和平均值.出于某种原因,我无法获得等级或平均值打印出来,它们显示为空白或0或星标.该程序在从txt文件打印矩阵表后运行时崩溃,它表示错误是访问冲突 - 所以根本没有多大帮助.到目前为止,我的代码是:
program calculate1
real,dimension(:,:),allocatable :: a
character(200)::line
print *,'How many rows are there?'
read *,n !amount of rows
print *,'How many columns are there?'
read *,m !amount of columns
allocate (a(n+1,m+1))
open(1, file='in1.txt')
call print_out (a,n+1,m+1)
Close(1);
contains
subroutine print_out(b,n,m)
real,dimension(:,:):: b
character(200)::line(n)
character(1)::g
write(*,'(10x)',advance='no')
do j=2,m-1
write(*,100,advance='no'),'hw',j-1
enddo
100 format(a2,i2,3x)
print '(a6,a6)','exam ','grade '
do i=1,n-1 !makes rows from data
read(1,'(a)') line(i) !read from in1.txt
write(*,'(a)') line(i) !write to screen
enddo
do i=1,n !makes (m+1)th column
b(i,m+1)= …Run Code Online (Sandbox Code Playgroud) 我在调用MPI_FINALIZE()Fortran 90 程序时遇到分段错误。虽然代码相当广泛,但我将发布伪代码并查看它是否引发任何标志。我有一种预感(但还没有尝试过)它可能是由于未释放数组引起的?但是,我不确定 - 在 Fortran 90 中无法取消分配数组会导致调用 期间出现分段错误MPI_FINALIZE吗?
if(<rank 0>) then
do iat = 1,natoms
do il = 0, LMAX
do im = -il,il
<mpi_recv "rank_rdy"> ! find out which rank is ready for (at,l,m)
<mpi_send "(iat,il,im)"> ! send (at,l,m) to the rank asking for it
enddo
enddo
enddo
else ! other ranks send a 'ready' signal and recieve the (at,l,m) to optimize
if(<rank 0 is not finished processing (at,l,m)'s>)
<mpi_send "my_rank"> ! …Run Code Online (Sandbox Code Playgroud) 我有一个fortran MPI代码,其中在2D数组的每个元素上调用计算密集型函数.我正在尝试将任务分配给队伍.例如,如果有30列和10个等级,那么每个等级得到3列.以下代码执行此拆分并使用allgather收集结果.但是最终数组没有来自所有排名的值.
program allgather
include 'mpif.h'
!create a 2 x 30 myarray
integer :: x=2,y=30
integer :: numprocs,myid
integer :: i,j,k,myelements,mycolumns,jb,je
integer*4,dimension(:),allocatable :: displacement,recvcnt
real :: checksum
real,dimension(:,:),allocatable :: myarr,combinedarr
call MPI_INIT(IERR)
call MPI_COMM_SIZE(MPI_COMM_WORLD,NUMPROCS,IERR)
call MPI_COMM_RANK(MPI_COMM_WORLD,MYID,IERR)
mycolumns = y/numprocs
myelements = x * mycolumns
allocate(displacement(numprocs),recvcnt(numprocs))
jb = 1 + ( myid * mycolumns )
je = ( myid + 1 ) * mycolumns
allocate(myarr(x,mycolumns))
allocate(combinedarr(x,y))
myarr(:,:) =0
do j=jb,je
do i=1,x
myarr(i,j) = 1
enddo
enddo
!myarr(:,:)=1
if(mod(y,numprocs) > 0) …Run Code Online (Sandbox Code Playgroud) 我继承了大约400行非常古怪的Fortran 77代码,我试图逐步分析它,以便在我的脑海中清楚地表达出来.
无论如何,我有一个类似头文件(实际上是一个.h,但其中的代码是在fortran而不是C/C++中),其中有两个语句,称为getarg.h:
character*80 serie
integer ln
Run Code Online (Sandbox Code Playgroud)
然后我有另一个fortran文件(.f)调用getserie.h其中包含此代码:
subroutine getserie(serie, ln)
include 'getarg.h'
call getarg(1, serie)
ln = index(serie, ' ') - 1
return
end
Run Code Online (Sandbox Code Playgroud)
我的问题是:我可以call使用只有变量声明的外部文件吗?这样做有什么影响?
我正在使用GNU gfortran(gfortran -v4.8.2),我在使用数组作为对象属性时遇到了麻烦.这就是我的意思:
type test_type
real*8 test_array(10,20)
end type test_type
type (test_type) example_test_type
Run Code Online (Sandbox Code Playgroud)
稍后当我尝试分配test_array的元素时:
example_test_type%test_array[0,1] = 99
Run Code Online (Sandbox Code Playgroud)
编译器抱怨(致命错误):
致命错误:在(1)处禁用Coarray,使用-fcoarray =启用
从我能找到的一点点来看,coarray旨在促进对并行编程的支持,我绝对不会在这里尝试.
有什么想法吗?
我一直试图弄清楚这两行代码的含义:
TYPE(DGRID),TARGET,ALLOCATABLE :: DGRIDS(:)
Run Code Online (Sandbox Code Playgroud)
...
JEK => DGRIDS(IMOD)%JEK
Run Code Online (Sandbox Code Playgroud)
我正在使用代码块,IMOD以绿色字体显示,这似乎表明IMOD是一个内在函数.我理解第二行是设置指针,但我无法弄清楚为什么内在函数存在.我也不清楚如何使用JEK两次 - 第二行中的两个"JEK"是指不同的实体吗?
在Fortran中,二维数组以列主格式存储,例如:
integer, allocatable, dimension(:,:)::A
allocate(A(3,4))
Run Code Online (Sandbox Code Playgroud)
数组"A"将作为A(1,1),A(2,1),A(3,1),A(1,2),A(2,2),A(3,2)存储在存储器中),... 等等.
但是当我有一个派生数据类型时会发生什么,例如:
type :: innerdata
integer :: i
real :: j
end type innerdata
type(innerdata), allocatable, dimension(:,:) :: A
allocate(A(3,4))
Run Code Online (Sandbox Code Playgroud)
数组"A"现在如何存储在内存中?谢谢!
我正在阅读一些Fortran 90代码并遇到一些我不熟悉的概念.部分代码,用于计算两个向量的点积,dmf_dotp用于实数值,zmf_dotp用于复数值.
mesh.F90:
#include mesh_inc.F90
interface dmf_dotp
module procedure dmf_dotp_1, dmf_dotp_2
end interface dmf_dotp
interface zmf_dotp
module procedure zmf_dotp_1, zmf_dotp_2
end interface zmf_dotp
Run Code Online (Sandbox Code Playgroud)
在另一个文件中有以下功能:
R_TYPE function X(mf_dotp_1)(mesh, f1, f2, reduce, dotu) result(dotp)
R_TYPE function X(mf_dotp_2)(mesh, dim, f1, f2, reduce, dotu) result(dotp)
Run Code Online (Sandbox Code Playgroud)
然后可以用zmf_dotp或调用这些函数(或接口?)dmf_dotp.那么这里到底发生了什么?
编辑感谢弗拉基米尔˚F.事实证明,还有一些预处理器宏定义:
#define X(x) z ## x
#define R_TYPE CMPLX
Run Code Online (Sandbox Code Playgroud) 我想在fortran初始化一个大整数数组,我试过:
integer(kind=8) :: XGrid(1:20)
Run Code Online (Sandbox Code Playgroud)
但整数仍然是默认类= 4.我后来在数组中添加了数字:
XGrid = (/3002, 3340403,....,19460630000/)
Run Code Online (Sandbox Code Playgroud)
我收到"此数字常量超出范围"错误.因为它不适合一种kind = 4 int,但会在一种= 8 int.
我也尝试将其声明为:
integer, parameter :: ik8 = selected_int_kind(8)
integer(ik8) :: XGrid(1:20)
Run Code Online (Sandbox Code Playgroud)
但这也行不通.
编辑:感谢Vladimir F,但我试图定义一个数组而不仅仅是一个变量,因此我无法理解如何调整使用的答案: Fortran 90中有更好的双精度赋值吗? 可不可能是:
integer, parameter :: ik8 = selected_int_kind(8)
integer(ik8) :: XGrid(1:20)_ik8
XGrid = (/3002_ik8, 3340403_ik8,....,19460630000_ik8/)
Run Code Online (Sandbox Code Playgroud)
还是不一样?谢谢