Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 9a4feded authored by FELŠÖCI Marek's avatar FELŠÖCI Marek
Browse files

Further simplify the code

parent 6e4798d8
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#ifdef HAVE_STDINT_H #ifdef HAVE_STDINT_H
#include <stdint.h> #include <stdint.h>
#endif #endif
...@@ -19,12 +20,6 @@ ...@@ -19,12 +20,6 @@
#ifdef HAVE_SYS_RESOURCE_H #ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h> #include <sys/resource.h>
#endif #endif
#ifdef _WIN32
#include <windows.h>
#endif
#ifdef HAVE_MACH_MACH_TIME_H
#include <mach/mach_time.h>
#endif
#include <ctype.h> #include <ctype.h>
#include <limits.h> #include <limits.h>
#include <float.h> #include <float.h>
...@@ -35,60 +30,14 @@ struct mpf_hmat_create_compression_args_t { ...@@ -35,60 +30,14 @@ struct mpf_hmat_create_compression_args_t {
const void * output; const void * output;
}; };
#if !(defined (_WIN32)) /* It's a UNIX system, I know this ! */
/* Try to detect a debugger. This relies on the fact that GDB and IDB
(on Linux at least) catches the signal SIGTRAP and does not deliver
it to the application.
When no debugger is attached, the SIGTRAP raised by raise(SIGTRAP)
will go to my_sigtrap_handler() which will swallow it, and continue
the program execution as if nothing happened. Otherwise, SIGTRAP
will stop the program inside the debugger, as if a breakpoint had
been reached.
Thus, debug_break() will break into the debugger if present, and do
nothing otherwise.
*/
#include <signal.h>
static int is_debugger_present = -1;
static void my_sigtrap_handler(int signum) {
(void)signum; // silent unused parameter warnings
is_debugger_present = 0;
signal(SIGTRAP, SIG_DFL);
}
inline static void debug_break() {
if (is_debugger_present == -1) {
is_debugger_present = 1;
signal(SIGTRAP, my_sigtrap_handler);
raise(SIGTRAP);
}
}
#else
inline static void debug_break() {};
#endif
#if !(defined (_WIN32)) /* It's a UNIX system, I know this ! */
#include <execinfo.h>
#include <unistd.h>
inline static void mpf_backtrace(){
void * stack[32];
int n = backtrace(stack, 32);
backtrace_symbols_fd(stack, n, STDERR_FILENO);
}
#else
inline static void mpf_backtrace(){}
#endif
/*! \brief Displays a warning message and that's all. */ /*! \brief Displays a warning message and that's all. */
#define SETWARN(n,s, ...) {MpfWarning(__LINE__,PACKAGE_NAME,__FILE__,__func__,n,s, ## __VA_ARGS__);} #define SETWARN(n,s, ...) {MpfWarning(__LINE__,PACKAGE_NAME,__FILE__,__func__,n,s, ## __VA_ARGS__);}
/*! \brief Displays an error message. */ /*! \brief Displays an error message. */
#define SHWERRM(n,s, ...) {MpfError(__LINE__,PACKAGE_NAME,__FILE__,__func__,n,s, ## __VA_ARGS__);} #define SHWERRM(n,s, ...) {MpfError(__LINE__,PACKAGE_NAME,__FILE__,__func__,n,s, ## __VA_ARGS__);}
/*! \brief Displays an error message and quits the current routine. */ /*! \brief Displays an error message and quits the current routine. */
#define SETERRQ(n,s, ...) {int _ierr = MpfError(__LINE__,PACKAGE_NAME,__FILE__,__func__,n,s, ## __VA_ARGS__); debug_break(); return _ierr;} #define SETERRQ(n,s, ...) {int _ierr = MpfError(__LINE__,PACKAGE_NAME,__FILE__,__func__,n,s, ## __VA_ARGS__); return _ierr;}
/*! \brief Displays an error message and aborts the code. */ /*! \brief Displays an error message and aborts the code. */
#define SETERRA(n,s, ...) {int _ierr = MpfError(__LINE__,PACKAGE_NAME,__FILE__,__func__,n,s, ## __VA_ARGS__);mpf_backtrace();debug_break();exit(_ierr);} #define SETERRA(n,s, ...) {int _ierr = MpfError(__LINE__,PACKAGE_NAME,__FILE__,__func__,n,s, ## __VA_ARGS__); exit(_ierr); }
/*! \brief Checks the integer n, if not zero then it displays an error message and quits the current routine. */ /*! \brief Checks the integer n, if not zero then it displays an error message and quits the current routine. */
#define CHKERRQ(n) {if (n) SETERRQ(n,(char *)0);} #define CHKERRQ(n) {if (n) SETERRQ(n,(char *)0);}
/*! \brief Checks the integer n, if not zero then it displays an error message and aborts the code. */ /*! \brief Checks the integer n, if not zero then it displays an error message and aborts the code. */
...@@ -102,27 +51,7 @@ inline static void mpf_backtrace(){} ...@@ -102,27 +51,7 @@ inline static void mpf_backtrace(){}
/*! \brief Evaluates the expression x, if it is false then it displays an error message and aborts the code. */ /*! \brief Evaluates the expression x, if it is false then it displays an error message and aborts the code. */
#define ASSERTA(x) { if (!(x)) { SETERRA(1, "Assert failure %s", #x); }} #define ASSERTA(x) { if (!(x)) { SETERRA(1, "Assert failure %s", #x); }}
#if !defined (MIN)
/*! \brief Minimum value of two elements. */
#define MIN(a,b) ( ((a)<(b)) ? (a) : (b) )
#endif
#define MpfCalloc(a,b) calloc(a,b)
#define MpfMalloc(a,b) malloc(a)
#define MpfRealloc(a,b) realloc(a,b)
#define MpfFree(a) free(a)
#define enter_context(a)
#define leave_context()
#if defined(_WIN32) && \
!(defined (__MINGW64__) || defined(__MINGW32__))
typedef struct my_timespec {
int64_t tv_sec;
int64_t tv_nsec;
} Time;
#else
typedef struct timespec Time; typedef struct timespec Time;
#endif
int MpfError(int line,char *package,char *file,const char *function, int number, ...) ; int MpfError(int line,char *package,char *file,const char *function, int number, ...) ;
int MpfWarning(int line,char *package,char *file,const char *function,int number, ...) ; int MpfWarning(int line,char *package,char *file,const char *function,int number, ...) ;
......
...@@ -46,7 +46,7 @@ int produitClassique(void **sol) { ...@@ -46,7 +46,7 @@ int produitClassique(void **sol) {
int ierr; int ierr;
double temps_initial, temps_final, temps_cpu; double temps_initial, temps_final, temps_cpu;
void *solCLA = MpfCalloc((size_t)nbPts*nbRHS, sizeof(double)) ; CHKPTRQ(solCLA) ; void *solCLA = calloc((size_t)nbPts*nbRHS, sizeof(double)) ; CHKPTRQ(solCLA) ;
temps_initial = getTime (); temps_initial = getTime ();
ierr = produitClassiqueBEM(2, solCLA) ; CHKERRQ(ierr); ierr = produitClassiqueBEM(2, solCLA) ; CHKERRQ(ierr);
......
...@@ -49,7 +49,7 @@ int computeCoordCylinder(int i, double *coord) { ...@@ -49,7 +49,7 @@ int computeCoordCylinder(int i, double *coord) {
} }
double* createCylinder(void) { double* createCylinder(void) {
double* result = MpfCalloc((size_t)3 * nbPts, sizeof(double)); double* result = calloc((size_t)3 * nbPts, sizeof(double));
int i, ierr; int i, ierr;
for (i = 0; i < nbPts; i++) { for (i = 0; i < nbPts; i++) {
ierr=computeCoordCylinder(i, &(result[(size_t)3*i]) ) ; CHKERRA(ierr) ; ierr=computeCoordCylinder(i, &(result[(size_t)3*i]) ) ; CHKERRA(ierr) ;
......
...@@ -20,11 +20,11 @@ typedef struct { ...@@ -20,11 +20,11 @@ typedef struct {
static void free_block_data(void *v) { static void free_block_data(void *v) {
block_data_t* p = (block_data_t*) v; block_data_t* p = (block_data_t*) v;
if (p->col_points) MpfFree(p->col_points); if (p->col_points) free(p->col_points);
if (p->row_points) MpfFree(p->row_points); if (p->row_points) free(p->row_points);
if (p->dof_col_used) MpfFree(p->dof_col_used); if (p->dof_col_used) free(p->dof_col_used);
if (p->dof_row_used) MpfFree(p->dof_row_used); if (p->dof_row_used) free(p->dof_row_used);
if (p) MpfFree(p); if (p) free(p);
} }
/** Callback for hmat block info */ /** Callback for hmat block info */
...@@ -70,7 +70,7 @@ prepare_hmat(int row_start, ...@@ -70,7 +70,7 @@ prepare_hmat(int row_start,
ASSERTA(user_context); ASSERTA(user_context);
contextTestFEMBEM *myCtx = (contextTestFEMBEM *)user_context; contextTestFEMBEM *myCtx = (contextTestFEMBEM *)user_context;
info->user_data = MpfCalloc(1, sizeof(block_data_t)); info->user_data = calloc(1, sizeof(block_data_t));
block_data_t* bdata = (block_data_t*) info->user_data; block_data_t* bdata = (block_data_t*) info->user_data;
bdata->row_start = row_start; bdata->row_start = row_start;
...@@ -84,14 +84,14 @@ prepare_hmat(int row_start, ...@@ -84,14 +84,14 @@ prepare_hmat(int row_start,
info->release_user_data = free_block_data; info->release_user_data = free_block_data;
/* Arrays to store non-null rows and columns */ /* Arrays to store non-null rows and columns */
bdata->dof_row_used = MpfCalloc(row_count, sizeof(int)); CHKPTRA(bdata->dof_row_used); bdata->dof_row_used = calloc(row_count, sizeof(int)); CHKPTRA(bdata->dof_row_used);
bdata->dof_col_used = MpfCalloc(col_count, sizeof(int)); CHKPTRA(bdata->dof_col_used); bdata->dof_col_used = calloc(col_count, sizeof(int)); CHKPTRA(bdata->dof_col_used);
/* precompute and store the coordinates of the points (rows and columns) /* precompute and store the coordinates of the points (rows and columns)
and tag BEM rows and columns as non-null and tag BEM rows and columns as non-null
*/ */
int i, j, col, row, ierr; int i, j, col, row, ierr;
bdata->row_points=(double(*)[3])MpfCalloc(row_count, 3*sizeof(double)); CHKPTRA(bdata->row_points); bdata->row_points=(double(*)[3])calloc(row_count, 3*sizeof(double)); CHKPTRA(bdata->row_points);
for (i = 0; i < row_count; ++i) { for (i = 0; i < row_count; ++i) {
row = bdata->row_hmat2client ? bdata->row_hmat2client[i + bdata->row_start] : i + bdata->row_start; row = bdata->row_hmat2client ? bdata->row_hmat2client[i + bdata->row_start] : i + bdata->row_start;
int row_g = row + myCtx->rowOffset; int row_g = row + myCtx->rowOffset;
...@@ -100,7 +100,7 @@ prepare_hmat(int row_start, ...@@ -100,7 +100,7 @@ prepare_hmat(int row_start,
bdata->dof_row_used[i]=1; // tag this row as non-null bdata->dof_row_used[i]=1; // tag this row as non-null
} }
} }
bdata->col_points=(double(*)[3])MpfCalloc(col_count, 3*sizeof(double)); CHKPTRA(bdata->col_points); bdata->col_points=(double(*)[3])calloc(col_count, 3*sizeof(double)); CHKPTRA(bdata->col_points);
for (j = 0; j < col_count; ++j) { for (j = 0; j < col_count; ++j) {
col = bdata->col_hmat2client ? bdata->col_hmat2client[j + bdata->col_start] : j + bdata->col_start; col = bdata->col_hmat2client ? bdata->col_hmat2client[j + bdata->col_start] : j + bdata->col_start;
int col_g = col + myCtx->colOffset; int col_g = col + myCtx->colOffset;
...@@ -163,7 +163,7 @@ advanced_compute_hmat(struct hmat_block_compute_context_t *b) { ...@@ -163,7 +163,7 @@ advanced_compute_hmat(struct hmat_block_compute_context_t *b) {
HMAT_desc_t *HMAT_generate_matrix( hmat_interface_t *hi ) { HMAT_desc_t *HMAT_generate_matrix( hmat_interface_t *hi ) {
HMAT_desc_t *hdesc = MpfCalloc( 1, sizeof(HMAT_desc_t) ); HMAT_desc_t *hdesc = calloc( 1, sizeof(HMAT_desc_t) );
/* Create a cluster tree with a clustering algorithm */ /* Create a cluster tree with a clustering algorithm */
hmat_clustering_algorithm_t *clustering = NULL; hmat_clustering_algorithm_t *clustering = NULL;
...@@ -176,7 +176,7 @@ HMAT_desc_t *HMAT_generate_matrix( hmat_interface_t *hi ) { ...@@ -176,7 +176,7 @@ HMAT_desc_t *HMAT_generate_matrix( hmat_interface_t *hi ) {
double *points = createCylinder(); double *points = createCylinder();
hmat_cluster_tree_t *cluster_tree = hmat_create_cluster_tree_from_builder( points, 3, nbPts, hmat_cluster_tree_t *cluster_tree = hmat_create_cluster_tree_from_builder( points, 3, nbPts,
ct_builder ); ct_builder );
MpfFree(points); points=NULL; free(points); points=NULL;
hmat_delete_cluster_tree_builder( ct_builder ); hmat_delete_cluster_tree_builder( ct_builder );
/* Create the H-matrix with this cluster tree and an admissibility criteria */ /* Create the H-matrix with this cluster tree and an admissibility criteria */
...@@ -207,7 +207,7 @@ HMAT_desc_t *HMAT_generate_matrix( hmat_interface_t *hi ) { ...@@ -207,7 +207,7 @@ HMAT_desc_t *HMAT_generate_matrix( hmat_interface_t *hi ) {
ctx.compression = (hmat_compression_algorithm_t*) compression_ctx.output; ctx.compression = (hmat_compression_algorithm_t*) compression_ctx.output;
ctx.prepare = prepare_hmat; ctx.prepare = prepare_hmat;
ctx.advanced_compute = advanced_compute_hmat; ctx.advanced_compute = advanced_compute_hmat;
contextTestFEMBEM *myCtx = MpfCalloc(1, sizeof(contextTestFEMBEM)) ; CHKPTRA(myCtx); contextTestFEMBEM *myCtx = calloc(1, sizeof(contextTestFEMBEM)) ; CHKPTRA(myCtx);
myCtx->colDim = nbPts; myCtx->colDim = nbPts;
ctx.user_context = myCtx; ctx.user_context = myCtx;
hi->assemble_generic(hmatrix, &ctx); hi->assemble_generic(hmatrix, &ctx);
...@@ -232,7 +232,7 @@ void HMAT_destroy_matrix( hmat_interface_t *hi, ...@@ -232,7 +232,7 @@ void HMAT_destroy_matrix( hmat_interface_t *hi,
hmat_delete_admissibility(hdesc->admissibilityCondition); hmat_delete_admissibility(hdesc->admissibilityCondition);
hmat_delete_cluster_tree(hdesc->cluster_tree); hmat_delete_cluster_tree(hdesc->cluster_tree);
hmat_delete_clustering(hdesc->clustering); hmat_delete_clustering(hdesc->clustering);
if (hdesc->myCtx) MpfFree(hdesc->myCtx); if (hdesc->myCtx) free(hdesc->myCtx);
MpfFree(hdesc); free(hdesc);
} }
} }
...@@ -178,7 +178,7 @@ int run_one() { ...@@ -178,7 +178,7 @@ int run_one() {
printf("[minisolver] cleaning ... "); printf("[minisolver] cleaning ... ");
if (rhs) { if (rhs) {
MpfFree(rhs); free(rhs);
rhs = NULL; rhs = NULL;
} }
printf("done\n"); printf("done\n");
......
...@@ -69,7 +69,7 @@ int testHMAT(double * relative_error) { ...@@ -69,7 +69,7 @@ int testHMAT(double * relative_error) {
printf("[minisolver] test-specific cleaning ... "); printf("[minisolver] test-specific cleaning ... ");
HMAT_destroy_matrix( interface, hdesc ); HMAT_destroy_matrix( interface, hdesc );
MpfFree(solCLA); free(solCLA);
printf("done\n"); printf("done\n");
return 0; return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment