ColPack
Utilities/extra.h File Reference
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <iomanip>
#include <ctime>
#include <cstdlib>
#include <stdarg.h>
#include <list>
#include <set>
#include <map>
#include <vector>
#include "ColPackHeaders.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define DOT   1
#define NEATO   2
#define TWOPI   3
#define CIRCO   4
#define FDP   5

Functions

int WriteMatrixMarket_ADOLCInput (string s_postfix, int i_mode,...)
 Write out to the file ADOLC Input using Matrix Market format.
int ConvertHarwellBoeingDouble (string &num_string)
 Convert a number string under Harwell-Boeing format to the format that C++ can understand.
string itoa (int i)
vector< string > getListOfColors (string s_InputFile)
int buildDotWithoutColor (ColPack::GraphColoringInterface &g, vector< string > &ListOfColors, string fileName)
int buildDotWithColor (ColPack::GraphColoringInterface &g, vector< string > &ListOfColors, string fileName)
 Build dot file with colors, also highlight StarColoringConflicts.
int buildDotWithoutColor (ColPack::BipartiteGraphPartialColoringInterface &g, vector< string > &ListOfColors, string fileName)
int buildDotWithColor (ColPack::BipartiteGraphPartialColoringInterface &g, vector< string > &ListOfColors, string fileName)
int buildDotWithoutColor (ColPack::BipartiteGraphBicoloringInterface &g, vector< string > &ListOfColors, string fileName)
int buildDotWithColor (ColPack::BipartiteGraphBicoloringInterface &g, vector< string > &ListOfColors, string fileName)
int ReadRowCompressedFormat (string s_InputFile, unsigned int ***uip3_SparsityPattern, int &rowCount, int &columnCount)
 Read a Row Compressed Format file.
bool isValidOrdering (vector< int > &ordering, int offset=0)
 Test and make sure that this is a valid ordering.
void randomOrdering (vector< int > &ordering)
string toUpper (string input)
 Convert all the characters in input to upper case, ' ', '\ t', '\ n' will be converted to '_'.
int ConvertRowCompressedFormat2SparseSolversFormat_StructureOnly (unsigned int **uip2_HessianSparsityPattern, unsigned int ui_rowCount, unsigned int **ip2_RowIndex, unsigned int **ip2_ColumnIndex)
 Build the index struture from Row Compressed Format to Sparse Solvers Format.
int ConvertCoordinateFormat2RowCompressedFormat (unsigned int *uip1_RowIndex, unsigned int *uip1_ColumnIndex, double *dp1_HessianValue, int i_RowCount, int i_NonZeroCount, unsigned int ***dp3_Pattern, double ***dp3_Values)
 Convert Coordinate Format to Row Compressed Format.
void ConvertFileDIMACSFormat2MatrixMarketFormat (string fileNameNoExt)
 Covert file with DIMACS format to Matrix Market format.
int ConvertMatrixMarketFormat2RowCompressedFormat (string s_InputFile, unsigned int ***uip3_SparsityPattern, double ***dp3_Value, int &rowCount, int &columnCount)
 Read the sparse matrix from Matrix-Market-format file and convert to Row Compressed format (used by ADIC) "uip3_SparsityPattern" & "dp3_Value".
int ConvertRowCompressedFormat2CSR (unsigned int **uip2_SparsityPattern_RowCompressedFormat, int i_rowCount, int **ip_RowIndex, int **ip_ColumnIndex)
 Convert Row Compressed format (used by ADOL-C) to zero-based indexing, 3-array variation CSR format (used by ADIC)
int ConvertRowCompressedFormat2ADIC (unsigned int **uip2_SparsityPattern_RowCompressedFormat, int i_rowCount, double **dp2_Value, std::list< std::set< int > > &lsi_SparsityPattern, std::list< std::vector< double > > &lvd_Value)
int MatrixMultiplication_VxS (unsigned int **uip3_SparsityPattern, double **dp3_Value, int rowCount, int columnCount, double **dp2_seed, int colorCount, double ***dp3_CompressedMatrix)
 Multiply the original sparse matrix (uip3_SparsityPattern,dp3_Value) (in compress sparse row format) with the seed matrix dp2_seed and store the result in "dp3_CompressedMatrix".
int MatrixMultiplication_VxS__usingVertexPartialColors (std::list< std::set< int > > &lsi_SparsityPattern, std::list< std::vector< double > > &lvd_Value, int columnCount, vector< int > &vi_VertexPartialColors, int colorCount, double ***dp3_CompressedMatrix)
int MatrixMultiplication_SxV (unsigned int **uip3_SparsityPattern, double **dp3_Value, int rowCount, int columnCount, double **dp2_seed, int colorCount, double ***dp3_CompressedMatrix)
 Multiply the seed matrix dp2_seed with the original sparse matrix (uip3_SparsityPattern,dp3_Value) (in compress sparse row format) and store the result in "dp3_CompressedMatrix".
bool CompressedRowMatricesAreEqual (double **dp3_Value, double **dp3_NewValue, int rowCount, bool compare_exact=1, bool print_all=0)
 Compare dp3_Value with dp3_NewValue and see if all the values are equal.
bool ADICMatricesAreEqual (std::list< std::vector< double > > &lvd_Value, std::list< std::vector< double > > &lvd_NewValue, bool compare_exact=1, bool print_all=0)
int Times2Plus1point5 (double **dp2_Values, int i_RowCount, int i_ColumnCount)
 just manipulate the value of dp2_Values a little bit. Each non-zero entry in the matrix * 2 + 1.5.
int Times2 (double **dp2_Values, int i_RowCount, int i_ColumnCount)
 just manipulate the value of dp2_Values a little bit. Each non-zero entry in the matrix * 2.
int GenerateValues (unsigned int **uip2_SparsityPattern, int rowCount, double ***dp3_Value)
 Allocate memory and generate random values for dp3_Value.
int GenerateValuesForSymmetricMatrix (unsigned int **uip2_SparsityPattern, int rowCount, double ***dp3_Value)
 Allocate memory and generate random values for dp3_Value of a Symmetric Matrix.
int DisplayADICFormat_Sparsity (std::list< std::set< int > > &lsi_SparsityPattern)
int DisplayADICFormat_Value (std::list< std::vector< double > > &lvd_Value)
int displayGraph (map< int, map< int, bool > > *graph, vector< int > *vi_VertexColors=NULL, int i_RunInBackground=false, int filter=DOT)
int buildDotWithoutColor (map< int, map< int, bool > > *graph, vector< string > &ListOfColors, string fileName)
int buildDotWithColor (map< int, map< int, bool > > *graph, vector< int > *vi_VertexColors, vector< string > &ListOfColors, string fileName)

Define Documentation

#define CIRCO   4

Definition at line 54 of file extra.h.

Referenced by displayGraph().

#define DOT   1

Definition at line 51 of file extra.h.

#define FDP   5
#define NEATO   2

Definition at line 52 of file extra.h.

Referenced by displayGraph().

#define TWOPI   3

Definition at line 53 of file extra.h.

Referenced by displayGraph().


Function Documentation

bool ADICMatricesAreEqual ( std::list< std::vector< double > > &  lvd_Value,
std::list< std::vector< double > > &  lvd_NewValue,
bool  compare_exact = 1,
bool  print_all = 0 
)

Definition at line 1310 of file extra.cpp.

Referenced by main().

Here is the caller graph for this function:

int buildDotWithColor ( ColPack::GraphColoringInterface g,
vector< string > &  ListOfColors,
string  fileName 
)

Build dot file with colors, also highlight StarColoringConflicts.

!!! TO DO: improve this function so that it can detect conflicts of all coloring types

Definition at line 608 of file extra.cpp.

References _UNKNOWN, ColPack::GraphCore::GetEdges(), ColPack::GraphColoring::GetStarColoringConflicts(), ColPack::GraphColoring::GetVertexColors(), ColPack::GraphCore::GetVertices(), itoa(), and STEP_DOWN.

Here is the call graph for this function:

int buildDotWithColor ( ColPack::BipartiteGraphBicoloringInterface g,
vector< string > &  ListOfColors,
string  fileName 
)

Definition at line 562 of file extra.cpp.

References Pause().

Here is the call graph for this function:

int buildDotWithColor ( map< int, map< int, bool > > *  graph,
vector< int > *  vi_VertexColors,
vector< string > &  ListOfColors,
string  fileName 
)

Definition at line 267 of file extra.cpp.

References _UNKNOWN, and itoa().

Referenced by displayGraph().

Here is the call graph for this function:

Here is the caller graph for this function:

int buildDotWithoutColor ( ColPack::GraphColoringInterface g,
vector< string > &  ListOfColors,
string  fileName 
)

Definition at line 570 of file extra.cpp.

References ColPack::GraphCore::GetEdges(), ColPack::GraphCore::GetVertices(), itoa(), and STEP_DOWN.

Here is the call graph for this function:

