Hitmap 1.3
 All Data Structures Namespaces Files Functions Variables Typedefs Friends Macros Groups Pages
Data Structures | Macros | Functions | Variables
spring_bitmap.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <hitmap.h>
#include <hit_com.h>
#include <unistd.h>
#include <string.h>
Include dependency graph for spring_bitmap.c:

Go to the source code of this file.

Data Structures

struct  Vector
 
struct  Matrix
 

Macros

#define printfRootInternal(...)   { if( hit_Rank == 0 ) { printf(__VA_ARGS__); fflush(stdout); }}
 
#define printfRoot(...)   printfRootInternal(__VA_ARGS__)
 
#define D   (3)
 
#define K   (1)
 
#define L   (0.001)
 
#define P_FIXED   10
 
#define ITER1   10
 
#define ITER2   100
 
#define clearV(vv)   clearVInternal((vv).v)
 
#define clearVInternal(v)   ((v)[0] = (v)[1] = (v)[2] = 0.0 )
 
#define cpyV(r, a)   cpyVInternal((r).v,(a).v)
 
#define cpyVInternal(r, a)   {(r)[0] = (a)[0]; (r)[1] = (a)[1]; (r)[2] = (a)[2]; }
 
#define addV(r, a, b)   addVInternal((r).v,(a).v,(b).v)
 
#define addVInternal(r, a, b)   {(r)[0] = (a)[0] + (b)[0]; (r)[1] = (a)[1] + (b)[1]; (r)[2] = (a)[2] + (b)[2]; }
 
#define subV(r, a, b)   subVInternal((r).v,(a).v,(b).v)
 
#define subVInternal(r, a, b)   {(r)[0] = (a)[0] - (b)[0]; (r)[1] = (a)[1] - (b)[1]; (r)[2] = (a)[2] - (b)[2]; }
 
#define norm(vv)   normInternal((vv).v)
 
#define normInternal(v)   (sqrt( pow((v)[0],2) + pow((v)[1],2) + pow((v)[2],2) ))
 
#define multSV(r, s, vv)   multSVInternal((r).v,s,(vv).v)
 
#define multSVInternal(r, s, v)   {(r)[0] = (s) * (v)[0]; (r)[1] = (s) * (v)[1]; (r)[2] = (s) * (v)[2]; }
 
#define clearM(mm)   clearMInternal((mm).m)
 
#define clearMInternal(m)
 
#define det(mm)   detInternal((mm).m)
 
#define detInternal(m)
 
#define init_matrix(mm, a, b, c, d, e, f, g, h, i)   init_matrixInternal((mm).m,a,b,c,d,e,f,g,h,i)
 
#define init_matrixInternal(m, a, b, c, d, e, f, g, h, i)
 
#define multSM(r, s, mm)   multSMInternal((r).m,s,(mm).m)
 
#define multSMInternal(r, s, m)
 
#define multSI(r, s)   multSIInternal((r).m,s)
 
#define multSIInternal(r, s)
 
#define addM(r, a, b)   addMInternal((r).m,(a).m,(b).m)
 
#define addMInternal(r, a, b)
 
#define multVVt(r, a, b)   multVVtInternal((r).m,(a).v,(b).v)
 
#define multVVtInternal(r, a, b)
 
#define multMV(r, mm, vv)   multMVInternal((r).v,(mm).m,(vv).v)
 
#define multMVInternal(r, m, v)
 
#define inv(r, mm)   invInternal((r).m,(mm).m)
 
#define invInternal(r, m)
 
#define multMM(r, a, b)   multMMInternal((r).m,(a).m,(b).m)
 
#define multMMInternal(r, a, b)
 
#define ITER_SJ   10
 

Functions

 hit_tileNewType (Vector)
 
 hit_tileNewType (Matrix)
 
 hit_tileNewType (int)
 
 hit_tileNewType (double)
 
void calculate_GH (int vertex)
 
void solve_system_iter (int vertex)
 
Vector solve_jacobi (Matrix A, Vector b)
 
Vector solve (Matrix A, Vector b)
 
void init_structures ()
 
void free_structures ()
 
void print_help (char *name)
 
char * replace_str (char *str, const char *orig, const char *rep)
 
void random_coordinates ()
 
void init_graph (int argc, char **argv)
 
double gradient_norm ()
 
int main (int argc, char **argv)
 
Vector g (int i, int j)
 
Matrix W (int i, int j)
 

Variables

int iter1 = ITER1
 
int iter2 = ITER2
 
HitTile_Vector gradient
 
HitTile_Matrix hessian
 
HitTile_Vector e
 
HitTile_Vector new_e
 
HitShape global_shape
 
HitShape shape
 
HitShape ext_shape
 
HitTile_Vector graph
 
HitTile_Vector global_graph
 
HitTile_int fixed
 
HitTile_int global_fixed
 
HitLayout lay = HIT_LAYOUT_NULL_STATIC
 

Detailed Description

Calculate the stable position of a spring system. Parallel hitmap version of the benchmark using a bitmap structure.

Author
Javier Fresno
Date
21-6-2012
Version
1.0 (21-6-2012) First version based on spring_csr.

This is the same code from spring_csr_sec with the following changes: Changed hit_cShape* -> hit_bShape* Changed hit_gcTile* -> hit_gbTile* Changed HIT_CSR_SHAPE_NULL -> HIT_BITMAP_SHAPE_NULL Changed hit_fileHBRead -> hit_fileHBReadBitmap Changed plug_layMetis -> plug_layBitmap

Definition in file spring_bitmap.c.

Macro Definition Documentation

#define addM (   r,
  a,
 
)    addMInternal((r).m,(a).m,(b).m)

Add two matrix, r = a + b.

Definition at line 294 of file spring_bitmap.c.

#define addMInternal (   r,
  a,
 
)
Value:
{(r)[0][0] = (a)[0][0] + (b)[0][0]; (r)[0][1] = (a)[0][1] + (b)[0][1]; (r)[0][2] = (a)[0][2] + (b)[0][2]; \
(r)[1][0] = (a)[1][0] + (b)[1][0]; (r)[1][1] = (a)[1][1] + (b)[1][1]; (r)[1][2] = (a)[1][2] + (b)[1][2]; \
(r)[2][0] = (a)[2][0] + (b)[2][0]; (r)[2][1] = (a)[2][1] + (b)[2][1]; (r)[2][2] = (a)[2][2] + (b)[2][2]; }
#define r(a, b, c)

Definition at line 295 of file spring_bitmap.c.

#define addV (   r,
  a,
 
)    addVInternal((r).v,(a).v,(b).v)

Add two vectors, r = a + b.

Definition at line 209 of file spring_bitmap.c.

#define addVInternal (   r,
  a,
 
)    {(r)[0] = (a)[0] + (b)[0]; (r)[1] = (a)[1] + (b)[1]; (r)[2] = (a)[2] + (b)[2]; }

Definition at line 210 of file spring_bitmap.c.

#define clearM (   mm)    clearMInternal((mm).m)

Clear a matrix.

Definition at line 238 of file spring_bitmap.c.

#define clearMInternal (   m)
Value:
((m)[0][0] = (m)[0][1] = (m)[0][2] = \
(m)[1][0] = (m)[1][1] = (m)[1][2] = \
(m)[2][0] = (m)[2][1] = (m)[2][2] = 0.0 )
#define m(a, b, c)

Definition at line 239 of file spring_bitmap.c.

#define clearV (   vv)    clearVInternal((vv).v)

Clear a vector.

Definition at line 195 of file spring_bitmap.c.

#define clearVInternal (   v)    ((v)[0] = (v)[1] = (v)[2] = 0.0 )

Definition at line 196 of file spring_bitmap.c.

