Skip to content

Commit

Permalink
Make some warnings about bad C-code (#7158)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund committed Feb 15, 2021
1 parent 9c61439 commit 3de3ab4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
Expand Up @@ -75,8 +75,8 @@ typedef struct DATA_HOMOTOPY
{
int initialized; /* 1 = initialized, else = 0*/

int n; /* dimension; n == size */
int m; /* dimension: m == size+1 */
size_t n; /* dimension; n == size */
size_t m; /* dimension: m == size+1 */

double xtol_sqrd; /* tolerance for updating solution vector */
double ftol_sqrd; /* tolerance for accepting accuracy */
Expand Down Expand Up @@ -163,7 +163,7 @@ typedef struct DATA_HOMOTOPY
* allocate memory for nonlinear system solver
* \author bbachmann
*/
int allocateHomotopyData(int size, void** voiddata)
int allocateHomotopyData(size_t size, void** voiddata)
{
DATA_HOMOTOPY* data = (DATA_HOMOTOPY*) malloc(sizeof(DATA_HOMOTOPY));

Expand Down Expand Up @@ -681,6 +681,7 @@ double vecScalarProd(int n, double *a, double *b)
void matVecMult(int n, int m, double *A, double *b, double *c)
{
int i, j;
#warning "Fix the performance problem here; this order will trash the cache"
for (i=0;i<n;i++) {
c[i] = 0.0;
for (j=0;j<m;j++)
Expand All @@ -692,6 +693,7 @@ void matVecMult(int n, int m, double *A, double *b, double *c)
void matVecMultAbs(int n, int m, double *A, double *b, double *c)
{
int i, j;
#warning "Fix the performance problem here; this order will trash the cache"
for (i=0;i<n;i++) {
c[i] = 0.0;
for (j=0;j<m;j++)
Expand All @@ -703,6 +705,7 @@ void matVecMultAbs(int n, int m, double *A, double *b, double *c)
void matVecMultBB(int n, double *A, double *b, double *c)
{
int i, j;
#warning "Fix the performance problem here; this order will trash the cache"
for (i=0;i<n;i++) {
c[i] = 0.0;
for (j=0;j<n;j++)
Expand All @@ -714,6 +717,7 @@ void matVecMultBB(int n, double *A, double *b, double *c)
void matVecMultAbsBB(int n, double *A, double *b, double *c)
{
int i, j;
#warning "Fix the performance problem here; this order will trash the cache"
for (i=0;i<n;i++) {
c[i] = 0.0;
for (j=0;j<n;j++)
Expand All @@ -725,7 +729,7 @@ void matVecMultAbsBB(int n, double *A, double *b, double *c)
void matAddBB(int n, double* A, double* B, double* C)
{
int i, j;

#warning "Fix the performance problem here; this order will trash the cache"
for (i=0;i<n;i++) {
for (j=0;j<n+1;j++)
C[i + j*n] = A[i + j*n] + B[i + j*n];
Expand All @@ -736,7 +740,7 @@ void matAddBB(int n, double* A, double* B, double* C)
void matDiffBB(int n, double* A, double* B, double* C)
{
int i, j;

#warning "Fix the performance problem here; this order will trash the cache"
for (i=0;i<n;i++) {
for (j=0;j<n;j++)
C[i + j*n] = A[i + j*n] - B[i + j*n];
Expand All @@ -749,6 +753,7 @@ void scaleMatrixRows(int n, int m, double *A)
const double delta = sqrt(DBL_EPSILON);
int i, j;
double rowMax;
#warning "Fix the performance problem here; this order will trash the cache"
for (i=0;i<n;i++) {
rowMax = 0; /* This might be changed to delta */
for (j=0;j<n;j++) {
Expand All @@ -767,6 +772,7 @@ void scaleMatrixRows(int n, int m, double *A)
void orthogonalBacktraceMatrix(DATA_HOMOTOPY* solverData, double* hJac, double* hvec, double* v, double* hJac2, int n, int m)
{
int i, j;
#warning "Fix the performance problem here; this order will trash the cache"
for (i=0; i<n; i++)
{
for (j=0; j<m; j++)
Expand Down
Expand Up @@ -36,7 +36,7 @@

#include "../../simulation_data.h"

int allocateHomotopyData(int size, void** data);
int allocateHomotopyData(size_t size, void** data);
int freeHomotopyData(void** data);

int solveHomotopy(DATA *data, threadData_t *threadData, int sysNumber);
Expand Down
Expand Up @@ -61,7 +61,7 @@ static void wrapper_fvec_hybrj(const integer* n, const double* x, double* f, dou
/*! \fn allocate memory for nonlinear system solver hybrd
*
*/
int allocateHybrdData(int size, void** voiddata)
int allocateHybrdData(size_t size, void** voiddata)
{
DATA_HYBRD* data = (DATA_HYBRD*) malloc(sizeof(DATA_HYBRD));

Expand Down
Expand Up @@ -51,7 +51,7 @@ void hybrj_( void(*) (const integer*, const double*, double*, double *, const in
double *r, integer *lr, double *qtf, double *wa1, double *wa2,
double *wa3, double *wa4, void* user_data);

extern int allocateHybrdData(int size, void **data);
extern int allocateHybrdData(size_t size, void **data);
extern int freeHybrdData(void **data);
extern int solveHybrd(DATA *data, threadData_t *threadData, int sysNumber);

Expand Down

0 comments on commit 3de3ab4

Please sign in to comment.