int buildDotWithoutColor ( ColPack::BipartiteGraphPartialColoringInterface g,
vector< string > &  ListOfColors,
string  fileName 
)

Definition at line 384 of file extra.cpp.

References ColPack::BipartiteGraphCore::GetEdges(), ColPack::BipartiteGraphCore::GetLeftVertices(), itoa(), and STEP_DOWN.

Here is the call graph for this function:

int buildDotWithoutColor ( ColPack::BipartiteGraphBicoloringInterface g,
vector< string > &  ListOfColors,
string  fileName 
)

Definition at line 556 of file extra.cpp.

References Pause().

Here is the call graph for this function:

int buildDotWithoutColor ( map< int, map< int, bool > > *  graph,
vector< string > &  ListOfColors,
string  fileName 
)

Definition at line 231 of file extra.cpp.

References itoa().

Referenced by displayGraph().

Here is the call graph for this function:

Here is the caller graph for this function:

bool CompressedRowMatricesAreEqual ( double **  dp3_Value,
double **  dp3_NewValue,
int  rowCount,
bool  compare_exact = 1,
bool  print_all = 0 
)

Compare dp3_Value with dp3_NewValue and see if all the values are equal.

If (compare_exact == 0) num1 and num2 are consider equal if 0.99 <= num1/num2 <= 1.02 If (print_all == 1) all cases of non-equal will be print out. Normally (when print_all == 0), this rountine will stop after the first non-equal.

Definition at line 1371 of file extra.cpp.

Referenced by main().

Here is the caller graph for this function:

int ConvertCoordinateFormat2RowCompressedFormat ( unsigned int *  uip1_RowIndex,
unsigned int *  uip1_ColumnIndex,
double *  dp1_HessianValue,
int  i_RowCount,
int  i_NonZeroCount,
unsigned int ***  dp3_Pattern,
double ***  dp3_Values 
)

Convert Coordinate Format to Row Compressed Format.

dp3_Pattern and dp3_Values will be allocated memory (using malloc) and populated with the matrix structure in Row Compressed Format

Input: (Coordinate Format)

  • unsigned int* uip1_RowIndex
  • unsigned int* uip1_ColumnIndex
  • double* dp1_HessianValue
  • int i_RowCount: number of rows of the matrix
  • int i_ColumnCount: number of columns of the matrix

Output: (Row Compressed Format)

  • unsigned int *** dp3_Pattern
  • double*** dp3_Values

Definition at line 836 of file extra.cpp.

Referenced by ColPack::HessianRecovery::IndirectRecover_CoordinateFormat_unmanaged().

Here is the caller graph for this function:

void ConvertFileDIMACSFormat2MatrixMarketFormat ( string  fileNameNoExt)

Covert file with DIMACS format to Matrix Market format.

DIMACS graph format: http://www.dis.uniroma1.it/~challenge9/format.shtml#graph Note: DIMACS graph format is for directed graph => the equivalent matrix is squared and non-systemic

Read input from file "<fileNameNoExt>.gr" (DIMACS graph format) and generate file "<fileNameNoExt>.mtx" (Matrix Market format)

Definition at line 878 of file extra.cpp.

int ConvertHarwellBoeingDouble ( string &  num_string)

Convert a number string under Harwell-Boeing format to the format that C++ can understand.

For example: -6.310289677458059D-07 to -6.310289677458059E-07

Essentially, this function just search backward for the letter D and replace it with E

Return value:

  • 0 if letter D is not found
  • 1 if latter D is found and replace by letter E

Definition at line 343 of file extra.cpp.

Referenced by ColPack::GraphInputOutput::ReadHarwellBoeingAdjacencyGraph().

Here is the caller graph for this function:

int ConvertMatrixMarketFormat2RowCompressedFormat ( string  s_InputFile,
unsigned int ***  uip3_SparsityPattern,
double ***  dp3_Value,
int &  rowCount,
int &  columnCount 
)

Read the sparse matrix from Matrix-Market-format file and convert to Row Compressed format (used by ADIC) "uip3_SparsityPattern" & "dp3_Value".

Read in a matrix from matrix-market format file and create a matrix stored in compressed sparse row format The Matrix-Market-format has 3 values in each row, the row index, column index and numerical value of each nonzero. The last 4 parameters of this routine are output parameters (unsigned int *** uip3_SparsityPattern, double*** dp3_Value,int &rowCount, int &columnCount)

Definition at line 1046 of file extra.cpp.

References ColPack::f(), mm_is_coordinate, mm_is_general, mm_is_integer, mm_is_pattern, mm_is_real, mm_is_symmetric, mm_read_banner(), mm_typecode_to_str(), and Pause().

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