#define cpyV (   r,
 
)    cpyVInternal((r).v,(a).v)

Copy a vector.

Definition at line 202 of file spring_bitmap.c.

#define cpyVInternal (   r,
 
)    {(r)[0] = (a)[0]; (r)[1] = (a)[1]; (r)[2] = (a)[2]; }

Definition at line 203 of file spring_bitmap.c.

#define D   (3)

Number of dimensions.

Definition at line 62 of file spring_bitmap.c.

#define det (   mm)    detInternal((mm).m)

Calculate the determinant.

a b c d e f g h i

det = aei + bfg + cdh - afh - bdi - ceg

Definition at line 254 of file spring_bitmap.c.

#define detInternal (   m)
Value:
( (m)[0][0] * (m)[1][1] * (m)[2][2] \
+ (m)[0][1] * (m)[1][2] * (m)[2][0] \
+ (m)[0][2] * (m)[1][0] * (m)[2][1] \
- (m)[0][0] * (m)[1][2] * (m)[2][1] \
- (m)[0][1] * (m)[1][0] * (m)[2][2] \
- (m)[0][2] * (m)[1][1] * (m)[2][0] )
#define m(a, b, c)

Definition at line 255 of file spring_bitmap.c.

#define init_matrix (   mm,
  a,
  b,
  c,
  d,
  e,
  f,
  g,
  h,
 
)    init_matrixInternal((mm).m,a,b,c,d,e,f,g,h,i)

Initialization of a matrix.

Definition at line 266 of file spring_bitmap.c.

#define init_matrixInternal (   m,
  a,
  b,
  c,
  d,
  e,
  f,
  g,
  h,
 
)
Value:
{(m)[0][0] = a; (m)[0][1] = b; (m)[0][2] = c; \
(m)[1][0] = d; (m)[1][1] = e; (m)[1][2] = f; \
(m)[2][0] = g; (m)[2][1] = h; (m)[2][2] = i; }
Vector g(int i, int j)
#define m(a, b, c)
HitTile_Vector e
#define h(i, j)
Definition: SWpar.c:244

Definition at line 267 of file spring_bitmap.c.

#define inv (   r,
  mm 
)    invInternal((r).m,(mm).m)

Inverses a matrix.

Definition at line 324 of file spring_bitmap.c.

#define invInternal (   r,
  m 
)
Value:
{(r)[0][0] = (m)[1][1] * (m)[2][2] - (m)[1][2] * (m)[2][1]; \
(r)[0][1] = - (m)[0][1] * (m)[2][2] + (m)[0][2] * (m)[2][1]; \
(r)[0][2] = (m)[0][1] * (m)[1][2] - (m)[0][2] * (m)[1][1]; \
(r)[1][0] = - (m)[1][0] * (m)[2][2] + (m)[1][2] * (m)[2][0]; \
(r)[1][1] = (m)[0][0] * (m)[2][2] - (m)[0][2] * (m)[2][0]; \
(r)[1][2] = - (m)[0][0] * (m)[1][2] + (m)[0][2] * (m)[1][0]; \
(r)[2][0] = (m)[1][0] * (m)[2][1] - (m)[1][1] * (m)[2][0]; \
(r)[2][1] = - (m)[0][0] * (m)[2][1] + (m)[0][1] * (m)[2][0]; \
(r)[2][2] = (m)[0][0] * (m)[1][1] - (m)[0][1] * (m)[1][0]; \
#define detInternal(m)
#define r(a, b, c)
#define multSMInternal(r, s, m)
#define m(a, b, c)

Definition at line 325 of file spring_bitmap.c.

#define ITER1   10

Default number of iterations for the Newton-Raphson method.

Definition at line 73 of file spring_bitmap.c.

#define ITER2   100

Default number of iterations for the Jacobi method.

Definition at line 75 of file spring_bitmap.c.

#define ITER_SJ   10
#define K   (1)

Spring constant.

Definition at line 65 of file spring_bitmap.c.

#define L   (0.001)

Spring length.

Definition at line 67 of file spring_bitmap.c.

#define multMM (   r,
  a,
 
)    multMMInternal((r).m,(a).m,(b).m)

Multiplies two matrices.

Definition at line 340 of file spring_bitmap.c.

#define multMMInternal (   r,
  a,
 
)
Value:
{(r)[0][0] = (a)[0][0] * (b)[0][0] + (a)[0][1] * (b)[1][0] + (a)[0][2] * (b)[2][0]; \
(r)[0][1] = (a)[0][0] * (b)[0][1] + (a)[0][1] * (b)[1][1] + (a)[0][2] * (b)[2][1]; \
(r)[0][2] = (a)[0][0] * (b)[0][2] + (a)[0][1] * (b)[1][2] + (a)[0][2] * (b)[2][2]; \
(r)[1][0] = (a)[1][0] * (b)[0][0] + (a)[1][1] * (b)[1][0] + (a)[1][2] * (b)[2][0]; \
(r)[1][1] = (a)[1][0] * (b)[0][1] + (a)[1][1] * (b)[1][1] + (a)[1][2] * (b)[2][1]; \
(r)[1][2] = (a)[1][0] * (b)[0][2] + (a)[1][1] * (b)[1][2] + (a)[1][2] * (b)[2][2]; \
(r)[2][0] = (a)[2][0] * (b)[0][0] + (a)[2][1] * (b)[1][0] + (a)[2][2] * (b)[2][0]; \
(r)[2][1] = (a)[2][0] * (b)[0][1] + (a)[2][1] * (b)[1][1] + (a)[2][2] * (b)[2][1]; \
(r)[2][2] = (a)[2][0] * (b)[0][2] + (a)[2][1] * (b)[1][2] + (a)[2][2] * (b)[2][2]; }
#define r(a, b, c)

Definition at line 341 of file spring_bitmap.c.

#define multMV (   r,
  mm,
  vv 
)    multMVInternal((r).v,(mm).m,(vv).v)

Multiplies a matrix with a vector.

Definition at line 314 of file spring_bitmap.c.

#define multMVInternal (   r,
  m,
  v 
)
Value:
{(r)[0] = (m)[0][0] * (v)[0] + (m)[0][1] * (v)[1] + (m)[0][2] * (v)[2]; \
(r)[1] = (m)[1][0] * (v)[0] + (m)[1][1] * (v)[1] + (m)[1][2] * (v)[2]; \
(r)[2] = (m)[2][0] * (v)[0] + (m)[2][1] * (v)[1] + (m)[2][2] * (v)[2]; }
#define r(a, b, c)
#define m(a, b, c)
#define v(a, b, c)

Definition at line 315 of file spring_bitmap.c.

#define multSI (   r,
  s 
)    multSIInternal((r).m,s)

Multiplication scalar x identity matrix.

Definition at line 284 of file spring_bitmap.c.

#define multSIInternal (   r,
  s 
)
Value:
{(r)[0][0] = (s); (r)[0][1] = 0; (r)[0][2] = 0; \
(r)[1][0] = 0; (r)[1][1] = (s); (r)[1][2] = 0; \
(r)[2][0] = 0; (r)[2][1] = 0; (r)[2][2] = (s); }
#define r(a, b, c)
#define s

Definition at line 285 of file spring_bitmap.c.

#define multSM (   r,
  s,
  mm 
)    multSMInternal((r).m,s,(mm).m)

Multiplication scalar x matrix.

Definition at line 275 of file spring_bitmap.c.

