Mentions légales du service

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