Une MAJ de sécurité est nécessaire sur notre version actuelle. Elle sera effectuée lundi 02/08 entre 12h30 et 13h. L'interruption de service devrait durer quelques minutes (probablement moins de 5 minutes).

Commit 917b1be0 authored by Mathieu Faverge's avatar Mathieu Faverge
Browse files

cleanup(MatrixVisualizer): Pursue cleanup in a better use of the data structure

parent ca1789a8
......@@ -52,6 +52,7 @@ void Zooming::move(double xStart, double xEnd, double yStart, double yEnd)
clean_move( &xStart, &xEnd, &yStart, &yEnd );
// Convert to column/row indexes
int startCol = xStart * m_matrix->m_colsnbr;
int endCol = xEnd * m_matrix->m_colsnbr;
int startRow = yStart * m_matrix->m_rowsnbr;
......@@ -59,7 +60,9 @@ void Zooming::move(double xStart, double xEnd, double yStart, double yEnd)
// Find first cblk
int startCblk = 0;
int endCblk = 0;
int endCblk = 0;
// Search for beginnings
cblk = m_matrix->m_cblktab;
for (i = 0; i < m_matrix->m_cblknbr; ++i, cblk++)
{
......@@ -106,23 +109,18 @@ void Zooming::move(double xStart, double xEnd, double yStart, double yEnd)
int lbloknum = (i + 1 != m_matrix->m_cblknbr ? cblk[1].m_bloknum : m_matrix->m_bloknbr);
// Get first block size in col from x to xEnd
int startingCol = cblk->m_fcolnum;
int endingCol = cblk->m_lcolnum;
int x = (startingCol - startCol) * xCoeff;
int xEnd = (endingCol - startCol) * xCoeff;
int x = (cblk->m_fcolnum - startCol) * xCoeff;
int xEnd = (cblk->m_lcolnum - startCol) * xCoeff;
blok = m_matrix->m_bloktab + fbloknum;
for (j = fbloknum; j < lbloknum; ++j)
for (j = fbloknum; j < lbloknum; ++j, blok++)
{
if (blok->m_frownum >= startRow && blok->m_frownum <= endRow)
if ( (blok->m_frownum >= startRow) &&
(blok->m_frownum <= endRow ) )
{
// Get first block size in row from y to yEnd
int startingRow = blok->m_frownum;
int endingRow = blok->m_lrownum;
int y = (startingRow - startRow) * yCoeff;
int yEnd = (endingRow - startRow) * yCoeff;
int y = (blok->m_frownum - startRow) * yCoeff;
int yEnd = (blok->m_lrownum - startRow) * yCoeff;
m = x;
do
......
......@@ -18,26 +18,31 @@ static inline int32_t imax(int32_t a, int32_t b)
/* Macros */
#define memFree(ptr) free((void*)(ptr))
#define memFree_null(ptr) do \
{ \
memFree( ptr ); \
(ptr) = NULL; \
} while(0)
{ \
memFree( ptr ); \
(ptr) = NULL; \
} while(0)
void symbol_matrix_init(symbol_matrix_t* matrix)
{
memset(matrix, 0, sizeof(symbol_matrix_t));
return;
}
void symbol_matrix_deinit(symbol_matrix_t* matrix)
{
if (matrix->m_cblktab != nullptr)
{
memFree_null(matrix->m_cblktab);
}
if (matrix->m_bloktab != nullptr)
{
memFree_null(matrix->m_bloktab);
}
if (matrix->m_browtab != nullptr)
{
memFree_null(matrix->m_browtab);
}
memset(matrix, 0, sizeof(symbol_matrix_t));
......@@ -132,10 +137,9 @@ void symbol_matrix_print_stats(symbol_matrix_t* matrix)
" Blok height max %10ld\n"
" Blok height avg %11.2lf\n"
" Blok height stdev %11.2lf\n"
" Matrix structure space %11.2lf %s\n",
" Matrix structure space %11.2lf %cB\n",
(long)cblknbr, (long)bloknbr,
(long)cblkmin, (long)cblkmax, cblkavg1, cblkavg2,
(long)blokmin, (long)blokmax, blokavg1, blokavg2,
MEMORY_WRITE( mem ), MEMORY_UNIT_WRITE( mem )
);
print_get_value( mem ), print_get_units( mem ) );
}
......@@ -5,45 +5,42 @@
typedef struct symbol_cblk_s
{
int32_t m_fcolnum; // First column index
int32_t m_lcolnum; // Last column index (exclusive)
int32_t m_bloknum; // First blok in column
int32_t m_flags; // Flags
int32_t m_fcolnum; // First column index
int32_t m_lcolnum; // Last column index (exclusive)
int32_t m_bloknum; // First blok in column
int32_t m_flags; // Flags
} symbol_cblk_t;
#define CBLK_FLAG_2D 1
#define CBLK_FLAG_1D CBLK_FLAG_2D << 1
typedef struct symbol_blok_s
{
int32_t m_frownum; // First row index
int32_t m_lrownum; // Last row index (exclusive)
int32_t m_frownum; // First row index
int32_t m_lrownum; // Last row index (exclusive)
int32_t m_lcblknm; // Local column blok
int32_t m_fcblknm; // Facing column blok
uint32_t m_localization; // Localization
int32_t m_flags;
uint32_t m_localization; // Localization
int32_t m_flags;
} symbol_blok_t;
#define BLOK_FLAG_IN_TREE 1
#define BLOK_FLAG_IN_TREE 1
/*
How localization works ?
=> See Z-curve identification
How localization works ?
=> See Z-curve identification
We use Z-curve to ID the quadtree nodes and we flip the bit of the level.
For example if we are in the third level of quadtreefication and we have the ID 2:
We use Z-curve to ID the quadtree nodes and we flip the bit of the level.
For example if we are in the third level of quadtreefication and we have the ID 2:
0000 0000 0001 0010
^ ^
| ID of the node
Bit flipped for the level
0000 0000 0001 0010
^ ^
| ID of the node
Bit flipped for the level
With this technique we can store a 32 bits localization to allow 15 levels of details
and know the parents of any node due to the Z-curve :D
With this technique we can store a 32 bits localization to allow 15 levels of details
and know the parents of any node due to the Z-curve :D
*/
*/
typedef struct symbol_matrix_s
{
......@@ -52,7 +49,7 @@ typedef struct symbol_matrix_s
int32_t m_cblknbr;
int32_t m_bloknbr;
int32_t m_colsnbr;
int32_t m_colsnbr;
int32_t m_rowsnbr;
symbol_cblk_t* m_cblktab;
......
......@@ -7,23 +7,23 @@
namespace Helper
{
void log(LogStatus status, const char* format, ...)
{
va_list ap;
va_start(ap, format);
void log(LogStatus status, const char* format, ...)
{
va_list ap;
va_start(ap, format);
Matrix_visualizer::Get()->log(status, format, ap);
Matrix_visualizer::Get()->log(status, format, ap);
va_end(ap);
}
va_end(ap);
}
void set_infos(const char* format, ...)
{
va_list ap;
va_start(ap, format);
void set_infos(const char* format, ...)
{
va_list ap;
va_start(ap, format);
Matrix_visualizer::Get()->set_infos(format, ap);
Matrix_visualizer::Get()->set_infos(format, ap);
va_end(ap);
}
va_end(ap);
}
}
......@@ -10,20 +10,35 @@ enum LogStatus
COUNT
};
#define MEMORY_WRITE(mem) ( ((mem) < 1<<10) ? \
( (double)(mem) ) : \
( ( (mem) < 1<<20 ) ? \
( (double)(mem)/(double)(1<<10) ) : \
( ((mem) < 1<<30 ) ? \
( (double)(mem)/(double)(1<<20) ) : \
( (double)(mem)/(double)(1<<30) ))))
#define MEMORY_UNIT_WRITE(mem) (((mem) < 1<<10) ? \
"o" : \
( ( (mem) < 1<<20 ) ? \
"Ko" : \
( ( (mem) < 1<<30 ) ? \
"Mo" : \
"Go" )))
static inline double
print_get_value( double flops )
{
static double ratio = (double)(1<<10);
int unit = 0;
while ( (flops > ratio) && (unit < 9) ) {
flops /= ratio;
unit++;
}
return flops;
}
static inline char
print_get_units( double flops )
{
static char units[9] = { ' ', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y' };
static double ratio = (double)(1<<10);
int unit = 0;
while ( (flops > ratio) && (unit < 9) ) {
flops /= ratio;
unit++;
}
return units[unit];
}
#define MEMORY_WRITE(mem) printflopsv( mem )
#define MEMORY_UNIT_WRITE(mem) printflopsu( mem )
namespace Helper
{
......
......@@ -10,17 +10,17 @@ int pastix_read_symbol(FILE* stream, symbol_matrix_t* matrix)
int32_t versval;
int32_t cblknum;
int32_t bloknum;
int32_t nodenbr;
int32_t nodenbr;
int32_t result = 0;
int32_t result = 0;
result += pastix_read_int(stream, &versval);
result += pastix_read_int(stream, &matrix->m_cblknbr);
result += pastix_read_int(stream, &matrix->m_bloknbr);
result += pastix_read_int(stream, &nodenbr);
result += pastix_read_int(stream, &matrix->m_baseval);
result += pastix_read_int(stream, &versval);
result += pastix_read_int(stream, &matrix->m_cblknbr);
result += pastix_read_int(stream, &matrix->m_bloknbr);
result += pastix_read_int(stream, &nodenbr);
result += pastix_read_int(stream, &matrix->m_baseval);
if ((result != 5) ||
if ((result != 5) ||
(versval < 0) ||
(versval > 1) ||
(matrix->m_bloknbr < matrix->m_cblknbr) ||
......@@ -30,6 +30,7 @@ int pastix_read_symbol(FILE* stream, symbol_matrix_t* matrix)
return 1;
}
Helper::log(LogStatus::MESSAGE, "Version %d", versval);
matrix->m_cblktab = (symbol_cblk_t*)malloc((matrix->m_cblknbr + 1) * sizeof(symbol_cblk_t));
matrix->m_bloktab = (symbol_blok_t*)malloc(matrix->m_bloknbr * sizeof(symbol_blok_t));
......@@ -41,54 +42,59 @@ int pastix_read_symbol(FILE* stream, symbol_matrix_t* matrix)
return 1;
}
symbol_cblk_t *cblk = matrix->m_cblktab;
int32_t cblknbr = matrix->m_cblknbr;
int32_t maxcol = 0;
for (cblknum = 0; cblknum < cblknbr; ++cblknum)
int32_t maxcol = 0;
for (cblknum = 0; cblknum < cblknbr; ++cblknum, ++cblk)
{
result = pastix_read_int(stream, &(matrix->m_cblktab[cblknum].m_fcolnum));
result += pastix_read_int(stream, &(matrix->m_cblktab[cblknum].m_lcolnum));
result += pastix_read_int(stream, &(matrix->m_cblktab[cblknum].m_bloknum));
result = pastix_read_int(stream, &(cblk->m_fcolnum));
result += pastix_read_int(stream, &(cblk->m_lcolnum));
result += pastix_read_int(stream, &(cblk->m_bloknum));
if ((result != 3) ||
(matrix->m_cblktab[cblknum].m_fcolnum > matrix->m_cblktab[cblknum].m_lcolnum))
(cblk->m_fcolnum > cblk->m_lcolnum))
{
Helper::log(LogStatus::FATAL, "Bad input while reading cblk !");
return 1;
}
if (matrix->m_cblktab[cblknum].m_lcolnum > maxcol)
maxcol = matrix->m_cblktab[cblknum].m_lcolnum;
if (cblk->m_lcolnum > maxcol)
{
maxcol = cblk->m_lcolnum;
}
matrix->m_cblktab[cblknum].m_flags = 0;
matrix->m_cblktab[cblknum].m_lcolnum++;
cblk->m_flags = 0;
cblk->m_lcolnum++;
}
matrix->m_cblktab[cblknbr].m_fcolnum = matrix->m_cblktab[cblknbr].m_lcolnum = nodenbr + matrix->m_baseval;
matrix->m_cblktab[cblknbr].m_bloknum = matrix->m_bloknbr + matrix->m_baseval;
cblk->m_fcolnum = cblk->m_lcolnum = nodenbr + matrix->m_baseval;
cblk->m_bloknum = matrix->m_bloknbr + matrix->m_baseval;
matrix->m_colsnbr = maxcol + 1;
matrix->m_colsnbr = maxcol + 1;
symbol_blok_t *blok = matrix->m_bloktab;
int32_t bloknbr = matrix->m_bloknbr;
int32_t maxrow = 0;
for (bloknum = 0; bloknum < bloknbr; ++bloknum)
int32_t maxrow = 0;
for (bloknum = 0; bloknum < bloknbr; ++bloknum, ++blok)
{
result = pastix_read_int(stream, &matrix->m_bloktab[bloknum].m_frownum);
result += pastix_read_int(stream, &matrix->m_bloktab[bloknum].m_lrownum);
result += pastix_read_int(stream, &matrix->m_bloktab[bloknum].m_fcblknm);
result = pastix_read_int(stream, &(blok->m_frownum));
result += pastix_read_int(stream, &(blok->m_lrownum));
result += pastix_read_int(stream, &(blok->m_fcblknm));
if ((result != 3) ||
(matrix->m_bloktab[bloknum].m_frownum > matrix->m_bloktab[bloknum].m_lrownum))
(blok->m_frownum > blok->m_lrownum))
{
Helper::log(LogStatus::FATAL, "Bad input while reading blok %d !", bloknum);
return 1;
}
if (matrix->m_bloktab[bloknum].m_lrownum > maxrow)
maxrow = matrix->m_bloktab[bloknum].m_lrownum;
matrix->m_bloktab[bloknum].m_lrownum++;
matrix->m_bloktab[bloknum].m_localization = 0;
matrix->m_bloktab[bloknum].m_flags = 0;
if (blok->m_lrownum > maxrow)
{
maxrow = blok->m_lrownum;
}
blok->m_lrownum++;
blok->m_localization = 0;
blok->m_flags = 0;
// Compatibility block
{
......@@ -102,9 +108,9 @@ int pastix_read_symbol(FILE* stream, symbol_matrix_t* matrix)
}
matrix->m_dof = 1;
matrix->m_rowsnbr = maxrow + 1;
matrix->m_rowsnbr = maxrow + 1;
Helper::log(LogStatus::MESSAGE,
Helper::log(LogStatus::MESSAGE,
"Loaded header:\n"
" Version: %10d\n"
" Number of cblk: %10d\n"
......@@ -116,7 +122,7 @@ int pastix_read_symbol(FILE* stream, symbol_matrix_t* matrix)
matrix->m_cblknbr, matrix->m_rowsnbr,
matrix->m_bloknbr, nodenbr,
matrix->m_baseval
);
);
return 0;
}
......
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