2016-11-12 12 views
0

私は、MPIの理解を助けるためオンラインで見つけたコードを実行しようとしていますが、次のコードをコンパイルしようとするとエラーが発生します。MPI行列の乗算を実行しようとしています

私は次のように返されています:

ここ
$ mpicc -o mpimm mpimm.c 
mpimm.c: In function ‘main’: 
mpimm.c:10: error: storage size of ‘start’ isn’t known 
mpimm.c:10: error: storage size of ‘stop’ isn’t known 

は、あなたがまだ含まれていない<time.h>で定義されている

#include "stdio.h" 
 
#include "mpi.h" 
 
#define N \t \t 500  /* number of rows and columns in matrix */ 
 

 
MPI_Status status; 
 

 
double a[N][N],b[N][N],c[N][N]; \t //matrix used 
 
     
 
main(int argc, char **argv){ 
 
\t struct timeval start, stop; 
 
\t int numberOfTasks, 
 
\t mtype, 
 
\t taskID, 
 
\t numberOfWorkers, 
 
\t source, 
 
\t destination, 
 
\t rows, 
 
\t averageRow, 
 
\t extra, 
 
\t offset,i,j,k; 
 
\t //first initialization 
 
\t MPI_Init(&argc, &argv); 
 
\t MPI_Comm_rank(MPI_COMM_WORLD, &taskID); 
 
\t MPI_Comm_size(MPI_COMM_WORLD, &numberOfTasks); 
 

 
\t numberOfWorkers = numberOfTasks-1; 
 

 
//---------------------------- master ----------------------------// 
 
\t if (taskID == 0) { 
 
\t \t for (i=0; i<N; i++) { 
 
\t \t \t for (j=0; j<N; j++) { 
 
\t \t \t \t a[i][j]= 1.0; 
 
\t \t \t \t b[i][j]= 2.0; 
 
\t \t \t } 
 
\t \t } 
 

 
    /* send matrix data to the worker tasks */ 
 
\t 
 
\t gettimeofday(&start, 0); 
 
\t 
 
    averageRow = N/numberOfWorkers; //average rows per worker 
 
\t extra= N%numberOfWorkers; \t \t //extra rows 
 
    offset = 0; 
 
    
 
\t \t for (destination=1; destination<=numberOfWorkers; destination++){ \t \t \t  \t 
 
\t 
 
\t \t \t if(destination<=extra){ 
 
\t \t \t \t rows = averageRow+1; 
 
\t \t \t }else{ 
 
\t \t \t \t rows = averageRow; 
 
\t \t \t } 
 
\t \t \t mtype = 1; 
 
\t \t \t MPI_Send(&offset, 1, MPI_INT, destination, mtype, MPI_COMM_WORLD); 
 
\t \t \t MPI_Send(&rows, 1, MPI_INT, destination, mtype, MPI_COMM_WORLD); 
 
\t \t \t MPI_Send(&a[offset][0], rows*N, MPI_DOUBLE,destination,mtype, MPI_COMM_WORLD); 
 
\t \t \t MPI_Send(&b, N*N, MPI_DOUBLE, destination, mtype, MPI_COMM_WORLD); 
 
\t \t \t offset = offset + rows; 
 
\t \t } 
 

 
    /* wait for results from all worker tasks */ 
 
\t \t for (i=1; i<=numberOfWorkers; i++){ 
 
\t \t \t mtype = 2; 
 
\t \t \t source = i; 
 
\t \t \t MPI_Recv(&offset, 1, MPI_INT, source, mtype, MPI_COMM_WORLD, &status); 
 
\t \t \t MPI_Recv(&rows, 1, MPI_INT, source, mtype, MPI_COMM_WORLD, &status); 
 
\t \t \t MPI_Recv(&c[offset][0], rows*N, MPI_DOUBLE, source, mtype, MPI_COMM_WORLD, &status); 
 
\t \t } 
 
\t \t gettimeofday(&stop, 0); 
 
\t 
 
\t \t 
 
\t \t printf("Upper Left = %6.2f Upper Right = %6.2f \n",c[0][0],c[0][N-1]); 
 
\t \t printf("Lower Left = %6.2f Lower Right = %6.2f \n",c[N-1][0],c[N-1][N-1]); 
 
\t \t 
 
\t \t fprintf(stdout,"Time = %.6f\n\n",(stop.tv_sec+stop.tv_usec*1e-6)-(start.tv_sec+start.tv_usec*1e-6)); 
 

 
    
 
\t } 
 

 
    /*---------------------------- worker----------------------------*/ 
 
\t if (taskID > 0) { 
 
\t \t source = 0; 
 
\t \t mtype = 1; 
 
\t \t MPI_Recv(&offset, 1, MPI_INT, source, mtype, MPI_COMM_WORLD, &status); 
 
\t \t MPI_Recv(&rows, 1, MPI_INT, source, mtype, MPI_COMM_WORLD, &status); 
 
\t \t MPI_Recv(&a, rows*N, MPI_DOUBLE, source, mtype, MPI_COMM_WORLD, &status); 
 
\t \t MPI_Recv(&b, N*N, MPI_DOUBLE, source, mtype, MPI_COMM_WORLD, &status); 
 
    
 
    /* Matrix multiplication */ 
 
\t \t for (k=0; k<N; k++) 
 
\t \t \t for (i=0; i<rows; i++) { 
 
\t \t \t \t c[i][k] = 0.0; 
 
\t \t \t \t for (j=0; j<N; j++) 
 
\t \t \t \t c[i][k] = c[i][k] + a[i][j] * b[j][k]; 
 
\t \t \t } 
 

 
\t \t \t mtype = 2; 
 
\t \t MPI_Send(&offset, 1, MPI_INT, 0, mtype, MPI_COMM_WORLD); 
 
\t \t MPI_Send(&rows, 1, MPI_INT, 0, mtype, MPI_COMM_WORLD); 
 
\t \t MPI_Send(&c, rows*N, MPI_DOUBLE, 0, mtype, MPI_COMM_WORLD); 
 
\t } 
 
    
 
    MPI_Finalize(); 
 
}

答えて

0

struct timeval以下のコード例、です。

gettimeofdayでも問題ありませんが、これを行う「mpi」の方法はMPI_Wtime()です。そのルーチンはdoubleを返すので、struct timevalの問題は完全に回避できます。

関連する問題