#define multSMInternal (   r,
  s,
  m 
)
Value:
{(r)[0][0] = (s) * (m)[0][0]; (r)[0][1] = (s) * (m)[0][1]; (r)[0][2] = (s) * (m)[0][2]; \
(r)[1][0] = (s) * (m)[1][0]; (r)[1][1] = (s) * (m)[1][1]; (r)[1][2] = (s) * (m)[1][2]; \
(r)[2][0] = (s) * (m)[2][0]; (r)[2][1] = (s) * (m)[2][1]; (r)[2][2] = (s) * (m)[2][2]; }
#define r(a, b, c)
#define s
#define m(a, b, c)

Definition at line 276 of file spring_bitmap.c.

#define multSV (   r,
  s,
  vv 
)    multSVInternal((r).v,s,(vv).v)

Multiplication scalar x vector.

Definition at line 231 of file spring_bitmap.c.

#define multSVInternal (   r,
  s,
  v 
)    {(r)[0] = (s) * (v)[0]; (r)[1] = (s) * (v)[1]; (r)[2] = (s) * (v)[2]; }

Definition at line 232 of file spring_bitmap.c.

#define multVVt (   r,
  a,
 
)    multVVtInternal((r).m,(a).v,(b).v)

Multiply a vector with a transposed vector. the result is a matrix.

Definition at line 304 of file spring_bitmap.c.

#define multVVtInternal (   r,
  a,
 
)
Value:
{(r)[0][0] = (a)[0] * (b)[0]; (r)[0][1] = (a)[0] * (b)[1]; (r)[0][2] = (a)[0] * (b)[2]; \
(r)[1][0] = (a)[1] * (b)[0]; (r)[1][1] = (a)[1] * (b)[1]; (r)[1][2] = (a)[1] * (b)[2]; \
(r)[2][0] = (a)[2] * (b)[0]; (r)[2][1] = (a)[2] * (b)[1]; (r)[2][2] = (a)[2] * (b)[2]; }
#define r(a, b, c)

Definition at line 305 of file spring_bitmap.c.

#define norm (   vv)    normInternal((vv).v)

Calculate the norm of a vector

Definition at line 224 of file spring_bitmap.c.

#define normInternal (   v)    (sqrt( pow((v)[0],2) + pow((v)[1],2) + pow((v)[2],2) ))

Definition at line 225 of file spring_bitmap.c.

#define P_FIXED   10

Percentage of fixed points

Definition at line 70 of file spring_bitmap.c.

#define printfRoot (   ...)    printfRootInternal(__VA_ARGS__)

Definition at line 59 of file spring_bitmap.c.

#define printfRootInternal (   ...)    { if( hit_Rank == 0 ) { printf(__VA_ARGS__); fflush(stdout); }}

Definition at line 58 of file spring_bitmap.c.

#define subV (   r,
  a,
 
)    subVInternal((r).v,(a).v,(b).v)

Subtract two vectors, r = a - b.

Definition at line 217 of file spring_bitmap.c.

#define subVInternal (   r,
  a,
 
)    {(r)[0] = (a)[0] - (b)[0]; (r)[1] = (a)[1] - (b)[1]; (r)[2] = (a)[2] - (b)[2]; }

Definition at line 218 of file spring_bitmap.c.

Function Documentation

void calculate_GH ( int  vertex)

Function to calculate the gradient and hessian for a given node.

Parameters
vertexThe vertex index.

Function to calculate the gradient and hessian for a given node. Gradient: gs_i = Sum_j gij

Parameters
vertexThe vertex index.

Definition at line 927 of file spring_bitmap.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void free_structures ( )

Release the memory

Definition at line 445 of file spring_bitmap.c.

Here is the caller graph for this function:

Vector g ( int  i,
int  j 
)

Auxiliary function to get the gradient.

Definition at line 843 of file spring_bitmap.c.

Here is the caller graph for this function:

double gradient_norm ( )

Calculate the norm of the whole gradient vector.

Returns
the norm

Definition at line 667 of file spring_bitmap.c.

Here is the call graph for this function:

Here is the caller graph for this function:

