Создание приложений для распределенной обработки данных. Результаты вычислений, страница 2

{                           

ColofPivot = ((int)Buffer_Pivot[0]) * NoofRows_Bloc + irow;

for (jrow = 0; jrow < NoofRows_Bloc; jrow++)

{

index = jrow*n_size;

tmp = ARecv[index + ColofPivot];

for (icol = ColofPivot; icol < n_size; icol++)

ARecv[index + icol] -= tmp * Buffer_Pivot[irow*n_size + icol + 1 + NoofRows_Bloc];

BRecv[jrow] -= tmp * Buffer_Pivot[1 + irow];

ARecv[index + ColofPivot] = 0.0;

}

}

}

Y_buffer = new double[NoofRows_Bloc];                

for (irow = 0; irow < NoofRows_Bloc; irow++)

{

ColofPivot = MyRank * NoofRows_Bloc + irow;

index = irow*n_size;

Pivot = ARecv[index + ColofPivot];

assert(Pivot != 0);

for (icol = ColofPivot; icol < n_size; icol++)

{

ARecv[index + icol] = ARecv[index + icol] / Pivot;

Buffer_Pivot[index + icol + 1 + NoofRows_Bloc] = ARecv[index + icol];

}

Y_buffer[irow] = BRecv[irow] / Pivot;

Buffer_Pivot[irow + 1] = Y_buffer[irow];

for (jrow = irow + 1; jrow<NoofRows_Bloc; jrow++)

{

tmp = ARecv[jrow*n_size + ColofPivot];

for (icol = ColofPivot + 1; icol < n_size; icol++)

ARecv[jrow*n_size + icol] -= tmp * Buffer_Pivot[index + icol + 1 + NoofRows_Bloc];

BRecv[jrow] -= tmp * Y_buffer[irow];

ARecv[jrow*n_size + irow] = 0;

}

}

for (neigh_proc = MyRank + 1; neigh_proc < Numprocs; neigh_proc++)

{                 

Buffer_Pivot[0] = (double)MyRank;

MPI_Send(Buffer_Pivot, NoofRows_Bloc*n_size + 1 + NoofRows_Bloc, MPI_DOUBLE, neigh_proc,

MyRank, MPI_COMM_WORLD);

}

/*.... Back Substitution starts from here ........*/

Buffer_bksub = new double[NoofRows_Bloc * 2];

X_buffer = new double[NoofRows_Bloc];      

for (neigh_proc = MyRank + 1; neigh_proc<Numprocs; ++neigh_proc)

{

MPI_Recv(Buffer_bksub, 2 * NoofRows_Bloc, MPI_DOUBLE, neigh_proc, neigh_proc,

MPI_COMM_WORLD, &status);

for (irow = NoofRows_Bloc - 1; irow >= 0; irow--)

{

for (icol = NoofRows_Bloc - 1; icol >= 0; icol--)

{                                     

index = (int)Buffer_bksub[icol];

Y_buffer[irow] -= Buffer_bksub[NoofRows_Bloc + icol] * ARecv[irow*n_size + index];

}

}

}

for (irow = NoofRows_Bloc - 1; irow >= 0; irow--)

{

index = MyRank*NoofRows_Bloc + irow;

Buffer_bksub[irow] = (double)index;

Buffer_bksub[NoofRows_Bloc + irow] = X_buffer[irow] = Y_buffer[irow];

for (jrow = irow - 1; jrow >= 0; jrow--)

Y_buffer[jrow] -= X_buffer[irow] * ARecv[jrow*n_size + index];

}

for (neigh_proc = 0; neigh_proc < MyRank; neigh_proc++)

MPI_Send(Buffer_bksub, 2 * NoofRows_Bloc, MPI_DOUBLE, neigh_proc, MyRank, MPI_COMM_WORLD);

Output = new double[n_size];     

MPI_Gather(X_buffer, NoofRows_Bloc, MPI_DOUBLE, Output, NoofRows_Bloc, MPI_DOUBLE, 0, MPI_COMM_WORLD);      

if (MyRank == 0)

{

printf("\n");

printf(" ------------------------------------------- \n");

printf("Results:\n");

printf("\n");

printf("Matrix A\n");

printf("\n");

for (irow = 0; irow < n_size; irow++)

{

for (icol = 0; icol < n_size; icol++)

printf("%.3lf  ", Matrix_A[irow][icol]);

printf("\n");

}

printf("\n");

printf("Matrix B\n");

printf("\n");

for (irow = 0; irow < n_size; irow++)

{

printf("%.3lf\n", Input_B[irow]);

}

printf("\n");

printf("Solution vector\n");

printf("\n");

for (irow = 0; irow < n_size; irow++)

printf("%.3lf\n", Output[irow]);

printf(" --------------------------------------------------- \n");

}

MPI_Finalize();

time_t endTime = time(NULL);

printf("Processing time: %lf s", difftime(endTime, startTime));

system("pause");

return 0;

}