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

#include "likwid-marker.h"
#include "omp.h"
#include "parameter.h"
#include "solver.h"
#include "timing.h"

#define LIKWID_PROFILE(tag, call)                                                        \
    startTime = getTimeStamp();                                                          \
    LIKWID_MARKER_START(#tag);                                                           \
    call(&solver);                                                                       \
    LIKWID_MARKER_STOP(#tag);                                                            \
    endTime = getTimeStamp();

int main(int argc, char** argv)
{
    int volatile dummy = 0;
    double startTime, endTime;
    Parameter params;
    Solver solver;
    initParameter(&params);
#pragma omp parallel
    {
        if (dummy == 1 || omp_get_thread_num() == 0)
            printf("OMP_THREADS_DETECTED: %d\n", omp_get_num_threads());
    }
    if (argc < 2) {
        printf("Usage: %s <configFile>\n", argv[0]);
        exit(EXIT_SUCCESS);
    }

    readParameter(&params, argv[1]);

    initSolver(&solver, &params, 2);
    startTime = getTimeStamp();
    solveRB(&solver);
    endTime = getTimeStamp();
    printf(" %.2fs\n", endTime - startTime);
    writeResult(&solver, "p.dat");

    return EXIT_SUCCESS;
}