hit_tileNewType ( Vector  )
hit_tileNewType ( Matrix  )
hit_tileNewType ( int  )
hit_tileNewType ( double  )
void init_graph ( int  argc,
char **  argv 
)

Init the graph

Definition at line 541 of file spring_bitmap.c.

Here is the call graph for this function:

void init_structures ( )

Allocate memory of all the variables

Definition at line 430 of file spring_bitmap.c.

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Main function

Definition at line 722 of file spring_bitmap.c.

Here is the call graph for this function:

void print_help ( char *  name)

Command-line help

Parameters
nameprogram name

Definition at line 467 of file spring_bitmap.c.

void random_coordinates ( )

Generate random coordinates for the spring nodes. It also set the fixed nodes

Definition at line 504 of file spring_bitmap.c.

Here is the caller graph for this function:

char* replace_str ( char *  str,
const char *  orig,
const char *  rep 
)

Replace string

Parameters
str
orig
rep
Returns

Definition at line 483 of file spring_bitmap.c.

Here is the caller graph for this function:

Vector solve ( Matrix  A,
Vector  b 
)

Solve a linear system. It calculates the inverse matrix. If the matrix is singular, it use the jacobi method to get an approximation. Ax=b.

Parameters
AThe coefficients matrix.
bThe constant terms vector.
Returns
The variable vector (x).

Definition at line 408 of file spring_bitmap.c.

Here is the call graph for this function:

Here is the caller graph for this function:

Vector solve_jacobi ( Matrix  A,
Vector  b 
)

Solve a linear system using the jacobi method. Ax=b.

Parameters
AThe coefficients matrix.
bThe constant terms vector.
Returns
The variable vector (s).

Definition at line 360 of file spring_bitmap.c.

Here is the caller graph for this function:

void solve_system_iter ( int  vertex)

Function that solves a iteration of the jacobi method for a given node.

Parameters
vertexThe vertex index.

Function that solves a iteration of the jacobi method for a given node. e_i = H_ii^(-1) * (Gi - SUM_{i not j} ( Hij e_j ) )

Parameters
vertexThe vertex index.

Definition at line 969 of file spring_bitmap.c.

Here is the call graph for this function:

Here is the caller graph for this function:

Matrix W ( int  i,
int  j 
)

Auxiliary function to get the hessian.

Definition at line 880 of file spring_bitmap.c.

Here is the caller graph for this function:

Variable Documentation

HitTile_Vector e

Vector with the position increase.

Definition at line 117 of file spring_bitmap.c.

HitShape ext_shape

Hit shape defining the extended local spring structure.

Definition at line 129 of file spring_bitmap.c.

HitTile_int fixed

Tile with the fixed/free status

Definition at line 138 of file spring_bitmap.c.

HitTile_int global_fixed

Tile with all the fixed/free status

Definition at line 141 of file spring_bitmap.c.

HitTile_Vector global_graph

Tile with all the node values.

Definition at line 135 of file spring_bitmap.c.

HitShape global_shape

Hit shape defining the spring structure.

Definition at line 123 of file spring_bitmap.c.

HitTile_Vector gradient

Gradient array part for each node.

Definition at line 111 of file spring_bitmap.c.

HitTile_Vector graph

Tile with the local node values.

Definition at line 132 of file spring_bitmap.c.

HitTile_Matrix hessian

Hessian matrix part for each edge.

Definition at line 114 of file spring_bitmap.c.

int iter1 = ITER1

Number of iterations for the Newton-Raphson method.

Definition at line 78 of file spring_bitmap.c.

int iter2 = ITER2

Number of iterations for the Jacobi method.

Definition at line 80 of file spring_bitmap.c.

Layout

Definition at line 145 of file spring_bitmap.c.

HitTile_Vector new_e

Vector with the new position increase.

Definition at line 120 of file spring_bitmap.c.

HitShape shape

Hit shape defining the local spring structure.

Definition at line 126 of file spring_bitmap.c.