Commit 3503a582 authored by Andreas Marek's avatar Andreas Marek

One example C test for new api

parent 0694eadb
......@@ -2,6 +2,11 @@
from __future__ import print_function
from itertools import product
language_flag = {
"Fortran" : "Fortran",
"C" : "C",
}
domain_flag = {
"real" : "-DTEST_REAL",
"complex": "-DTEST_COMPLEX",
......@@ -39,7 +44,8 @@ layout_flag = {
"square" : ""
}
for m, g, t, p, d, s, l in product(
for lang, m, g, t, p, d, s, l in product(
sorted(language_flag.keys()),
sorted(matrix_flag.keys()),
sorted(gpu_flag.keys()),
sorted(test_type_flag.keys()),
......@@ -48,6 +54,11 @@ for m, g, t, p, d, s, l in product(
sorted(solver_flag.keys()),
sorted(layout_flag.keys())):
if (lang == "C"):
continue
if (lang == "C" and ( m == "analytic" or l == "all_layouts")):
continue
if(m == "analytic" and (g == 1 or t != "eigenvectors")):
continue
......@@ -102,28 +113,53 @@ for m, g, t, p, d, s, l in product(
raise Exception("Oh no!")
endifs += 1
name = "test_{0}_{1}_{2}_{3}{4}{5}{6}{7}".format(
d, p, t, s,
"" if kernel == "nokernel" else "_" + kernel,
"_gpu" if g else "",
"_analytic" if m == "analytic" else "",
"_all_layouts" if l == "all_layouts" else "")
print("noinst_PROGRAMS += " + name)
print("check_SCRIPTS += " + name + ".sh")
print(name + "_SOURCES = test/Fortran/test.F90")
print(name + "_LDADD = $(test_program_ldadd)")
print(name + "_FCFLAGS = $(test_program_fcflags) \\")
print(" -DTEST_CASE=\\\"{0}\\\" \\".format(name))
print(" " + " \\\n ".join([
domain_flag[d],
prec_flag[p],
test_type_flag[t],
solver_flag[s],
gpu_flag[g],
matrix_flag[m]] + extra_flags))
print("endif\n" * endifs)
if (lang == "Fortran"):
name = "test_{0}_{1}_{2}_{3}{4}{5}{6}{7}".format(
d, p, t, s,
"" if kernel == "nokernel" else "_" + kernel,
"_gpu" if g else "",
"_analytic" if m == "analytic" else "",
"_all_layouts" if l == "all_layouts" else "")
print("noinst_PROGRAMS += " + name)
print("check_SCRIPTS += " + name + ".sh")
print(name + "_SOURCES = test/Fortran/test.F90")
print(name + "_LDADD = $(test_program_ldadd)")
print(name + "_FCFLAGS = $(test_program_fcflags) \\")
print(" -DTEST_CASE=\\\"{0}\\\" \\".format(name))
print(" " + " \\\n ".join([
domain_flag[d],
prec_flag[p],
test_type_flag[t],
solver_flag[s],
gpu_flag[g],
matrix_flag[m]] + extra_flags))
print("endif\n" * endifs)
if (lang == "C"):
name = "test_c_version_{0}_{1}_{2}_{3}{4}{5}{6}{7}".format(
d, p, t, s,
"" if kernel == "nokernel" else "_" + kernel,
"_gpu" if g else "",
"_analytic" if m == "analytic" else "",
"_all_layouts" if l == "all_layouts" else "")
print("noinst_PROGRAMS += " + name)
print("check_SCRIPTS += " + name + ".sh")
print(name + "_SOURCES = test/C/test.c")
print(name + "_LDADD = $(test_program_ldadd) $(FCLIBS)")
print(name + "_CFLAGS = $(test_program_fcflags) \\")
print(" -DTEST_CASE=\\\"{0}\\\" \\".format(name))
print(" " + " \\\n ".join([
domain_flag[d],
prec_flag[p],
test_type_flag[t],
solver_flag[s],
gpu_flag[g],
matrix_flag[m]] + extra_flags))
print("endif\n" * endifs)
for p, d in product(sorted(prec_flag.keys()), sorted(domain_flag.keys())):
endifs = 0
......
noinst_PROGRAMS += \
real_2stage_c_version@SUFFIX@ \
legacy_real_1stage@SUFFIX@ \
legacy_complex_1stage@SUFFIX@ \
legacy_real_2stage@SUFFIX@ \
......@@ -72,6 +73,11 @@ noinst_PROGRAMS += \
endif
endif
real_2stage_c_version@SUFFIX@_SOURCES = test/C/real_2stage_c_version.c
real_2stage_c_version@SUFFIX@_LDADD = $(test_program_ldadd) $(FCLIBS)
real_2stage_c_version@SUFFIX@_FCFLAGS = $(test_program_fcflags)
EXTRA_real_2stage_c_version@SUFFIX@_DEPENDENCIES = test/Fortran/elpa_print_headers.F90
legacy_real_1stage_c_version@SUFFIX@_SOURCES = test/C/elpa1/legacy_interface/legacy_real_1stage_c_version.c
legacy_real_1stage_c_version@SUFFIX@_LDADD = $(test_program_ldadd) $(FCLIBS)
legacy_real_1stage_c_version@SUFFIX@_FCFLAGS = $(test_program_fcflags)
......
/* This file is part of ELPA. */
/* */
/* The ELPA library was originally created by the ELPA consortium, */
/* consisting of the following organizations: */
/* */
/* - Max Planck Computing and Data Facility (MPCDF), formerly known as */
/* Rechenzentrum Garching der Max-Planck-Gesellschaft (RZG), */
/* - Bergische Universität Wuppertal, Lehrstuhl für angewandte */
/* Informatik, */
/* - Technische Universität München, Lehrstuhl für Informatik mit */
/* Schwerpunkt Wissenschaftliches Rechnen , */
/* - Fritz-Haber-Institut, Berlin, Abt. Theorie, */
/* - Max-Plack-Institut für Mathematik in den Naturwissenschaften, */
/* Leipzig, Abt. Komplexe Strukutren in Biologie und Kognition, */
/* and */
/* - IBM Deutschland GmbH */
/* */
/* */
/* More information can be found here: */
/* http://elpa.mpcdf.mpg.de/ */
/* */
/* ELPA is free software: you can redistribute it and/or modify */
/* it under the terms of the version 3 of the license of the */
/* GNU Lesser General Public License as published by the Free */
/* Software Foundation. */
/* */
/* ELPA is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU Lesser General Public License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with ELPA. If not, see <http://www.gnu.org/licenses/> */
/* */
/* ELPA reflects a substantial effort on the part of the original */
/* ELPA consortium, and we ask you to respect the spirit of the */
/* license that we chose: i.e., please contribute any changes you */
/* may have back to the original ELPA library distribution, and keep */
/* any derivatives of ELPA under the same license that we chose for */
/* the original distribution, the GNU Lesser General Public License. */
/* */
/* */
#include "config-f90.h"
#include <stdio.h>
#include <stdlib.h>
#ifdef WITH_MPI
#include <mpi.h>
#endif
#include <math.h>
#include <elpa/elpa.h>
#include <assert.h>
#include <test/shared/generated.h>
#define DOUBLE_PRECISION_REAL 1
#define assert_elpa_ok(x) assert(x == ELPA_OK)
int main(int argc, char** argv) {
int myid;
int nprocs;
#ifndef WITH_MPI
int MPI_COMM_WORLD;
#endif
int na, nev, nblk;
int status;
int np_cols, np_rows, np_colsStart;
int my_blacs_ctxt, my_prow, my_pcol;
int mpierr;
int my_mpi_comm_world;
int mpi_comm_rows, mpi_comm_cols;
int info, *sc_desc;
int na_rows, na_cols;
double startVal;
#ifdef DOUBLE_PRECISION_REAL
double *a, *z, *as, *ev;
#else
float *a, *z, *as, *ev;
#endif
int success;
elpa_t handle;
int value, error;
#ifdef WITH_MPI
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
#else
nprocs = 1;
myid=0;
MPI_COMM_WORLD=1;
#endif
na = 1000;
nev = 500;
nblk = 16;
if (myid == 0) {
printf("This is the c version of an ELPA test-programm\n");
printf("\n");
printf("It will call the 2stage ELPA real solver for an\n");
printf("matrix of size %d. It will compute %d eigenvalues\n",na,nev);
printf("and uses a blocksize of %d\n",nblk);
printf("\n");
printf("This is an example program with much less functionality\n");
printf("as it's Fortran counterpart. It's only purpose is to show how \n");
printf("to evoke ELPA2 from a c programm\n");
printf("\n");
#ifdef DOUBLE_PRECISION_REAL
printf(" Double precision version of ELPA2 is used. \n");
#else
printf(" Single precision version of ELPA2 is used. \n");
#endif
}
status = 0;
startVal = sqrt((double) nprocs);
np_colsStart = (int) round(startVal);
for (np_cols=np_colsStart;np_cols>1;np_cols--){
if (nprocs %np_cols ==0){
break;
}
}
np_rows = nprocs/np_cols;
if (myid == 0) {
printf("\n");
printf("Number of processor rows %d, cols %d, total %d \n",np_rows,np_cols,nprocs);
}
/* set up blacs */
/* convert communicators before */
#ifdef WITH_MPI
my_mpi_comm_world = MPI_Comm_c2f(MPI_COMM_WORLD);
#else
my_mpi_comm_world = 1;
#endif
set_up_blacsgrid_f(my_mpi_comm_world, np_rows, np_cols, 'C', &my_blacs_ctxt, &my_prow, &my_pcol);
if (myid == 0) {
printf("\n");
printf("Past BLACS_Gridinfo...\n");
printf("\n");
}
sc_desc = malloc(9*sizeof(int));
set_up_blacs_descriptor_f(na, nblk, my_prow, my_pcol, np_rows, np_cols, &na_rows, &na_cols, sc_desc, my_blacs_ctxt, &info);
if (myid == 0) {
printf("\n");
printf("Past scalapack descriptor setup...\n");
printf("\n");
}
/* allocate the matrices needed for elpa */
if (myid == 0) {
printf("\n");
printf("Allocating matrices with na_rows=%d and na_cols=%d\n",na_rows, na_cols);
printf("\n");
}
#ifdef DOUBLE_PRECISION_REAL
a = malloc(na_rows*na_cols*sizeof(double));
z = malloc(na_rows*na_cols*sizeof(double));
as = malloc(na_rows*na_cols*sizeof(double));
ev = malloc(na*sizeof(double));
#else
a = malloc(na_rows*na_cols*sizeof(float));
z = malloc(na_rows*na_cols*sizeof(float));
as = malloc(na_rows*na_cols*sizeof(float));
ev = malloc(na*sizeof(float));
#endif
#ifdef DOUBLE_PRECISION_REAL
prepare_matrix_random_real_double_f(na, myid, na_rows, na_cols, sc_desc, a, z, as);
#else
prepare_matrix_random_real_single_f(na, myid, na_rows, na_cols, sc_desc, a, z, as);
#endif
if (elpa_init(CURRENT_API_VERSION) != ELPA_OK) {
fprintf(stderr, "Error: ELPA API version not supported");
exit(1);
}
handle = elpa_allocate(&error);
assert_elpa_ok(error);
/* Set parameters */
elpa_set(handle, "na", na, &error);
assert_elpa_ok(error);
elpa_set(handle, "nev", nev, &error);
assert_elpa_ok(error);
elpa_set(handle, "local_nrows", na_rows, &error);
assert_elpa_ok(error);
elpa_set(handle, "local_ncols", na_cols, &error);
assert_elpa_ok(error);
elpa_set(handle, "nblk", nblk, &error);
assert_elpa_ok(error);
#ifdef WITH_MPI
elpa_set(handle, "mpi_comm_parent", MPI_Comm_c2f(MPI_COMM_WORLD), &error);
assert_elpa_ok(error);
elpa_set(handle, "process_row", my_prow, &error);
assert_elpa_ok(error);
elpa_set(handle, "process_col", my_pcol, &error);
assert_elpa_ok(error);
#endif
/* Setup */
assert_elpa_ok(elpa_setup(handle));
/* Set tunables */
elpa_set(handle, "solver", ELPA_SOLVER_2STAGE, &error);
assert_elpa_ok(error);
elpa_set(handle, "gpu", 0, &error);
assert_elpa_ok(error);
elpa_set(handle, "real_kernel", ELPA_2STAGE_REAL_GENERIC, &error);
assert_elpa_ok(error);
elpa_get(handle, "solver", &value, &error);
if (myid == 0) {
printf("Solver is set to %d \n", value);
}
if (myid == 0) {
printf("\n");
printf("Entering ELPA 2stage real solver\n");
printf("\n");
}
#ifdef WITH_MPI
mpierr = MPI_Barrier(MPI_COMM_WORLD);
#endif
/* Solve EV problem */
elpa_eigenvectors(handle, a, ev, z, &error);
assert_elpa_ok(error);
elpa_deallocate(handle);
elpa_uninit();
if (myid == 0) {
printf("\n");
printf("2stage ELPA real solver complete\n");
printf("\n");
}
/* check the results */
#ifdef DOUBLE_PRECISION_REAL
status = check_correctness_evp_numeric_residuals_real_double_f(na, nev, na_rows, na_cols, as, z, ev, sc_desc, myid);
#else
status = check_correctness_evp_numeric_residuals_real_single_f(na, nev, na_rows, na_cols, as, z, ev, sc_desc, myid);
#endif
if (status !=0){
printf("The computed EVs are not correct !\n");
}
if (status ==0){
if (myid ==0) {
printf("All ok!\n");
}
}
free(sc_desc);
free(a);
free(z);
free(as);
free(ev);
#ifdef WITH_MPI
MPI_Finalize();
#endif
return 0;
}
......@@ -55,15 +55,15 @@
#include "test/shared/generated.h"
#if !(defined(TEST_REAL) ^ defined(TEST_COMPLEX))
error: define exactly one of TEST_REAL or TEST_COMPLEX
//#error "define exactly one of TEST_REAL or TEST_COMPLEX"
#endif
#if !(defined(TEST_SINGLE) ^ defined(TEST_DOUBLE))
error: define exactly one of TEST_SINGLE or TEST_DOUBLE
//#error "define exactly one of TEST_SINGLE or TEST_DOUBLE"
#endif
#if !(defined(TEST_SOLVER_1STAGE) ^ defined(TEST_SOLVER_2STAGE))
error: define exactly one of TEST_SOLVER_1STAGE or TEST_SOLVER_2STAGE
//#error "define exactly one of TEST_SOLVER_1STAGE or TEST_SOLVER_2STAGE"
#endif
#ifdef TEST_SINGLE
......@@ -71,14 +71,14 @@ error: define exactly one of TEST_SOLVER_1STAGE or TEST_SOLVER_2STAGE
# ifdef TEST_REAL
# define MATRIX_TYPE float
# else
# define MATRIX_TYPE float complex
# define MATRIX_TYPE complex
# endif
#else
# define EV_TYPE double
# ifdef TEST_REAL
# define MATRIX_TYPE double
# else
# define MATRIX_TYPE double complex
# define MATRIX_TYPE complex double
# endif
#endif
......@@ -136,7 +136,7 @@ int main(int argc, char** argv) {
#else
mpi_comm = 0;
#endif
set_up_blacsgrid_f(mpi_comm, np_rows, np_cols, &my_blacs_ctxt, &my_prow, &my_pcol);
set_up_blacsgrid_f(mpi_comm, np_rows, np_cols, 'C', &my_blacs_ctxt, &my_prow, &my_pcol);
set_up_blacs_descriptor_f(na, nblk, my_prow, my_pcol, np_rows, np_cols, &na_rows, &na_cols, sc_desc, my_blacs_ctxt, &info);
/* allocate the matrices needed for elpa */
......@@ -147,15 +147,15 @@ int main(int argc, char** argv) {
#ifdef TEST_REAL
#ifdef TEST_DOUBLE
prepare_matrix_real_double_f(na, myid, na_rows, na_cols, sc_desc, a, z, as);
prepare_matrix_random_real_double_f(na, myid, na_rows, na_cols, sc_desc, a, z, as);
#else
prepare_matrix_real_single_f(na, myid, na_rows, na_cols, sc_desc, a, z, as);
prepare_matrix_random_real_single_f(na, myid, na_rows, na_cols, sc_desc, a, z, as);
#endif
#else
#ifdef TEST_DOUBLE
prepare_matrix_complex_double_f(na, myid, na_rows, na_cols, sc_desc, a, z, as);
prepare_matrix_random_complex_double_f(na, myid, na_rows, na_cols, sc_desc, a, z, as);
#else
prepare_matrix_complex_single_f(na, myid, na_rows, na_cols, sc_desc, a, z, as);
prepare_matrix_random_complex_single_f(na, myid, na_rows, na_cols, sc_desc, a, z, as);
#endif
#endif
......@@ -174,6 +174,9 @@ int main(int argc, char** argv) {
elpa_set(handle, "nev", nev, &error);
assert_elpa_ok(error);
if (myid == 0) {
printf("Setting the matrix parameters na=%d, nev=%d \n",na,nev);
}
elpa_set(handle, "local_nrows", na_rows, &error);
assert_elpa_ok(error);
......@@ -218,8 +221,9 @@ int main(int argc, char** argv) {
#endif
elpa_get(handle, "solver", &value, &error);
printf("Solver is set to %d \n", value);
if (myid == 0) {
printf("Solver is set to %d \n", value);
}
/* Solve EV problem */
elpa_eigenvectors(handle, a, ev, z, &error);
assert_elpa_ok(error);
......@@ -231,15 +235,15 @@ int main(int argc, char** argv) {
/* check the results */
#ifdef TEST_REAL
#ifdef TEST_DOUBLE
status = check_correctness_real_double_f(na, nev, na_rows, na_cols, as, z, ev, sc_desc, myid);
status = check_correctness_evp_numeric_residuals_real_double_f(na, nev, na_rows, na_cols, as, z, ev, sc_desc, myid);
#else
status = check_correctness_real_single_f(na, nev, na_rows, na_cols, as, z, ev, sc_desc, myid);
status = check_correctness_evp_numeric_residuals_real_single_f(na, nev, na_rows, na_cols, as, z, ev, sc_desc, myid);
#endif
#else
#ifdef TEST_DOUBLE
status = check_correctness_complex_double_f(na, nev, na_rows, na_cols, as, z, ev, sc_desc, myid);
status = check_correctness_evp_numeric_residuals_complex_double_f(na, nev, na_rows, na_cols, as, z, ev, sc_desc, myid);
#else
status = check_correctness_complex_single_f(na, nev, na_rows, na_cols, as, z, ev, sc_desc, myid);
status = check_correctness_evp_numeric_residuals_complex_single_f(na, nev, na_rows, na_cols, as, z, ev, sc_desc, myid);
#endif
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment