Commit 12783ffa authored by Mathieu Faverge's avatar Mathieu Faverge

More cleanup

parent fed225b4
......@@ -22,108 +22,104 @@
#include <assert.h>
char *color[] = {
"red",
"blue",
"green",
"orange",
"cyan",
"purple",
"yellow",
"red", "blue", "green", "orange", "cyan", "purple", "yellow",
};
#define DAG_NBCOLORS 7
void
libhqr_print_dot( const libhqr_tree_t *qrtree,
const char *filename )
libhqr_print_dot( const libhqr_tree_t *qrtree, const char *filename )
{
int *pos, *next, *done;
int k, m, n, lpos, prev, length;
int minMN = libhqr_imin( qrtree->mt, qrtree->nt );
FILE *f = fopen( filename, "w" );
int *pos, *next, *done;
int k, m, n, lpos, prev, length;
int minMN = libhqr_imin( qrtree->mt, qrtree->nt );
FILE *f = fopen( filename, "w" );
done = (int*)malloc( qrtree->mt * sizeof(int) );
pos = (int*)malloc( qrtree->mt * sizeof(int) );
next = (int*)malloc( qrtree->mt * sizeof(int) );
memset(pos, 0, qrtree->mt * sizeof(int) );
memset(next, 0, qrtree->mt * sizeof(int) );
if ( f == NULL ) {
perror("fopen");
return;
}
done = (int *)malloc( qrtree->mt * sizeof( int ) );
pos = (int *)malloc( qrtree->mt * sizeof( int ) );
next = (int *)malloc( qrtree->mt * sizeof( int ) );
memset( pos, 0, qrtree->mt * sizeof( int ) );
memset( next, 0, qrtree->mt * sizeof( int ) );
/* Print header */
fprintf(f, "digraph G { orientation=portrait; \n" );
fprintf( f, "digraph G { orientation=portrait; \n" );
/* Print labels */
for(m=0; m < qrtree->mt; m++) {
fprintf( f, "%d [label=\"%d\",color=white,pos=\"-1.,-%d.!\"]\n",
m, m, m );
for ( m = 0; m < qrtree->mt; m++ ) {
fprintf( f, "%d [label=\"%d\",color=white,pos=\"-1.,-%d.!\"]\n", m, m, m );
}
for(k=0; k<minMN; k++ ) {
int nb2reduce = qrtree->mt - k - 1;
for(m=k; m < qrtree->mt; m++) {
fprintf( f, "p%d_m%d_k%d [shape=point,width=0.1, pos=\"%d.,-%d.!\",color=\"%s\"];\n",
m, qrtree->mt, k, pos[m], m, color[ (m%qrtree->p) % DAG_NBCOLORS ] );
next[m] = qrtree->nextpiv( qrtree, k, m, qrtree->mt);
}
while( nb2reduce > 0 ) {
memset(done, 0, qrtree->mt * sizeof(int) );
for(m=qrtree->mt-1; m > (k-1); m--) {
n = next[m];
if ( next[n] != qrtree->mt ) {
continue;
for ( k = 0; k < minMN; k++ ) {
int nb2reduce = qrtree->mt - k - 1;
for ( m = k; m < qrtree->mt; m++ ) {
fprintf( f,
"p%d_m%d_k%d [shape=point,width=0.1, pos=\"%d.,-%d.!\",color=\"%s\"];\n",
m, qrtree->mt, k, pos[m], m,
color[( m % qrtree->p ) % DAG_NBCOLORS] );
next[m] = qrtree->nextpiv( qrtree, k, m, qrtree->mt );
}
while ( nb2reduce > 0 ) {
memset( done, 0, qrtree->mt * sizeof( int ) );
for ( m = qrtree->mt - 1; m > ( k - 1 ); m-- ) {
n = next[m];
if ( next[n] != qrtree->mt ) {
continue;
}
if ( n != qrtree->mt ) {
lpos = libhqr_imax( pos[m], pos[n] );
lpos++;
pos[m] = lpos;
pos[n] = lpos;
fprintf( f, "p%d_m%d_k%d [shape=point,width=0.1, pos=\"%d.,-%d.!\",color=\"%s\"];\n",
m, n, k, pos[m], m, color[ (m%qrtree->p) % DAG_NBCOLORS ] );
prev = qrtree->prevpiv( qrtree, k, m, n );
fprintf( f, "p%d_m%d_k%d->p%d_m%d_k%d [width=0.1,color=\"%s\"]\n",
m, prev, k,
m, n, k,
color[ (m%qrtree->p) % DAG_NBCOLORS ] );
prev = qrtree->prevpiv( qrtree, k, n, n );
if ( qrtree->gettype(qrtree, k, n) == 0 ) {
fprintf( f, "p%d_m%d_k%d->p%d_m%d_k%d [style=dotted, width=0.1,color=\"%s\"]\n",
n, prev, k,
m, n, k,
color[ (m%qrtree->p) % DAG_NBCOLORS ] );
if ( n != qrtree->mt ) {
lpos = libhqr_imax( pos[m], pos[n] );
lpos++;
pos[m] = lpos;
pos[n] = lpos;
fprintf( f, "p%d_m%d_k%d [shape=point,width=0.1, pos=\"%d.,-%d.!\",color=\"%s\"];\n",
m, n, k, pos[m], m,
color[( m % qrtree->p ) % DAG_NBCOLORS] );
prev = qrtree->prevpiv( qrtree, k, m, n );
fprintf( f, "p%d_m%d_k%d->p%d_m%d_k%d [width=0.1,color=\"%s\"]\n",
m, prev, k, m, n, k,
color[( m % qrtree->p ) % DAG_NBCOLORS] );
prev = qrtree->prevpiv( qrtree, k, n, n );
if ( qrtree->gettype( qrtree, k, n ) == 0 ) {
fprintf( f, "p%d_m%d_k%d->p%d_m%d_k%d [style=dotted, width=0.1,color=\"%s\"]\n",
n, prev, k, m, n, k,
color[( m % qrtree->p ) % DAG_NBCOLORS] );
}
else {
fprintf( f, "p%d_m%d_k%d->p%d_m%d_k%d [style=dashed, width=0.1,color=\"%s\"]\n",
n, prev, k,
m, n, k,
color[ (m%qrtree->p) % DAG_NBCOLORS ] );
else {
fprintf( f, "p%d_m%d_k%d->p%d_m%d_k%d [style=dashed, width=0.1,color=\"%s\"]\n",
n, prev, k, m, n, k,
color[( m % qrtree->p ) % DAG_NBCOLORS] );
}
next[m] = qrtree->nextpiv( qrtree, k, m, n);
done[m] = done[n] = 1;
nb2reduce--;
}
}
}
next[m] = qrtree->nextpiv( qrtree, k, m, n );
done[m] = done[n] = 1;
nb2reduce--;
}
}
}
}
length = 0;
for(m=0; m < qrtree->mt; m++) {
length = libhqr_imax(length, pos[m]);
for ( m = 0; m < qrtree->mt; m++ ) {
length = libhqr_imax( length, pos[m] );
}
length++;
for(k=0; k<length; k++) {
fprintf( f, "l%d [label=\"%d\",color=white,pos=\"%d.,0.5!\"]\n",
k, k, k );
for ( k = 0; k < length; k++ ) {
fprintf( f, "l%d [label=\"%d\",color=white,pos=\"%d.,0.5!\"]\n", k, k, k );
}
fprintf( f, "} // close graph\n" );
printf("Tic Max = %d\n", length-1);
printf( "Tic Max = %d\n", length - 1 );
fclose( f );
free(done);
free(pos);
free(next);
free( done );
free( pos );
free( next );
}
......@@ -69,7 +69,8 @@ static void
drawsvg_top_TS( FILE *file, int k, int x, int y, int w, int h )
{
int rc;
rc = fprintf(file,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"%s\" /> \n", x, y, w, h, colortree[k%NBCOLORS]);
rc = fprintf( file, "<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"%s\" /> \n",
x, y, w, h, colortree[k%NBCOLORS] );
if (rc < 0) {
fprintf(stderr, "Something wrong happened while writing the file (drawsvg_top_TS)\n");
......@@ -97,7 +98,8 @@ drawsvg_bot_TS( FILE *file, int k, int x, int y, int w, int h )
{
int rc, x2, y2, w2, h2;
rc = fprintf(file,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"%s\" /> \n", x, y, w, h, colortree[k%NBCOLORS]);
rc = fprintf( file, "<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"%s\" /> \n",
x, y, w, h, colortree[k%NBCOLORS] );
if (rc < 0) {
fprintf(stderr, "Something wrong happened while writing the file (drawsvg_bot_TS)\n");
return;
......@@ -108,7 +110,8 @@ drawsvg_bot_TS( FILE *file, int k, int x, int y, int w, int h )
w2 = (w / 2);
h2 = (h / 2);
rc = fprintf(file,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill =\"white\"/> \n", x2, y2, w2, h2);
rc = fprintf( file, "<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill =\"white\"/> \n",
x2, y2, w2, h2 );
if (rc < 0) {
fprintf(stderr, "Something wrong happened while writing the file (drawsvg_bot_TS)\n");
}
......@@ -134,7 +137,7 @@ static void
drawsvg_top_TT( FILE *file, int k, int x, int y, int w, int h )
{
int rc;
rc = fprintf( file,"<circle cx=\"%d\" cy=\"%d\" r=\"%d\" fill=\"%s\" /> \n",
rc = fprintf( file, "<circle cx=\"%d\" cy=\"%d\" r=\"%d\" fill=\"%s\" /> \n",
x + w / 2, y + h / 2, w / 2, colortree[k%NBCOLORS] );
if (rc < 0) {
fprintf(stderr, "Something wrong happened while writing the file (drawsvg_top_TT)\n");
......@@ -161,14 +164,14 @@ static void
drawsvg_bot_TT( FILE *file, int k, int x, int y, int w, int h )
{
int rc;
rc = fprintf( file,"<circle cx=\"%d\" cy=\"%d\" r=\"%d\" fill=\"%s\" /> \n",
rc = fprintf( file, "<circle cx=\"%d\" cy=\"%d\" r=\"%d\" fill=\"%s\" /> \n",
x + w / 2, y + h / 2, w / 2, colortree[k%NBCOLORS] );
if (rc < 0) {
fprintf(stderr, "Something wrong happened while writing the file (drawsvg_bot_TT)\n");
return;
}
rc = fprintf( file,"<circle cx=\"%d\" cy=\"%d\" r=\"%d\" fill=\"white\" /> \n",
rc = fprintf( file, "<circle cx=\"%d\" cy=\"%d\" r=\"%d\" fill=\"white\" /> \n",
x + w / 2, y + h / 2, w / 4 );
if (rc < 0) {
fprintf(stderr, "Something wrong happened while writing the file (drawsvg_bot_TT)\n");
......@@ -195,7 +198,8 @@ static void
drawsvg_line( FILE *file, int k, int x1, int y1, int x2, int y2 )
{
int rc;
rc = fprintf(file,"<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" style=\"fill:none;stroke:%s;stroke-width:2px;\"/> \n", x1, y1, x2, y2, colortree[k%NBCOLORS]);
rc = fprintf( file, "<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" style=\"fill:none;stroke:%s;stroke-width:2px;\"/>\n",
x1, y1, x2, y2, colortree[k%NBCOLORS] );
if (rc < 0) {
fprintf(stderr, "Something wrong happened while writing the file (drawsvg_line)\n");
......
......@@ -314,14 +314,12 @@ hqr_currpiv(const libhqr_tree_t *qrtree, int k, int m)
switch( hqr_gettype( qrtree, k, m ) )
{
case 0:
tmp = lm / a;
/* tmpk = (k + p - 1 - m%p) / p / a; */
tmp = lm / a;
tmpk = k / (p * a);
return ( tmp == tmpk ) ? k + (m-k)%p : tmp * a * p + rank ;
break;
case 1:
tmp = arg->llvl->currpiv(arg->llvl, k, m);
/* tmpk = (k + p - 1 - m%p) / p / a; */
tmp = arg->llvl->currpiv(arg->llvl, k, m);
tmpk = k / (p * a);
return ( tmp == tmpk ) ? k + (m-k)%p : tmp * a * p + rank ;
break;
......@@ -583,10 +581,6 @@ hqr_prevpiv(const libhqr_tree_t *qrtree, int k, int pivot, int start)
case LIBHQR_KILLED_BY_TS:
/* Search for predecessor in TS tree */
/* if ( ( start+p < gmt ) && */
/* ( (((start+p) / p) % a) != 0 ) ) */
/* return start + p; */
if ( start == pivot ) {
tmp = lpivot + a - 1 - lpivot%a;
nextp = tmp * p + rpivot;
......@@ -595,7 +589,7 @@ hqr_prevpiv(const libhqr_tree_t *qrtree, int k, int pivot, int start)
nextp -= p;
}
} else {
nextp = start - p; /*(lstart - 1) * p + rpivot;*/
nextp = start - p;
}
assert(nextp < gmt);
if ( pivot < nextp ) {
......@@ -753,7 +747,7 @@ libhqr_initfct_hqr( libhqr_tree_t *qrtree,
/* Compute parameters */
if ( a == -1) {
a = 4; /* TODO: add automatic computation */
a = 4;
}
else {
a = libhqr_imax( a, 1 );
......@@ -983,10 +977,8 @@ libhqr_walk_stepk( const libhqr_tree_t *qrtree,
(qrtree->prevpiv(qrtree, k, p, p) != qrtree->mt) )
{
libhqr_queue_tile_push(&tt,p);
/* printf("PUSH TT: %d\n", p); */
}
libhqr_queue_tile_push(&ts, p);
/* printf("PUSH TS: %d\n", p); */
p = qrtree->prevpiv(qrtree, k, pivot, p);
assert( p != -1 );
}
......@@ -998,12 +990,7 @@ libhqr_walk_stepk( const libhqr_tree_t *qrtree,
while( (tsid != -1) &&
(tsid != ttid) )
{
/* printf( "TS=%d, TT=%d\n", tsid, ttid ); */
tsid = libhqr_queue_tile_pop(&ts);
/* printf("POP TS: %d\n", tsid); */
/* printf("Call function on (%d, %d)\n",
qrtree->currpiv(qrtree, k, tsid), tsid ); */
assert(m < (qrtree->mt-1));
tiles[m] = tsid;
m++;
......@@ -1014,7 +1001,6 @@ libhqr_walk_stepk( const libhqr_tree_t *qrtree,
tiles[m] = p;
//assert(m == (qrtree->mt-1));
assert(ts == NULL);
assert(tt == NULL);
......
......@@ -137,7 +137,7 @@ rdmtx_nextpiv(const libhqr_tree_t *qrtree, int k, int p, int m){
libhqr_tile_args_t *args = (libhqr_tile_args_t*)(qrtree->args);
libhqr_tile_info_t *tileinfo = args->tileinfo;
int gmt = qrtree->mt;
// myassert( (m > p) && (p >= k) );
myassert( (m == gmt) || (p == rdmtx_currpiv( qrtree, k, m )) );
if(m == qrtree->mt){
id = (k * qrtree->mt) + p;
......@@ -155,7 +155,7 @@ rdmtx_prevpiv(const libhqr_tree_t *qrtree, int k, int p, int m){
libhqr_tile_args_t *args = (libhqr_tile_args_t*)(qrtree->args);
libhqr_tile_info_t *tileinfo = args->tileinfo;
int gmt = qrtree->mt;
//myassert( m >= p && p >= k );
myassert( m < gmt );
myassert( m == p || p == rdmtx_currpiv( qrtree, k, m ) );
......
This diff is collapsed.
......@@ -73,8 +73,8 @@ libhqr_initmtx_tphqr( libhqr_tree_t *qrtree,
libhqr_tile_args_t *args;
libhqr_tile_info_t *tileinfo;
int *killers, *pivots;
int low_mt, i, j, k, l;
int lp, la, killer_index;
int low_mt, i, j, k;
int lp, la;
if ( qrtree == NULL ) {
fprintf( stderr, "libhqr_hqr_init, illegal value of qrtree" );
......@@ -91,7 +91,7 @@ libhqr_initmtx_tphqr( libhqr_tree_t *qrtree,
/* Compute parameters */
if ( a == -1 ) {
a = 4; /* TODO: add automatic computation */
a = 4;
}
else {
a = libhqr_imax( a, 1 );
......@@ -166,7 +166,7 @@ libhqr_initmtx_tphqr( libhqr_tree_t *qrtree,
/* Initialize the matrix */
for ( k = 0; k < qrtree->nt; k++, killers += qrtree->mt, tileinfo += qrtree->mt ) {
killer_index = 0;
int l, killer_index = 0;
/* Move remaining rows from level 3 to level 2 */
for ( i = 0; i < ( low_mt * p ); i++ ) {
......
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