我想使用发送2d数据块MPI_GATHER.例如:我在每个节点上有2x3阵列,如果我有4个节点,我想在root上有8x3阵列.对于1d数组,MPI_GATHER根据MPI排序对数据进行排序,但对于2d数据,它会造成混乱!
把块放好的干净方法是什么?
我期望这段代码的输出:
program testmpi
use mpi
implicit none
integer :: send (2,3)
integer :: rec (4,3)
integer :: ierror,my_rank,i,j
call MPI_Init(ierror)
MPI_DATA_TYPE type_col
! find out process rank
call MPI_Comm_rank(MPI_COMM_WORLD, my_rank, ierror)
if (my_rank==0) then
send=1
do i=1,2
print*,(send(i,j),j=1,3)
enddo
endif
if (my_rank==1) then
send=5
! do 1,2
! print*,(send(i,j),j=1,3)
! enddo
endif
call MPI_GATHER(send,6,MPI_INTEGER,rec,6,MPI_INTEGER,0,MPI_COMM_WORLD,ierror)
if (my_rank==0) then
print*,'<><><><><>rec'
do i=1,4
print*,(rec(i,j),j=1,3)
enddo
endif
call MPI_Finalize(ierror)
end program testmpi
Run Code Online (Sandbox Code Playgroud)
是这样的:
1 1 1
1 1 …Run Code Online (Sandbox Code Playgroud) 我是node.js和docker以及微服务架构的新手.我试图了解微服务架构实际上是什么,理论上我理解微服务架是什么.请看下面的实现这是index.js文件:
var express = require("express");
var app = express();
var service1 = require("./service1");
var service2 = require("./service2");
app.use("/serviceonerequest",service1);
app.use("/servicetwo",service2);
app.listen(3000,function(){
console.log("listening on port 3000");
});
Run Code Online (Sandbox Code Playgroud)
文件service1:
var express = require("express");
var router = express.Router();
router.use(express.json());
router.get("/",(req,res)=>{
//perform some service here
res.send("in the get method of service 1");
res.end();
});
router.post("/letsPost",(req,res)=>{
res.send(req.body);
res.end("in post method here");
})
module.exports = router;
Run Code Online (Sandbox Code Playgroud)
文件服务2:
var express = require("express");
var router = express.Router();
router.use(express.json());
router.get("/",(req,res)=>{
//perform some service here
res.end("in …Run Code Online (Sandbox Code Playgroud) 我正在运行 VS Code,目前正在尝试在我的打字稿项目上设置一些别名。
我的开发设置依赖于 nodemon 和 ts-node,代码被编译到一个 dist 文件夹。
到目前为止,我成功地让 Typescript Hero 使用别名来管理导入:
到目前为止,我的文件夹结构是:
.
??? src
???modules
?????Category
?????Ressource
???shared
?????debug
Run Code Online (Sandbox Code Playgroud)
// tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"pretty": true,
"sourceMap": true,
"target": "es6",
"outDir": "./dist",
"baseUrl": "./src",
"paths": {
"@shared/*": [
"shared/*"
],
"@modules/*": [
"modules/*"
]
},
"resolveJsonModule": true,
"esModuleInterop": true
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
"**/*.spec.ts",
"**/*.test.ts",
]
}
Run Code Online (Sandbox Code Playgroud)
这是第一个失败的别名导入。
//Server.ts file
import Print from '@shared/debug/Print.class';
import App from './App';
const …Run Code Online (Sandbox Code Playgroud) 假设我想编写一个函数,该函数将一个维度的数组x作为输入,并基于该数组返回相同维度的另一个数组y(为了说明这一点,我正在使用将其乘以2的函数)。对于该代码,我有两个选择:
function times2(x) result(y)
real, intent(in) :: x(:)
real, allocatable :: y(:)
allocate(y(size(x))
y = 2*x
end function
Run Code Online (Sandbox Code Playgroud)
要么
function times2(x,n) result(y)
real, intent(in) :: x(n)
integer, intent(in) :: n
real :: y(n)
y = 2*x
end function
Run Code Online (Sandbox Code Playgroud)
就个人而言,我更喜欢第一个,因为它更易于调用方使用,但是我不确定哪个在内存方面更好,假设数组x可以很大,我不知道成为a会更好。延迟数组或自动数组。无论如何,这是在现代Fortran中实现的最佳方法吗?
假设给你一个整数对列表pairs和两个整数k1和k2。
从列表中查找满足以下条件的对的数量:
pairs[i][0] + pairs[j][0] <= k1pairs[i][1] + pairs[j][1] <= k2i < j例如,如果 、pairs=[[1,2],[2,3],[3,4],[4,5]]、k1=6和k2=7,结果应该是4,因为([1,2],[2,3])、([1,2],[3,4])、([1,2],[4,5])和([2,3],[3,4])都满足上述条件。
请参阅图片以更好地描述问题:
有没有一种方法可以比 O(n^2) 更高效地解决这个问题?到目前为止,这是我的解决方案:
pairs = [[1,2],[2,3],[3,4],[4,5]]
k1 = 6
k2 = 7
count = 0
n = len(pairs)
for i in range(n):
for j in range(i+1, n):
if pairs[i][0]+pairs[j][0] <= k1 and pairs[i][1]+pairs[j][1] <= k2:
count += 1
print(count)
Run Code Online (Sandbox Code Playgroud) 我有一个基本模块,其限定某些子程序(sub1,sub2,sub3)。然后,我想在一系列子模块中覆盖这些子例程。
我知道如何使用单独的模块和延迟类型来执行此操作,但是我决定尝试使用submodules。不幸的是,我不了解它们的用法。
这是我到目前为止的内容:
BaseModule:
module BaseModule
implicit none
interface
subroutine sub1(idx)
implicit none
integer, intent(in) :: idx
end subroutine sub1
subroutine sub2(idx)
implicit none
integer, intent(in) :: idx
end subroutine sub2
subroutine sub3(idx)
implicit none
integer, intent(in) :: idx
end subroutine sub3
end interface
end module BaseModule
Run Code Online (Sandbox Code Playgroud)
ChildModule1:
submodule (BaseModule) ChildModule1
implicit none
type :: Child1
contains
module procedure :: sub1
module procedure :: sub2
end …Run Code Online (Sandbox Code Playgroud)