<div id="RTEContent">hi,</div>
<div>I have a matrix multiplication program to be run on multiple machines.</div>
<div>The program works fine with small size matrices, but doesn't work with large size matrices.</div>
<div>There is no error message popping up when the program exits.</div>
<div>Besides, the working size of matrix is much smaller for windows than the one for linux.</div>
<div> </div>
<div>Can anyone tell me the possible reason that causes this error?</div>
<div> </div>
<div>Below shows my program C source code.</div>
<div> </div>
<div>#include <mpi.h><br>#include <stdio.h></div>
<div>#define NRA 3000 // number of rows in matrix A<br>#define NCA 2000 // number of columns in matrix A<br>#define NCB 400 // number of columns in matrix B<br>#define MASTER 0 // taskid of first task
<br>#define FROM_MASTER 1 // setting a message type<br>#define FROM_WORKER 2 // setting a message type</div>
<div>int main(int argc, char *argv[]) {<br> int numtasks, // number of tasks<br> taskid, // task identifier<br> source, // task id of message source
<br> dest, // task id of message destination<br> mtype, // message type<br> rows, // rows of matrix A sent to each worker<br> averow, extra, offset, // used to determine rows sent to each worker
<br> i, j, k; // misc</div>
<div> double a[NRA][NCA], // matrix A to be multiplied<br> b[NCA][NCB], // matrix B to be multiplied<br> c[NRA][NCB]; // result matrix C</div>
<div> MPI_Status status;</div>
<div> printf("debug_1\n"); // the execution did not come to this point</div>
<div> MPI_Init(&argc, &argv);<br> MPI_Comm_size(MPI_COMM_WORLD, &numtasks);<br> MPI_Comm_rank(MPI_COMM_WORLD, &taskid);</div>
<div> if(taskid == MASTER) {<br> printf("Number of worker tasks = %d\n", numtasks-1);<br> // initialize matrix a and matrix b<br> for(i=0; i<NRA; i++) {<br> for(j=0; j<NCA; j++) {
<br> a[i][j] = i+j;<br> }<br> }<br> for(i=0; i<NCA; i++) {<br> for(j=0; j<NCB; j++) {<br> b[i][j] = i*j;<br> }<br> }</div>
<div> // send matrix data to worker processes<br> averow = NRA/(numtasks-1);<br> extra = NRA%(numtasks-1);<br> offset = 0;<br> mtype = FROM_MASTER;<br> for(dest=1; dest<numtasks; dest++) {
<br> rows = (dest <= extra) ? averow+1 : averow;<br> printf(" sending %d rows to task %d\n", rows, dest);<br> MPI_Send(&offset, 1, MPI_INT, dest, mtype, MPI_COMM_WORLD);
<br> MPI_Send(&rows, 1, MPI_INT, dest, mtype, MPI_COMM_WORLD);<br> MPI_Send(&a[offset][0], rows*NCA, MPI_DOUBLE, dest, mtype, MPI_COMM_WORLD);<br> MPI_Send(&b, NCA*NCB, MPI_DOUBLE, dest, mtype, MPI_COMM_WORLD);
<br> offset = offset + rows;<br> }<br> }<br> else {<br> // receive matrix data from master process<br> mtype = FROM_MASTER;<br> MPI_Recv(&offset, 1, MPI_INT, MASTER, mtype, MPI_COMM_WORLD, &status);
<br> MPI_Recv(&rows, 1, MPI_INT, MASTER, mtype, MPI_COMM_WORLD, &status);<br> MPI_Recv(&a, rows*NCA, MPI_DOUBLE, MASTER, mtype, MPI_COMM_WORLD, &status);<br> MPI_Recv(&b, NCA*NCB, MPI_DOUBLE, MASTER, mtype, MPI_COMM_WORLD, &status);
<br> }</div>
<div> if(taskid == MASTER) {<br> // receive results from worker processes<br> mtype = FROM_WORKER;<br> for(source=1; source<numtasks; source++) {<br> MPI_Recv(&offset, 1, MPI_INT, source, mtype, MPI_COMM_WORLD, &status);
<br> MPI_Recv(&rows, 1, MPI_INT, source, mtype, MPI_COMM_WORLD, &status);<br> MPI_Recv(&c[offset][0], rows*NCB, MPI_DOUBLE, source, mtype, MPI_COMM_WORLD, &status);<br> }<br> }
<br> else {<br> // matrix calculation<br> for(k=0; k<NCB; k++) {<br> for(i=0; i<rows; i++) {<br> c[i][k] = 0.0;<br> for(j=0; j<NCA; j++) {<br> c[i][k] = c[i][k] + a[i][j]*b[j][k];
<br> }<br> }<br> }<br> // send results to master process<br> mtype = FROM_WORKER;<br> MPI_Send(&offset, 1, MPI_INT, MASTER, mtype, MPI_COMM_WORLD);<br> MPI_Send(&rows, 1, MPI_INT, MASTER, mtype, MPI_COMM_WORLD);
<br> MPI_Send(&c, rows*NCB, MPI_DOUBLE, MASTER, mtype, MPI_COMM_WORLD);<br> }</div>
<div> if(taskid == MASTER) {<br> printf("Here is the result matrix\n\n");<br> /*<br> for(i=0; i<NRA; i++) {<br> for(j=0; j<NCB; j++) {<br> printf("%6.2f ", c[i][j]);
<br> }<br> printf("\n");<br> }<br> */<br> }</div>
<div> MPI_Finalize();<br> return 0;<br>}<br> </div>