Example #1
0
// One jacobi iteration
void jacobi_iteration() {
    for (int i = 0; i < local_height; i++) {
        for (int j = 0; j < local_width; j++) {
            local_pres[LP(i, j)] = calculate_jacobi(i, j);
        }
    }
}
Example #2
0
/* ************************************************************************ */
int
main (int argc, char** argv)
{
    MPI_Init(&argc, &argv);

    struct options options;
    struct calculation_arguments arguments;
    struct calculation_results results;

    /* get parameters */
    AskParams(&options, argc, argv);

    initVariables(&arguments, &results, &options);

    allocateMatrices(&arguments);        /*  get and initialize variables and matrices  */
    initMatrices(&arguments, &options);

    gettimeofday(&start_time, NULL);                  /*  start timer         */
    if (options.method == METH_JACOBI)
        calculate_jacobi(&arguments, &results, &options);        /*  solve the equation using Jaocbi  */
    else
        calculate_gaussseidel(&arguments, &results, &options);   /*  solve the equation using Gauss-Seidel  */

    MPI_Barrier(MPI_COMM_WORLD);
    gettimeofday(&comp_time, NULL);                   /*  stop timer          */

    // only attempt communication if we have more than 1 procss
    if(arguments.nproc > 1)
    {
        // communicate final maxresiduum from last rank to rank 0
        if(arguments.rank == 0)
            MPI_Recv(&results.stat_precision, 1, MPI_DOUBLE, arguments.nproc - 1, 1, MPI_COMM_WORLD, NULL);

        if(arguments.rank == arguments.nproc - 1)
            MPI_Send(&results.stat_precision, 1, MPI_DOUBLE, 0, 1, MPI_COMM_WORLD);
    }

    //printDebug(&arguments, &results); // pretty-print matrix if we are debugging
    if(arguments.rank == 0)
        displayStatistics(&arguments, &results, &options);

    DisplayMatrix("Matrix:", arguments.Matrix[results.m][0], options.interlines,
                  arguments.rank, arguments.nproc, arguments.offset + ((arguments.rank > 0) ? 1 : 0),
                  (arguments.offset + arguments.N - ((arguments.rank != arguments.nproc - 1) ? 1 : 0)));

    freeMatrices(&arguments);                                       /*  free memory     */

    MPI_Finalize();

    return 0;
}