如果我分配一个F90指针会发生什么:
real, pointer :: abc(:)
allocate abc (nx*ny*nz)
Run Code Online (Sandbox Code Playgroud)
我将abc传递给子程序,在那里我将其重新定义为
real arg1(nx,ny,xz)
Run Code Online (Sandbox Code Playgroud)
这似乎工作正常.
但如果我重新定义为2D数组,我会得到一个段错误.
real arg1(nx,ny)
Run Code Online (Sandbox Code Playgroud)
使用上面重新排序的数组,它应该工作.为什么会失败?任何帮助将不胜感激.
谢谢.
嘿那里,我有一个关于fortran的openmpi的简短问题:我有一个这样的代码:
I) definitions of vars & linear code, setting up some vars for later usage
II) a while loop which works like that in pseudocode:
nr=1
while(true)
{
filename='result'//nr//'.bin' (nr converted to string)
if(!file_exists(filename))
goto 100
// file exists... so do something with it
// calculations, read/write...
nr=nr+1
}
100 continue
III) some more linear code...
Run Code Online (Sandbox Code Playgroud)
现在我想用openmpi进行并行计算.来自I)和III)的线性代码应该只计算一次,而while循环应该在几个处理器上运行......如何最好地实现它?我的问题是while循环是如何工作的:例如,当处理器1计算result1.bin时,如何直接告诉处理器2计算result2.bin?如果有30个文件并且我使用它将如何工作
mpirun -n 10 my_program
?MPI如何"知道"在完成计算一个文件之后,还有更多的文件"等待"处理:一个处理器处理完一个文件后,该处理器应该直接重新开始处理队列中的下一个文件.
谢谢到目前为止!
#编辑:
#嘿那里,它又是我...我也想尝试OpenMP,所以我使用了一大块代码来读取现有文件,然后循环它们(并处理它们):
nfiles = 0
do
write(filename,FMT='(A,I0,A)'), prefix, nfiles+1, suffix
inquire(file=trim(filename),exist=exists)
if (not(exists)) exit
nfiles …Run Code Online (Sandbox Code Playgroud) 我正在使用一些Fortran代码(在此项目之前我从未使用过这个代码......)并且遇到了一个问题.我需要与另一个程序共享一些内存空间.为了让Fortran识别每个内存块,我使用以下代码:
do 10 i = 0, 5
CALL C_F_POINTER(TRANSFER(memory_location +
: VarNamesLoc_(i),
: memory_location_cptr) , VarNames_(i), [3])
exit
10 continue
Run Code Online (Sandbox Code Playgroud)
哪里:
VarLoc(i)是表示存储器位置的整数
VarNames(i)?指针数组的数组?
我遇到的问题是创建指针数组的VarNames数组.我从谷歌搜索中找到了一些示例代码,但我发现Fortran很难理解!! 任何人都可以告诉我如何设置指针数组的数组?或者如果我不正确地接近问题,请指出替代方案?
作为参考,Fortran代码是以自由形式编写的,并使用intel编译器
谢谢你的帮助!
我刚刚学习OpenMPI.试过一个简单的MPI_Scatter例子:
#include <mpi.h>
using namespace std;
int main() {
int numProcs, rank;
MPI_Init(NULL, NULL);
MPI_Comm_size(MPI_COMM_WORLD, &numProcs);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
int* data;
int num;
data = new int[5];
data[0] = 0;
data[1] = 1;
data[2] = 2;
data[3] = 3;
data[4] = 4;
MPI_Scatter(data, 5, MPI_INT, &num, 5, MPI_INT, 0, MPI_COMM_WORLD);
cout << rank << " recieved " << num << endl;
MPI_Finalize();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但它没有按预期工作......
我期待着类似的东西
0 received 0
1 received 1
2 received 2 ...
Run Code Online (Sandbox Code Playgroud)
但我得到的是
32609 …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用ifort评估模型性能,但打印输出没有正确显示.
这是我的代码.请告诉我如何完成这项任务.
! Time the run
call dtime(timearray, telapse)
! End of the simulation
call dtime(timearray, telapse)
call print_runtime(telapse, ctime)
subroutine print_runtime(telapse, ctime)
implicit none
real*4 telapse
character*8 ctime(2)
integer*2 RunDays,
> RunHours,
> RunMins,
> RunSecs
character*40 msgstr, rtfname
parameter (msgstr = ' *** Total run time (wallclock) was ')
parameter (rtfname = 'runtime.txt')
! Now convert telapse from seconds to DD HH:MM:SS
RunDays = INT (telapse / 86400.0)
telapse = telapse - (RunDays * 86400.0)
RunHours = INT …Run Code Online (Sandbox Code Playgroud) 编辑:对不起,我忘了提到我乘以两个5000x5000矩阵.
这是输出,表明当我增加进程数时,时间也在增加.那么这段代码的逻辑是否存在问题.我从网上找到它,只将名称更改为matrixMulti及其printf.当我连接到Grid实验室并增加进程数时,在我看来这是合乎逻辑的但不能正常工作.所以你怎么看?

/**********************************************************************************************
* Matrix Multiplication Program using MPI.
*
* Viraj Brian Wijesuriya - University of Colombo School of Computing, Sri Lanka.
*
* Works with any type of two matrixes [A], [B] which could be multiplied to produce a matrix [c].
*
* Master process initializes the multiplication operands, distributes the muliplication
* operation to worker processes and reduces the worker results to construct the final output.
*
************************************************************************************************/
#include<stdio.h>
#include<mpi.h>
#define NUM_ROWS_A 5000 //rows of input [A] …Run Code Online (Sandbox Code Playgroud) 我有一个使用MPI的C++程序,我希望每个进程(最多32个)写入文件.我正在使用一个小的测试数据集,其中包含100个双重均匀分布在整个过程中的数据集.到目前为止,输出的格式如下:
data_sink.Write(&d_p[i], 1, MPI::DOUBLE);
data_sink.Write(&space, 1, MPI::CHAR);
data_sink.Write(&r_p[j], 1, MPI::DOUBLE);
data_sink.Write(&new_line, 1, MPI::CHAR);
Run Code Online (Sandbox Code Playgroud)
格式化此输出的最佳方法是什么,以便GNUPlot可以直接解释结果?
我无法理解特斯拉C1060上令人尴尬的并行计算的缩放性能.使用所有块和每个块的多个线程运行它,我得到的运行时间约为0.87秒.
但是,如果我只在一个块中运行所有迭代,每个块有一个线程,则运行时间最长为1872秒,这远远超过240x0.87s = 209s,我只希望缩小到只使用其中一个240个流媒体处理器.
相反,通过使用所有240核心,我似乎加速超过2000倍.这种超线性加速怎么可能; 在我对这个系统的性能建模中,我应该注意哪些其他因素?
为什么这个程序将结果打印为64而不是5000?如果在临界区更新count变量,我希望在任何给定的时间点只有一个线程可以访问它.因此,每个线程都能够增加计数,并产生结果5000,那么为什么我得到64代替?
#include <iostream>
#include <omp.h>
using namespace std;
int main()
{
int count = 0;
omp_set_num_threads(5000);
#pragma omp parallel
{
#pragma omp critical
{
count++;
}
}
cout << "count = " << count << endl;
system("pause");
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我有这个代码:
#include <omp.h>
#include <stdio.h>
int main(){
int i,j = 0 ;
int tid;
# pragma omp parallel private(i,j,tid)
{
tid = omp_get_thread_num();
printf("Thread %d\n",tid);
for(i=0;i<10;i++){
# pragma omp for
for(j=0; j<10;j++){
tid = omp_get_thread_num();
printf("(i,j) = (%d,%d) Thread %d\n",i,j,tid);
}
}
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么第一个"printf"由每个线程执行而不是第二个?
我想使用MPI在计算机之间发送矩阵。以下是我的测试代码
#include <iostream>
#include <Eigen/Dense>
#include <mpi.h>
using std::cin;
using std::cout;
using std::endl;
using namespace Eigen;
int main(int argc, char ** argv)
{
MatrixXd a = MatrixXd::Ones(3, 4);
int myrank;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
MPI_Status status;
if (0 == myrank)
{
MPI_Send(&a, 96, MPI_BYTE, 1, 99, MPI_COMM_WORLD);
}
else if (1 == myrank)
{
MPI_Recv(&a, 96, MPI_BYTE, 0, 99, MPI_COMM_WORLD, &status);
cout << "RANK " << myrank << endl;
cout << a << endl;
}
MPI_Finalize();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它成功编译成功,没有错误,但是当我启动它时,它返回了以下错误。 …
我有一个数据文件,其中以这种方式填充数据
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
.
.
.
.
.
91 92 93 94 95 96 97 98 99 100
Run Code Online (Sandbox Code Playgroud)
我想将这些数据存储在(10,10)的矩阵中,这是我的程序
program test
integer j,n,m
character,dimension(10,10) ::text
character*50 line
open(unit=3,file="tmp.txt",status='old')
n=1
read(3,"(a50)"),line
read(line,*,end=1),(text(1,i),i=1,10)
1 read(3,"(a50)",end=3),line
n=n+1
read(line,*,end=1)(text(n,i),i=i,10)
3 close(3)
end program test
Run Code Online (Sandbox Code Playgroud)
但我没有得到正确的价值观.