/* Includes both algorithms */ void gauss() { void gaussElimination(); void backSubstitution(); /* Times */ double t1, t2; /* Barrier to sync all processes before starting the algorithms */ MPI_Barrier(MPI_COMM_WORLD); /* Initial time */ if ( my_rank == SOURCE ) t1 = MPI_Wtime(); /* Gauss Elimination is performed using MPI */ gaussElimination(); /* Back Substitution is performed sequentially */ if ( my_rank == SOURCE ) { backSubstitution(); /* Finish time */ t2 = MPI_Wtime(); printf("\nElapsed time: %f miliseconds\n", (t2-t1) * 1000 ); } }
void invertMatrix(double matrix[MAX][MAX], int n) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { matrix[i][j + n] = 0; } } for (int i = 0; i < n; i++) { matrix[i][i + n] = 1; } printMatrix(matrix, n, 2*n); gaussElimination(matrix, n, n); }