我是 Julia 编程的新手,面临着一种令人困惑的情况,我根本无法理解。所以,这就是我想做的:我有两个结构:Shoe和Person,其中Person包含Shoe
代码如下所示:
struct Shoe
size :: Int64
brand :: String
end
struct Person
age :: Int64
shoe :: Shoe
function Person(a::Int64, s::Shoe)
age = a
shoe = s
end
function Person()
age = 33
shoe = Shoe(17,"Nike")
end
end
ian = Person(17, Shoe(32,"Puma"))
tom = Person()
println(typeof(ian))
println(typeof(tom))
Run Code Online (Sandbox Code Playgroud)
令我大吃一惊的ian是tom,我试图将其定义为人,结果却是鞋子。知道我做错了什么吗?
我正在使用 Ubuntu 来开发带有 MPI 的 Fortran (2008+) 程序。在早期的 Ubuntu 版本上,一切都已经解决了,但我在 Ubuntu 22.04 上编译和运行 Fortran/MPI 时遇到了一些困难,我最近在一台新 PC 上安装了 Ubuntu 22.04。
我首先安装了 OpenMPI,但它根本不会编译我的程序,抱怨它找不到一些与mpi_f08. (很抱歉,但我不记得确切的消息,并且从那时起我就卸载了 OpenMPI)。
不过我在 MPICH 上的运气更好。它可以编译我的程序,但一旦处理器之间发生第一次通信,它就会在执行过程中崩溃。下面给出了演示该问题的最小示例:
subroutine global_sum_real(phi_old)
use mpi_f08
implicit none
real :: phi_old
real :: phi_new
integer :: error
call mpi_allreduce(phi_old, & ! send buffer
phi_new, & ! recv buffer
1, & ! length
mpi_real, & ! datatype
mpi_sum, & ! operation
mpi_comm_world, & ! communicator
error)
phi_old = phi_new
end subroutine
program global_sum_mpi
use mpi_f08 …Run Code Online (Sandbox Code Playgroud)