/** \file errors.c * Error reporting. * Contains just one function Error() which prints out a certain error message * class and starts the debugger. * * Project: ParallelCarParrinello * \author Jan Hamaekers * \date 2000 * * File: errors.c * $Id: errors.c,v 1.11 2006/03/31 10:38:04 foo Exp $ * */ #include #include #include"data.h" #include"opt.h" #include"errors.h" /** Deals with occuring errors. * Prints process id followed by error according to \ref Errors. * In the case of MallocError \a *SpecialData contains additional text. * Launches debugger, does afterwards MPI_abort and exit * * \note One could add another pointer to a function * * \sa StartDebugger() * \param error is the type of error(enum Errors) on error_msg array * \param *SpecialData is a typeless pointer on special data for error treatment, here detailed error message. */ void Error(enum Errors error, const void *SpecialData) { const char *const error_msg[] = { "SomeError", "FileOpenParams\nUnable to open parameter file", "InitReading\n", "MallocError\nUnable to allocate memory!", }; int mytid; MPI_Comm_rank(MPI_COMM_WORLD, &mytid); fprintf(stderr, "\nProcess %i: ", mytid); fprintf(stderr, "It has occured an error (%i): %s\n", error, error_msg[error]); switch (error) { case InitReading: case SomeError: case MallocError: if (SpecialData) fprintf(stderr, "%s\n", (const char*)SpecialData); break; default: break; } StartDebugger(); MPI_Abort(MPI_COMM_WORLD, (int)error); exit(EXIT_FAILURE); /* exit schreibt sowieso alle Dateipuffer aus */ }