int ConvertRowCompressedFormat2ADIC ( unsigned int **  uip2_SparsityPattern_RowCompressedFormat,
int  i_rowCount,
double **  dp2_Value,
std::list< std::set< int > > &  lsi_SparsityPattern,
std::list< std::vector< double > > &  lvd_Value 
)

Definition at line 1000 of file extra.cpp.

Referenced by main().

Here is the caller graph for this function:

int ConvertRowCompressedFormat2CSR ( unsigned int **  uip2_SparsityPattern_RowCompressedFormat,
int  i_rowCount,
int **  ip_RowIndex,
int **  ip_ColumnIndex 
)

Convert Row Compressed format (used by ADOL-C) to zero-based indexing, 3-array variation CSR format (used by ADIC)

Return 0 upon successful.

Definition at line 1016 of file extra.cpp.

Referenced by main().

Here is the caller graph for this function:

int ConvertRowCompressedFormat2SparseSolversFormat_StructureOnly ( unsigned int **  uip2_HessianSparsityPattern,
unsigned int  ui_rowCount,
unsigned int **  ip2_RowIndex,
unsigned int **  ip2_ColumnIndex 
)

Build the index struture from Row Compressed Format to Sparse Solvers Format.

ip2_RowIndex and ip2_ColumnIndex will be allocated memory (using malloc) and populated with the matrix structure in Sparse Solvers Format

Input:

  • uip2_HessianSparsityPattern in Row Compressed Format
  • ui_rowCount

Output:

  • ip2_RowIndex[ui_rowCount + 1] for Sparse Solvers Format
  • ip2_ColumnIndex[ ip2_RowIndex[ui_rowCount] - 1] for Sparse Solvers Format

Definition at line 798 of file extra.cpp.

References Pause().

Referenced by ColPack::HessianRecovery::DirectRecover_SparseSolversFormat_unmanaged(), and ColPack::HessianRecovery::IndirectRecover_SparseSolversFormat_unmanaged().

Here is the call graph for this function:

Here is the caller graph for this function:

int DisplayADICFormat_Sparsity ( std::list< std::set< int > > &  lsi_SparsityPattern)

Definition at line 1432 of file extra.cpp.

Referenced by main().

Here is the caller graph for this function:

int DisplayADICFormat_Value ( std::list< std::vector< double > > &  lvd_Value)

Definition at line 1458 of file extra.cpp.

Referenced by main().

Here is the caller graph for this function:

int displayGraph ( map< int, map< int, bool > > *  graph,
vector< int > *  vi_VertexColors = NULL,
int  i_RunInBackground = false,
int  filter = DOT 
)

Definition at line 198 of file extra.cpp.

References buildDotWithColor(), buildDotWithoutColor(), CIRCO, FDP, getListOfColors(), itoa(), NEATO, and TWOPI.

Referenced by ColPack::GraphColoring::BuildStarFromColorCombination_forChecking().

Here is the call graph for this function:

Here is the caller graph for this function:

int GenerateValues ( unsigned int **  uip2_SparsityPattern,
int  rowCount,
double ***  dp3_Value 
)

Allocate memory and generate random values for dp3_Value.

Definition at line 955 of file extra.cpp.

int GenerateValuesForSymmetricMatrix ( unsigned int **  uip2_SparsityPattern,
int  rowCount,
double ***  dp3_Value 
)

Allocate memory and generate random values for dp3_Value of a Symmetric Matrix.

Definition at line 973 of file extra.cpp.

vector<string> getListOfColors ( string  s_InputFile)

Definition at line 362 of file extra.cpp.

Referenced by displayGraph().

Here is the caller graph for this function:

bool isValidOrdering ( vector< int > &  ordering,
int  offset = 0 
)

Test and make sure that this is a valid ordering.

This routine will test for:

  • Duplicated vertices. If there is no duplicated vertex, this ordering is probably ok.
  • Invalid vertex #. The vertex # should be between 0 and ordering.size()

Definition at line 716 of file extra.cpp.

Referenced by ColPack::GraphOrdering::CheckVertexOrdering().

Here is the caller graph for this function:

string itoa ( int  i)

Definition at line 353 of file extra.cpp.

Referenced by buildDotWithColor(), buildDotWithoutColor(), and displayGraph().

Here is the caller graph for this function:

int MatrixMultiplication_SxV ( unsigned int **  uip3_SparsityPattern,
double **  dp3_Value,
int  rowCount,
int  columnCount,
double **  dp2_seed,
int  colorCount,
double ***  dp3_CompressedMatrix 
)

