/*
 * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
 * All rights reserved.
 * Use of this source code is governed by a MIT-style
 * license that can be found in the LICENSE file.
 */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <limits.h>
#include <float.h>
#include <mpi.h>

#include "parameter.h"
#include "solver.h"

enum VARIANT { SOR = 1, RB, RBA };

int main (int argc, char** argv)
{
    int rank;
    int variant = SOR;

    Parameter params;
    Solver solver;

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    initParameter(&params);

    if ( argc < 2 ) {
        printf("Usage: %s <configFile>\n",argv[0]);
        exit(EXIT_SUCCESS);
    }

    readParameter(&params, argv[1]);
    if (argc == 3) 
    {
        variant = atoi(argv[2]);
    }


    if ( rank == 0 ) {
        printParameter(&params);
    }

    initSolver(&solver, &params, 2);

    switch (variant) {
    case SOR:
        printf("Plain SOR\n");
        solve(&solver);
        break;
    case RB:
        printf("Red-black SOR\n");
        solveRB(&solver);
        break;
    case RBA:
        printf("Red-black SOR with acceleration\n");
        solveRBA(&solver);
        break;
    }
    getResult(&solver);

    MPI_Finalize();
    return EXIT_SUCCESS;
}
