Jump to content

Cálculo de matrizes em C


tcms
 Share

Go to solution Solved by tcms,

Recommended Posts

Boas pessoa,,

Estou a tentar calcular a multiplicação de duas matrizes em C. Estou a usar MPI para paralelizar o calculo, contudo, estou a receber erros de segmentation fault, muito provavelmente por causa de ponteiros. O meu código é o seguinte:

int main(int argc, char *argv[]) {
double **A, **B, **C, *tmp1,*tmp2,*tmp3;
int N, i, j, k;
double som;

N =8;

int myrank, P, from, to;

tmp1 = (double *) malloc (sizeof(double ) * N * N);
tmp2 = (double *) malloc (sizeof(double ) * N * N);
tmp3 = (double *) malloc (sizeof(double ) * N * N);
A = (double **) malloc (sizeof(double *) * N);
B = (double **) malloc (sizeof(double *) * N);
C = (double **) malloc (sizeof(double *) * N);


MPI_Init (&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
MPI_Comm_size(MPI_COMM_WORLD, &P);


from = myrank * N/P;
to = (myrank+1) * N/P;


if(myrank == 0){

for (i = 0; i < N; i++){
			A[i] = &tmp1[i * N];
					B[i] = &tmp2[i * N];
							C[i] = &tmp3[i * N];
}


}



printf("Rank: %d\n", myrank);

MPI_Scatter(A, N*N/P, MPI_DOUBLE,A[from], N*N/P, MPI_DOUBLE, 0, MPI_COMM_WORLD);

Recebo um segmentation fault no MPI_Scatter, e não consigo perceber o que estou a fazer mal.

Edited by tcms
GeSHi
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.