먼저, 저의 아주 나쁜 영어에 대해 사과드립니다. 2d에서 Laplace 방정식을 풀기 위해 코드 시리즈와 병렬을 작성했습니다. 사용자로부터받는 노드 수 (코드에서 ractangle 크기가 아닌 노드 수를 받음) 및 정의 된 2 차원 행렬 시리즈 코드에서는 많은 수의 노드 (1000 <)를 가져올 수 있지만 병렬로는 80 개의 노드 만 가져올 수 있습니다. 큰 숫자를 가져 오면 다음과 같은 오류가 발생합니다. 먼저 행렬을 정상적으로 정의했습니다. 또한 "malloc"을 사용하여 2 차원 배열의 메모리를 정의하고 할당 할 때 노드 수에 관계없이 동일한 (심지어 80 미만).MPI의 메모리 문제
[handicraft-ThinkPad:03040] *** Process received signal ***
[handicraft-ThinkPad:03040] Signal: Segmentation fault (11)
[handicraft-ThinkPad:03040] Signal code: Address not mapped (1)
[handicraft-ThinkPad:03040] Failing at address: 0x1f4
[handicraft-ThinkPad:03040] [ 0] /lib/x86_64-linux-gnu/libpthread.so.0(+0x11390)[0x7fd1a1728390]
[handicraft-ThinkPad:03040] [ 1] l[0x4010e0]
[handicraft-ThinkPad:03040] [ 2] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7fd1a136e830]
[handicraft-ThinkPad:03040] [ 3] l[0x400b29]
[handicraft-ThinkPad:03040] *** End of error message ***
--------------------------------------------------------------------------
mpirun noticed that process rank 0 with PID 3040 on node handicraft-ThinkPad exited on signal 11 (Segmentation fault).
어디에 문제가 있습니까? 직렬 코드처럼 노드의 larg 노드를 병렬 코드로 가져올 수 있습니까? 내 코드는 여기에 있습니다 :
#include <math.h>
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
float **floatalloc2d(int n, int m);
int main()
{
int rank,size;
double start_t,end_t;
MPI_Init (NULL,NULL);
MPI_Comm_rank (MPI_COMM_WORLD, &rank);
MPI_Comm_size (MPI_COMM_WORLD, &size);
float k,b_left,b_right,b_up,b_down;
int l_type,u_type,r_type,d_type,i,j,n,flag;
//scan data from user
if (rank==0)
{
printf("Enter number of node: \n");
scanf("%d",&n);
printf("Enter the k factor: \n");
scanf("%f",&k);
printf("Enter type of left boundary conditions: 0 for dirichlet and 1 for Neumann \n");
scanf("%d",&l_type);
printf("Enter left boundary conditions:\n");
scanf("%f",&b_left);
}
//calculate the time
start_t=MPI_Wtime();
MPI_Bcast(&n,1,MPI_INT,0,MPI_COMM_WORLD);
MPI_Bcast(&k,1,MPI_FLOAT,0,MPI_COMM_WORLD);
int cond=0,dx=1,dy=1,step=n/size,snd_num=step*n,rcv_num=step*n;
//float t1[n][n],t2[n][n],t3[step][n],t4[step][n];
float error;
float** t1 = floatalloc2d(n, n);
float** t2 = floatalloc2d(n, n);
float** t3 = floatalloc2d(step, n);
float** t4 = floatalloc2d(step, n);
//comput with guass-sidel
for (int z=0;z<1000;z++)
{
//send data to all process
MPI_Barrier(MPI_COMM_WORLD);
MPI_Scatter(t1,snd_num,MPI_FLOAT,t3,rcv_num,MPI_FLOAT,0,MPI_COMM_WORLD);
//comput in each process
for (i=1;i<(step-1);i++)
{
for (j=1;j<(n-1);j++)
{
t4[i][j]=0.25*(t3[i-1][j]+t3[i+1][j]+t3[i][j-1]+t3[i][j+1]);
error=fabs(t4[i][j]-t3[i][j]);
t3[i][j]=t4[i][j];
//cout<<i<<","<<j<<": ";
//cout<<"error= "<<error<<"\n";
}
}
//collect data from all process
MPI_Barrier(MPI_COMM_WORLD);
MPI_Gather(&t3,snd_num,MPI_FLOAT,&t1,rcv_num,MPI_FLOAT,0,MPI_COMM_WORLD);
//review
}
end_t=MPI_Wtime();
MPI_Finalize();
}
float **floatalloc2d(int n, int m) {
float *data = (float *)malloc(n*m*sizeof(float));
float **array = (float **)malloc(n*sizeof(float *));
for (int i=0; i<n; i++)
array[i] = &(data[i*m]);
return array;
}
당신은 행렬의 요소를 분산하려는 당신의 대답
디버거를 사용해 보셨습니까? – Badda
C++ 태그를 제거하십시오. – Gnqz
@Badda 아니요. 너는 좋은 것을 아느냐 ?? –