MPI 및 C를 사용하여 벡터로 사각형 행렬을 곱하려고합니다. MPI_Allgather를 사용하여 행렬의 모든 부분을 모든 프로세스로 보내야합니다. 이것은 내가 지금까지 가지고있는 것입니다.MPI 및 C에서 행렬 벡터 곱셈
#include "mpi.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#define DIM 500
int main(int argc, char *argv[])
{
int i, j, n;
int nlocal; /* Number of locally stored rows of A */
double *fb;
double a[DIM*DIM], b[DIM], x[DIM]; /* Will point to a buffer that stores the entire vector b */
int npes, myrank;
MPI_Status status;
MPI_Init(&argc,&argv);
/* Get information about the communicator */
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
MPI_Comm_size(MPI_COMM_WORLD, &npes);
/* Allocate the memory that will store the entire vector b */
fb = (double*)malloc(n*sizeof(double));
nlocal = n/npes;
/* Gather the entire vector b on each processor using MPI's ALLGATHER operation */
MPI_Allgather(b, nlocal, MPI_DOUBLE, fb, nlocal, MPI_DOUBLE, MPI_COMM_WORLD);
/* Perform the matrix-vector multiplication involving the locally stored submatrix */
for (i=0; i<nlocal; i++) {
x[i] = 0.0;
for (j=0; j<n; j++)
x[i] += a[i*n+j]*fb[j];
}
free(fb);
MPI_Finalize();
}//end main
OK 이제 작동합니다! 그것은 컴파일하지만 다음 mpi allgather 내부 오류가 발생합니다! 나는 다른 해결책을 가지고 이것을 시도했다.
Fatal error in MPI_Allgather: Internal MPI error!, error stack:
MPI_Allgather(961).......: MPI_Allgather(sbuf=0xa1828, scount=407275437, MPI_DOU BLE, rbuf=0xf61d0008, rcount=407275437, MPI_DOUBLE, MPI_COMM_WORLD) failed
MPIR_Allgather_impl(807).:
MPIR_Allgather(766)......:
MPIR_Allgather_intra(560):
MPIR_Localcopy(357)......: memcpy arguments alias each other, dst=0xb8513d70 src =0xa1828 len=-1036763800
Fatal error in MPI_Allgather: Internal MPI error!, error stack:
MPI_Allgather(961).......: MPI_Allgather(sbuf=0xa1828, scount=407275437, MPI_DOU BLE, rbuf=0xf61d0008, rcount=407275437, MPI_DOUBLE, MPI_COMM_WORLD) failed
MPIR_Allgather_impl(807).:
MPIR_Allgather(766)......:
MPIR_Allgather_intra(560):
MPIR_Localcopy(357)......: memcpy arguments alias each other, dst=0x3cb9b840 src =0xa1828 len=-1036763800
Fatal error in MPI_Allgather: Internal MPI error!, error stack:
MPI_Allgather(961).......: MPI_Allgather(sbuf=0xa1828, scount=407275437, MPI_DOU BLE, rbuf=0xf61d0008, rcount=407275437, MPI_DOUBLE, MPI_COMM_WORLD) failed
MPIR_Allgather_impl(807).:
MPIR_Allgather(766)......:
MPIR_Allgather_intra(560):
MPIR_Localcopy(357)......: memcpy arguments alias each other, dst=0x7a857ad8 src =0xa1828 len=-1036763800
아무도 도와 줄 수 있습니까?
'a'는 2 차원 배열이지만, 하나의 차원 만 갖는 것처럼 액세스합니다. 구문은'a [??]'대신 'a [??] [??]'이 될 것이지만, ?? s 대신 넣는 것은 데이터 레이아웃에 달려 있습니다. – user786653
다른 프로세스의 행을 통해 분할되기 때문에 하나의 차원과 비슷합니다. –
나는 그것을 시도했지만 여전히 나에게 그 오류를 준다. 이 arround을 돌리는 방법을 모른다 –