Commit 95a568f0 authored by Kirill Terekhov's avatar Kirill Terekhov

Updates and bugfixes

Added 2-clause bsd license for cmake files requested in cmake script for
petsc.
Introduced cmake option for Mondriaan matrix partitioning package for
solvers.
Changed reading of solver's parameters database to fix uninitialized
access reported by dr.memory.
Fixed bug in svdnxn with static std::vector allocation.
Added features to OldDrawGrid example.
Added solutions to problems described in issue #13.
parent 821a833b
......@@ -80,6 +80,7 @@ option(COMPILE_TESTS "Compile some tests" OFF)
option(USE_PARTITIONER_PARMETIS "Use ParMetis partitioner" OFF)
option(USE_PARTITIONER_ZOLTAN "Use Zoltan partitioner" OFF)
option(USE_SOLVER_METIS "Use METIS for matrix reordering" OFF)
option(USE_SOLVER_MONDRIAAN "Use Mondriaan for matrix reordering" OFF)
option(USE_SOLVER_PETSC "Use PETSc solvers" OFF)
option(USE_SOLVER_TRILINOS "Use Trilinos solvers" OFF)
#option(USE_AUTODIFF_OPENCL "Use OpenCL for automatic differentiation (under work)" OFF)
......@@ -153,6 +154,20 @@ if(USE_SOLVER_METIS)
endif()
endif()
if(USE_SOLVER_MONDRIAAN)
find_package(MONDRIAAN)
if(NOT MONDRIAAN_FOUND)
set(USE_SOLVER_MONDRIAAN OFF)
message("Mondriaan NOT FOUND")
else()
link_directories(${MONDRIAAN_LIBRARY_DIRS})
include_directories(${MONDRIAAN_INCLUDE_DIRS})
set(USE_SOLVER_MONDRIAAN ON)
message("Mondriaan FOUND")
endif()
endif()
if(USE_PARTITIONER_ZOLTAN)
find_package(ZOLTAN)
if(NOT ZOLTAN_FOUND)
......
......@@ -2,6 +2,6 @@ Copy and paste contents of autoexp.dat into
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Packages\Debugger\autoexp.dat
or the directry where Visual Studio was installed.
In future capabilities will grove.
In future capabilities will grow.
Tested with Visual studio 2010.
Copyright (c) 2014-2015
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This folder contains scripts for CMake that aid in compilation of the INMOST library with third party libraries.
The original files were obtained through internet from the following projects:
- PETSc
- MSTK
- FindOpenCL
And may appear in original or modified form.
\ No newline at end of file
......@@ -34,6 +34,10 @@ if(OPENGL_FOUND)
message("linking DrawMatrix with Metis")
target_link_libraries(DrawMatrix ${METIS_LIBRARIES})
endif()
if(USE_SOLVER_MONDRIAAN)
message("linking DrawMatrix with Mondriaan")
target_link_libraries(DrawMatrix ${MONDRIAAN_LIBRARIES})
endif()
endif()
......
......@@ -25,6 +25,10 @@ if(USE_SOLVER)
message("linking FVDiscr with Metis")
target_link_libraries(FVDiscr ${METIS_LIBRARIES})
endif()
if(USE_SOLVER_MONDRIAAN)
message("linking FVDiscr with Mondriaan")
target_link_libraries(FVDiscr ${MONDRIAAN_LIBRARIES})
endif()
endif()
......
......@@ -127,7 +127,7 @@ int main(int argc,char ** argv)
if( m->GetProcessorRank() == 0 ) std::cout << "Exchange ghost: " << Timer()-ttt << std::endl;
ttt = Timer();
Solver S(Solver::INNER_ILU2); // Specify the linear solver to ASM+ILU2+BiCGStab one
Solver S(Solver::INNER_ILU2); // Specify the linear solver to ASM+ILU2+BiCGStab one
Solver::Matrix A; // Declare the matrix of the linear system to be solved
Solver::Vector x,b; // Declare the solution and the right-hand side vectors
......@@ -242,6 +242,8 @@ int main(int argc,char ** argv)
ttt = Timer();
Tag error = m->CreateTag("error",DATA_REAL,CELL,NONE,1);
Storage::real err_C = 0.0, err_L2 = 0.0;
for( Mesh::iteratorCell cell = m->BeginCell(); cell != m->EndCell(); ++cell )
if( cell->GetStatus() != Element::Ghost )
......@@ -251,6 +253,7 @@ int main(int argc,char ** argv)
if (err > err_C)
err_C = err;
err_L2 += err * err * cell->Volume();
cell->Real(error) = err;
// x[cell->Integer(id)] = err;
}
err_C = m->AggregateMax(err_C); // Compute the maximal C norm for the error
......
......@@ -33,6 +33,10 @@ if(USE_SOLVER)
message("linking MatSolve with Metis")
target_link_libraries(MatSolve ${METIS_LIBRARIES})
endif()
if(USE_SOLVER_MONDRIAAN)
message("linking MatSolve with Mondriaan")
target_link_libraries(MatSolve ${MONDRIAAN_LIBRARIES})
endif()
endif()
......
This diff is collapsed.
......@@ -168,6 +168,46 @@ void rotatevector(double * vec)
vec[2] = ret[2]/ret[3];
}
void reverse_rotatevector(double * vec)
{
int i;
double rot[16];
double temp[4] = {vec[0],vec[1],vec[2],1.0};
double ret[4];
q.x = -q.x;
q.y = -q.y;
q.z = -q.z;
rot[ 0] = (q.w*q.w + q.x*q.x - q.y*q.y - q.z*q.z);
rot[ 1] = 2.*(q.x*q.y - q.w*q.z);
rot[ 2] = 2.*(q.x*q.z + q.w*q.y);
rot[ 3] = 0.0;
rot[ 4] = 2.*(q.x*q.y + q.w*q.z);
rot[ 5] = (q.w*q.w - q.x*q.x + q.y*q.y - q.z*q.z);
rot[ 6] = 2.*(q.y*q.z - q.w*q.x);
rot[ 7] = 0.0;
rot[ 8] = 2.*(q.x*q.z - q.w*q.y);
rot[ 9] = 2.*(q.y*q.z + q.w*q.x);
rot[10] = (q.w*q.w - q.x*q.x - q.y*q.y + q.z*q.z);
rot[11] = 0.0;
rot[12] = 0.0;
rot[13] = 0.0;
rot[14] = 0.0;
rot[15] = (q.w*q.w + q.x*q.x + q.y*q.y + q.z*q.z);
for(i=0; i < 4; i++)
{
ret[i] = temp[0] * rot[i*4];
ret[i] += temp[1] * rot[i*4+1];
ret[i] += temp[2] * rot[i*4+2];
ret[i] += temp[3] * rot[i*4+3];
}
vec[0] = ret[0]/ret[3];
vec[1] = ret[1]/ret[3];
vec[2] = ret[2]/ret[3];
q.x = -q.x;
q.y = -q.y;
q.z = -q.z;
}
void revrotatevector(double * vec)
{
int i;
......@@ -240,6 +280,51 @@ void rotatevector_from_stack(double * vec)
vec[2] = ret[2]/ret[3];
}
void quatget(double *vec)
{
vec[0] = q.x / q.w;
vec[1] = q.y / q.w;
vec[2] = q.z / q.w;
}
void reverse_rotatevector_from_stack(double * vec)
{
int i;
struct quaternion q = storage.back();
q.x = -q.x;
q.y = -q.y;
q.z = -q.z;
double rot[16];
double temp[4] = {vec[0],vec[1],vec[2],1.0};
double ret[4];
rot[ 0] = (q.w*q.w + q.x*q.x - q.y*q.y - q.z*q.z);
rot[ 1] = 2.*(q.x*q.y - q.w*q.z);
rot[ 2] = 2.*(q.x*q.z + q.w*q.y);
rot[ 3] = 0.0;
rot[ 4] = 2.*(q.x*q.y + q.w*q.z);
rot[ 5] = (q.w*q.w - q.x*q.x + q.y*q.y - q.z*q.z);
rot[ 6] = 2.*(q.y*q.z - q.w*q.x);
rot[ 7] = 0.0;
rot[ 8] = 2.*(q.x*q.z - q.w*q.y);
rot[ 9] = 2.*(q.y*q.z + q.w*q.x);
rot[10] = (q.w*q.w - q.x*q.x - q.y*q.y + q.z*q.z);
rot[11] = 0.0;
rot[12] = 0.0;
rot[13] = 0.0;
rot[14] = 0.0;
rot[15] = (q.w*q.w + q.x*q.x + q.y*q.y + q.z*q.z);
for(i=0; i < 4; i++)
{
ret[i] = temp[0] * rot[i*4];
ret[i] += temp[1] * rot[i*4+1];
ret[i] += temp[2] * rot[i*4+2];
ret[i] += temp[3] * rot[i*4+3];
}
vec[0] = ret[0]/ret[3];
vec[1] = ret[1]/ret[3];
vec[2] = ret[2]/ret[3];
}
void rotate()
{
double rot[16];
......
......@@ -20,13 +20,16 @@
void clickmotion(int nmx, int nmy);
void motion(int nmx, int nmy);
void click(int b, int s, int nmx, int nmy);
void quatget(double * vec);
void quatinit();
void quatpush();
void quatpop();
void rotate();
void rotate_from_stack();
void rotatevector(double * vec);
void reverse_rotatevector(double * vec);
void revrotatevector(double * vec);
void rotatevector_from_stack(double * vec);
void reverse_rotatevector_from_stack(double * vec);
#endif
......@@ -25,6 +25,10 @@ if(USE_SOLVER)
message("linking Solver with Metis")
target_link_libraries(Solver ${METIS_LIBRARIES})
endif()
if(USE_SOLVER_MONDRIAAN)
message("linking Solver with Mondriaan")
target_link_libraries(Solver ${MONDRIAAN_LIBRARIES})
endif()
endif(USE_SOLVER)
if(USE_PARTITIONER)
......
......@@ -529,6 +529,9 @@ namespace INMOST
void Mesh::GetGeometricData(HandleType e, GeometricData type, Storage::real * ret)
{
assert(e != InvalidHandle());
assert(ret != NULL);
assert(type == MEASURE || type == CENTROID || type == BARYCENTER || type == NORMAL);
ElementType etype = GetHandleElementType(e);
integer edim = Element::GetGeometricDimension(GetGeometricType(e));
integer mdim = GetDimensions();
......
......@@ -27,6 +27,8 @@ set(INMOST_LIBRARIES inmost)
set(USE_MPI @USE_MPI@)
set(USE_PARTITIONER_ZOLTAN @USE_PARTITIONER_ZOLTAN@)
set(USE_PARTITIONER_PARMETIS @USE_PARTITIONER_PARMETIS@)
set(USE_SOLVER_MONDRIAAN @USE_SOLVER_MONDRIAAN@)
set(USE_SOLVER_METIS @USE_SOLVER_METIS@)
set(USE_SOLVER_TRILINOS @USE_SOLVER_TRILINOS@)
set(USE_SOLVER_PETSC @USE_SOLVER_PETSC@)
......@@ -49,6 +51,16 @@ if( USE_PARTITIONER_PARMETIS )
list(APPEND INMOST_INCLUDE_DIRS "@METIS_INCLUDE_DIR@")
endif( USE_PARTITIONER_PARMETIS )
if( USE_SOLVER_MONDRIAAN )
list(APPEND INMOST_LIBRARIES "@MONDRIAAN_LIBRARIES@")
list(APPEND INMOST_INCLUDE_DIRS "@MONDRIAAN_INCLUDE_DIRS@")
list(APPEND INMOST_LIBRARY_DIRS "@MONDRIAAN_LIBRARY_DIRS@")
endif( USE_SOLVER_MONDRIAAN )
if( USE_SOLVER_METIS )
list(APPEND INMOST_LIBRARIES "@METIS_LIBRARIES@")
list(APPEND INMOST_INCLUDE_DIRS "@METIS_INCLUDE_DIR@")
endif( USE_SOLVER_METIS )
if( USE_SOLVER_TRILINOS )
list(APPEND INMOST_LIBRARIES "@Trilinos_LIBRARIES@")
......
......@@ -15,6 +15,7 @@
#cmakedefine USE_PARTITIONER_PARMETIS
#cmakedefine USE_SOLVER
#cmakedefine USE_SOLVER_MONDRIAAN
#cmakedefine USE_SOLVER_METIS
#cmakedefine USE_SOLVER_PETSC
#cmakedefine USE_SOLVER_TRILINOS
......
This diff is collapsed.
......@@ -346,9 +346,17 @@ namespace INMOST
{
queue.push_back(*it);
m->Integer(queue.back(),index) = visited++;
if( visited % chunk == 0 )
{
queue.clear();
break;
}
}
}
if( visited % chunk == 0 ) queue.clear();
//this may not fire properly
//if( visited % chunk == 0 ) queue.clear();
}
}
m->DeleteTag(order);
......
#define _CRT_SECURE_NO_WARNINGS
#include "inmost_solver.h"
#if defined(USE_SOLVER)
#include "solver_petsc.h"
......@@ -1329,33 +1330,40 @@ namespace INMOST
(void)argv;
if( database != NULL )
{
std::fstream file(database,std::ios::in);
char str[4096];
while( !file.eof() && file.getline(str,4096) )
{
int k = 0, l;
for(k = 0; k < (int)strlen(str); ++k)
{
if( str[k] == ':' ) break;
}
if( k == strlen(str) ) continue; //invalid line
for(l = 0; l < k; ++l) str[l] = tolower(str[l]);
l = k+1;
while(l < (int)strlen(str) && isspace(str[l]) ) ++l;
if( l == strlen(str) ) continue; //skip empty entry
if( !strncmp(str,"petsc",k) )
petsc_database_file = std::string(str+l);
else if( !strncmp(str,"trilinos_ifpack",k) )
trilinos_ifpack_database_file = std::string(str+l);
else if( !strncmp(str,"trilinos_aztec",k) )
trilinos_aztec_database_file = std::string(str+l);
else if( !strncmp(str,"trilinos_ml",k) )
trilinos_ml_database_file = std::string(str+l);
else if( !strncmp(str,"trilinos_belos",k) )
trilinos_belos_database_file = std::string(str+l);
else if( !strncmp(str,"ani",k) )
ani_database_file = std::string(str+l);
}
FILE * f = fopen(database,"r");
if( f )
{
//std::fstream file(database,std::ios::in);
char str[4096];
//while( !file.eof() && file.getline(str,4096) )
while( !feof(f) && fgets(str,4096,f) )
{
int k = 0, l;
for(k = 0; k < (int)strlen(str); ++k)
{
if( str[k] == ':' ) break;
}
if( k == strlen(str) ) continue; //invalid line
for(l = 0; l < k; ++l) str[l] = tolower(str[l]);
l = k+1;
while(l < (int)strlen(str) && isspace(str[l]) ) ++l;
if( l == strlen(str) ) continue; //skip empty entry
if( !strncmp(str,"petsc",k) )
petsc_database_file = std::string(str+l);
else if( !strncmp(str,"trilinos_ifpack",k) )
trilinos_ifpack_database_file = std::string(str+l);
else if( !strncmp(str,"trilinos_aztec",k) )
trilinos_aztec_database_file = std::string(str+l);
else if( !strncmp(str,"trilinos_ml",k) )
trilinos_ml_database_file = std::string(str+l);
else if( !strncmp(str,"trilinos_belos",k) )
trilinos_belos_database_file = std::string(str+l);
else if( !strncmp(str,"ani",k) )
ani_database_file = std::string(str+l);
}
//file.close();
fclose(f);
}
}
//std::cout << "PETSc \"" << petsc_database_file << "\"" << std::endl;
//std::cout << "Trilinos_Ifpack \"" << trilinos_ifpack_database_file << "\"" << std::endl;
......
......@@ -46,13 +46,15 @@ namespace INMOST
shell<INMOST_DATA_REAL_TYPE> u(pu,n*n);
shell<INMOST_DATA_REAL_TYPE> v(pv,n*n);
shell<INMOST_DATA_REAL_TYPE> w(pw,n);
std::copy(a.begin(),a.end(),u.begin());
//std::copy(a.begin(),a.end(),u.begin());
//memcpy(u,a,sizeof(INMOST_DATA_REAL_TYPE)*n*n);
int flag, i, its, j, jj, k, l, nm;
INMOST_DATA_REAL_TYPE c, f, h, s, x, y, z;
INMOST_DATA_REAL_TYPE anorm = 0.0, g = 0.0, scale = 0.0;
static std::vector<INMOST_DATA_REAL_TYPE> rv1(n);
dynarray<INMOST_DATA_REAL_TYPE,64> rv1;
rv1.resize(n);
// Householder reduction to bidiagonal form
for (i = 0; i < n*n; ++i) u[i] = a[i];
for (i = 0; i < n; i++)
{
// left-hand reduction
......@@ -624,13 +626,13 @@ namespace INMOST
}
#endif
INMOST_DATA_ENUM_TYPE i = 0;
bool halt = false;
if( last_resid < atol || last_resid < rtol*resid0 )
{
reason = "initial solution satisfy tolerances";
goto exit;
halt = true;
}
bool halt = false;
#if defined(USE_OMP)
#pragma omp parallel
#endif
......@@ -826,17 +828,24 @@ namespace INMOST
sigma[j-1] = sigma_sum;
}
#if defined(CONVEX_COMBINATION)
INMOST_DATA_REAL_TYPE lagrangian = 0.0;
for(INMOST_DATA_ENUM_TYPE j = 0; j < l; j++) lagrangian += tau[j+size*j];
sigma[l] = lagrangian;
tau[(l+1)*(l+1)-1] = 0.0;
for(INMOST_DATA_ENUM_TYPE j = 0; j < l; j++)
#if defined(USE_OMP)
#pragma omp single
#endif
{
tau[l + j*(l+1)] = -lagrangian;
tau[l*(l+1)+j] = lagrangian;
INMOST_DATA_REAL_TYPE lagrangian = 0.0;
for(INMOST_DATA_ENUM_TYPE j = 0; j < l; j++) lagrangian += tau[j+size*j];
sigma[l] = lagrangian;
tau[(l+1)*(l+1)-1] = 0.0;
for(INMOST_DATA_ENUM_TYPE j = 0; j < l; j++)
{
tau[l + j*(l+1)] = -lagrangian;
tau[l*(l+1)+j] = lagrangian;
}
}
#endif
info->Integrate(tau,size*size+size); //sigma is updated with tau
info->Integrate(tau,(l+2)*(l+1)); //sigma is updated with tau
//info->Integrate(tau,size*size);
//info->Integrate(sigma,size);
#if defined(USE_OMP)
#pragma omp single
......@@ -1136,7 +1145,6 @@ namespace INMOST
i++;
}
}
exit:
if (prec != NULL)
{
prec->Solve(SOL, r_tilde); //undo right preconditioner
......@@ -1277,6 +1285,10 @@ exit:
if (prec != NULL)prec->ReplaceRHS(RHS);
info->GetLocalRegion(info->GetRank(),vlocbeg,vlocend);
info->GetVectorRegion(vbeg,vend);
ivbeg = vbeg;
ivend = vend;
ivlocbeg = vlocbeg;
ivlocend = vlocend;
std::copy(RHS.Begin(),RHS.End(),r.Begin());
{
Alink->MatVec(-1,SOL,1,r); //global multiplication, r probably needs an update
......@@ -1296,10 +1308,6 @@ exit:
}
last_resid = resid = resid0 = sqrt(resid);
last_it = 0;
ivbeg = vbeg;
ivend = vend;
ivlocbeg = vlocbeg;
ivlocend = vlocend;
#if defined(REPORT_RESIDUAL)
if( info->GetRank() == 0 )
{
......
......@@ -32,6 +32,10 @@ if(USE_SOLVER_METIS)
message("linking solver_test000 with Metis")
target_link_libraries(solver_test000 ${METIS_LIBRARIES})
endif()
if(USE_SOLVER_MONDRIAAN)
message("linking solver_test000 with Mondriaan")
target_link_libraries(solver_test000 ${MONDRIAAN_LIBRARIES})
endif()
add_test(NAME solver_test000_serial_inner_ilu2 COMMAND $<TARGET_FILE:solver_test000> 0 0)
......
......@@ -30,6 +30,10 @@ if(USE_SOLVER_METIS)
message("linking solver_test001 with Metis")
target_link_libraries(solver_test001 ${METIS_LIBRARIES})
endif()
if(USE_SOLVER_MONDRIAAN)
message("linking solver_test001 with Mondriaan")
target_link_libraries(solver_test001 ${MONDRIAAN_LIBRARIES})
endif()
set(TOKAMAK_TESTS utm300
......
......@@ -33,6 +33,10 @@ if(USE_SOLVER)
message("linking solver_test002 with Metis")
target_link_libraries(solver_test002 ${METIS_LIBRARIES})
endif()
if(USE_SOLVER_MONDRIAAN)
message("linking solver_test002 with Mondriaan")
target_link_libraries(solver_test002 ${MONDRIAAN_LIBRARIES})
endif()
endif()
add_test(NAME solver_test002_serial_inner_ilu2 COMMAND $<TARGET_FILE:solver_test002> 0 20)
......
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