Multiply the seed matrix dp2_seed with the original sparse matrix (uip3_SparsityPattern,dp3_Value) (in compress sparse row format) and store the result in "dp3_CompressedMatrix".

(*dp3_CompressedMatrix) = dp2_seed * (*dp3_Value)

Definition at line 1284 of file extra.cpp.

Referenced by main().

Here is the caller graph for this function:

int MatrixMultiplication_VxS ( unsigned int **  uip3_SparsityPattern,
double **  dp3_Value,
int  rowCount,
int  columnCount,
double **  dp2_seed,
int  colorCount,
double ***  dp3_CompressedMatrix 
)

Multiply the original sparse matrix (uip3_SparsityPattern,dp3_Value) (in compress sparse row format) with the seed matrix dp2_seed and store the result in "dp3_CompressedMatrix".

(*dp3_CompressedMatrix) = (*dp3_Value) * dp2_seed

Definition at line 1246 of file extra.cpp.

References Pause().

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

int MatrixMultiplication_VxS__usingVertexPartialColors ( std::list< std::set< int > > &  lsi_SparsityPattern,
std::list< std::vector< double > > &  lvd_Value,
int  columnCount,
vector< int > &  vi_VertexPartialColors,
int  colorCount,
double ***  dp3_CompressedMatrix 
)

Definition at line 1218 of file extra.cpp.

Referenced by main().

Here is the caller graph for this function:

int ReadRowCompressedFormat ( string  s_InputFile,
unsigned int ***  uip3_SparsityPattern,
int &  rowCount,
int &  columnCount 
)

Read a Row Compressed Format file.

Read a Row Compressed Format file Line 1: <# of rows> <# of columns> <# of non-zeros> Line 2-(# of non-zeros + 1): <# of non-zeros in that row> <index of the 1st non-zero> <index of the 2nd non-zero> ... <index of the (# of non-zeros in that row)th non-zero>

Definition at line 740 of file extra.cpp.

int Times2 ( double **  dp2_Values,
int  i_RowCount,
int  i_ColumnCount 
)

just manipulate the value of dp2_Values a little bit. Each non-zero entry in the matrix * 2.

Definition at line 945 of file extra.cpp.

int Times2Plus1point5 ( double **  dp2_Values,
int  i_RowCount,
int  i_ColumnCount 
)

just manipulate the value of dp2_Values a little bit. Each non-zero entry in the matrix * 2 + 1.5.

Definition at line 936 of file extra.cpp.

string toUpper ( string  input)

Convert all the characters in input to upper case, ' ', '\ t', '\ n' will be converted to '_'.

Definition at line 920 of file extra.cpp.

Referenced by ColPack::BipartiteGraphBicoloringInterface::Bicoloring(), ColPack::BipartiteGraphOrdering::OrderVertices(), ColPack::BipartiteGraphPartialOrdering::OrderVertices(), ColPack::GraphOrdering::OrderVertices(), and ColPack::BipartiteGraphPartialColoringInterface::PartialDistanceTwoColoring().

Here is the caller graph for this function:

int WriteMatrixMarket_ADOLCInput ( string  s_postfix,
int  i_mode,
  ... 
)

Write out to the file ADOLC Input using Matrix Market format.

Input parameters:

  • string s_postfix: postfix of the output file name
  • int i_mode:
    • i_mode == 0: output the structure of the matrix only. The next 3 parameter(s) are: unsigned int ** uip2_SparsityPattern, int i_Matrix_Row, int i_Matrix_Col
    • i_mode == 1: output the structure of the matrix and values in the Compressed Matrix The next 6 parameter(s) are: unsigned int ** uip2_SparsityPattern, int i_Matrix_Row, int i_Matrix_Col, double** dp2_CompressedMatrix, int i_CompressedMatrix_Row, int i_CompressedMatrix_Col
    • i_mode == 2: output the structure and values of the matrix and values in the Compressed Matrix The next 7 parameter(s) are: unsigned int ** uip2_SparsityPattern, int i_Matrix_Row, int i_Matrix_Col, double** dp2_CompressedMatrix, int i_CompressedMatrix_Row, int i_CompressedMatrix_Col, double** dp2_Values

Definition at line 29 of file extra.cpp.

Referenced by ColPack::GraphColoringInterface::GraphColoringInterface(), and ColPack::HessianRecovery::IndirectRecover_CoordinateFormat_unmanaged().

Here is the caller graph for this function:

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines