Commit 6c87951b authored by Kirill Terekhov's avatar Kirill Terekhov

add readmes and examples

parent 09c09f3b
......@@ -2,7 +2,6 @@ projects/
AsmJit/
compile32_vs2013/
compile64_vs2013/
examples/
examples/Data/
examples/Matrices/
examples/Grids/
......
ANI3D solvers
=======
This folder contains solvers from Ani3D package from:
http://sourceforge.net/projects/ani3d/
This folder stores some experimental code
add_subdirectory(DrawGrid)
add_subdirectory(OldDrawGrid)
add_subdirectory(DrawMatrix)
add_subdirectory(MatSolve)
add_subdirectory(OctreeCutcell)
add_subdirectory(Solver)
\ No newline at end of file
project(DrawGrid)
set(SOURCE main.cpp
rotate.cpp
rotate.h
my_glut.h)
find_package(OpenGL)
if (WIN32)
find_path(GLUT_INCLUDE_DIR GL/glut.h )
if (CYGWIN)
find_library(GLUT_glut_LIBRARY glut32 )
else ()
if(BORLAND)
set (GLUT_glut_LIBRARY import32 CACHE STRING "GLUT library for win32")
else()
set (GLUT_glut_LIBRARY opengl32 CACHE STRING "GLUT library for win32")
endif()
endif ()
if(NOT GLUT_glut_LIBRARY)
#-- use old way to find GLUT
find_path( GLUT_INCLUDE_DIR NAMES GL/glut.h
PATHS ${GLUT_ROOT_PATH}/include )
find_library( GLUT_glut_LIBRARY NAMES glut glut32 freeglut
PATHS
${OPENGL_LIBRARY_DIR}
${GLUT_ROOT_PATH}/Release
)
endif(NOT GLUT_glut_LIBRARY)
#include(FindPackageHandleStandardArgs.cmake)
#FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLUT REQUIRED_VARS GLUT_glut_LIBRARY GLUT_INCLUDE_DIR)
if (GLUT_glut_LIBRARY)
message("GLUT library found")
set( GLUT_LIBRARIES ${GLUT_glut_LIBRARY})
#The following deprecated settings are for backwards compatibility with CMake1.4
set (GLUT_LIBRARY ${GLUT_LIBRARIES})
if(NOT GLUT_INCLUDE_DIR)
message("GLUT include directory not found - trying to set OpenGL library")
message("OpenGL library is ${OPENGL_INCLUDE_DIR}")
set(GLUT_INCLUDE_DIR ${OPENGL_INCLUDE_DIR})
set(GLUT_INCLUDE_PATH ${GLUT_INCLUDE_DIR})
set(GLUT_FOUND 1)
else(NOT GLUT_INCLUDE_DIR)
set(GLUT_FOUND 1)
endif(NOT GLUT_INCLUDE_DIR)
endif(GLUT_glut_LIBRARY)
else(WIN32)
find_package(GLUT)
endif(WIN32)
if(OPENGL_FOUND)
include_directories(${OpenGL_INCLUDE_DIRS})
link_directories(${OpenGL_LIBRARY_DIRS})
add_definitions(${OpenGL_DEFINITIONS})
if(GLUT_FOUND)
include_directories(${GLUT_INCLUDE_DIRS})
link_directories(${GLUT_LIBRARY_DIRS})
add_definitions(${GLUT_DEFINITIONS})
add_executable(DrawGrid ${SOURCE})
target_link_libraries(DrawGrid ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} inmost)
if(USE_MPI)
target_link_libraries(DrawGrid ${MPI_LIBRARIES})
if(MPI_LINK_FLAGS)
set_target_properties(DrawGrid PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")
endif()
endif(USE_MPI)
else(GLUT_FOUND)
message("GLUT not found")
endif(GLUT_FOUND)
else(OPENGL_FOUND)
message("OpenGL not found")
endif(OPENGL_FOUND)
CXX=mpicxx
CC=mpicxx
#links for cluster
#PETSC_DIR=/data4t/terekhov/Packages/petsc-3.3-p3
#PETSC_ARCH=arch-linux2-c-opt
#INCPATH = -I${PETSC_DIR}/${PETSC_ARCH}/include -I${PETSC_DIR}/include
MSPPLIB = ../../mspp.a
#MSPPLIB = ../../msppd.a
#OPTFLAGS= -O0 -g -Wall -Wno-unused-function
OPTFLAGS= -Ofast -flto -fwhole-program -march=native -DNDEBUG -ftree-vectorize
OPENGL=-L/usr/X11R6/lib -lX11 -lXi -lXmu -lGL -lglut -lGLU
#OPENGL=-framework GLUT -framework OpenGL
#OPENGL=-lglut -lgl -lglu32 -lopengl32
#OPENGL=-L/lib -lglu32 -lopengl32
MYLIBS= $(OPENGL)
CXXFLAGS=$(OPTFLAGS) $(INCPATH)
LDFLAGS=$(OPTFLAGS)
LDLIBS=$(MYLIBS) $(PETSC)
targets=main
all: $(targets)
main: main.o rotate.o $(MSPPLIB)
clean:
rm -f $(targets) *.o
This diff is collapsed.
#if defined (__APPLE__) || defined(MAXOSX)
#include <GLUT/glut.h>
#endif
#if defined(_WIN32)
//#include <GL/glut.h>
// В windows следует скачать тот самый glut по ссылке
// http://www.opengl.org/resources/libraries/glut/
// и положить в папку с компилирующимся файлом
// так же следует установить пару библиотек
#define NOMINMAX
#include <windows.h>
#include <GL/glut.h>
//#include "glut.h"
#pragma comment(lib,"glut32.lib")
#endif
#if defined(__linux__)
#include <GL/glut.h>
#endif
/*********************************
Implementation of quaternion-based
object rotation
Functions
clickmotion - call when holded mouse moved
click - call when user clicks
motion - call when mouse just moves
quatinit - flush rotation value
rotate - multiply GL matrix
Dependency: rotate.h,
Standard: math.h
Specific: glut.h
**********************************/
#include "my_glut.h"
#include "rotate.h"
#include "math.h"
struct quaternion
{
double x,y,z,w;
};
struct vector
{
double x,y,z;
};
// Rotation
struct quaternion q;
struct vector drag, onclick;
double mx,my;
extern int width, height;
extern int interactive;
//
void clickmotion(int nmx, int nmy) // Mouse
{
struct vector n;
double norm,length,t;
mx = 2.*(nmx/(double)width - 0.5);
my = 2.*(0.5 - nmy/(double)height);
norm = mx*mx + my*my;
if( norm > 1.0 )
{
length = sqrt(norm);
drag.x = mx/length;
drag.y = my/length;
drag.z = 0.0;
}
else
{
drag.x = mx;
drag.y = my;
drag.z = sqrt(1.0-norm);
}
n.x = drag.y*onclick.z - drag.z*onclick.y;
n.y = drag.z*onclick.x - drag.x*onclick.z;
n.z = drag.x*onclick.y - drag.y*onclick.x;
if ( n.x*n.x + n.y*n.y + n.z*n.z > 10e-7 )
{
t = drag.x*onclick.x + drag.y*onclick.y + drag.z*onclick.z;
q.x = + q.x*t + q.y*n.z - q.z*n.y + q.w*n.x;
q.y = - q.x*n.z + q.y*t + q.z*n.x + q.w*n.y;
q.z = + q.x*n.y - q.y*n.x + q.z*t + q.w*n.z;
q.w = - q.x*n.x - q.y*n.y - q.z*n.z + q.w*t;
onclick.x = drag.x;
onclick.y = drag.y;
onclick.z = drag.z;
}
glutPostRedisplay();
}
void motion(int nmx, int nmy) // Mouse
{
mx = 2.*(nmx/(double)width - 0.5);
my = 2.*(0.5 - nmy/(double)height);
}
void click(int b, int s, int nmx, int nmy) // Mouse
{
double norm,length;
switch(b)
{
case GLUT_LEFT_BUTTON:
if( s == GLUT_DOWN ) interactive = 1;
else interactive = 0;
mx = 2.*(nmx/(double)width - 0.5);
my = 2.*(0.5 - nmy/(double)height);
norm = mx*mx + my*my;
if( norm > 1.0 )
{
length = sqrt(norm);
drag.x = mx/length;
drag.y = my/length;
drag.z = 0.0;
}
else
{
drag.x = mx;
drag.y = my;
drag.z = sqrt(1.0-norm);
}
onclick.x = drag.x;
onclick.y = drag.y;
onclick.z = drag.z;
break;
}
glutPostRedisplay();
}
void quatinit()
{
q.x = 0.0;
q.y = 0.0;
q.z = 0.0;
q.w = 1.0;
}
void rotatevector(double * vec)
{
int i;
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];
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);
glMultMatrixd(rot);
}
/*********************************
Implementation of quaternion-based
object rotation
Functions
clickmotion - call when holded mouse moved
click - call when user clicks
motion - call when mouse just moves
quatinit - flush rotation value
rotate - multiply GL matrix
Dependency: rotate.h,
Standard: math.h
Specific: glut.h
**********************************/
#ifndef _ROTATE_H
#define _ROTATE_H
void clickmotion(int nmx, int nmy);
void motion(int nmx, int nmy);
void click(int b, int s, int nmx, int nmy);
void quatinit();
void rotate();
void rotatevector(double * vec);
#endif
project(DrawMatrix)
set(SOURCE main.cpp my_glut.h)
find_package(OpenGL)
if (WIN32)
find_path(GLUT_INCLUDE_DIR GL/glut.h )
if (CYGWIN)
find_library(GLUT_glut_LIBRARY glut32 )
else ()
if(BORLAND)
set (GLUT_glut_LIBRARY import32 CACHE STRING "GLUT library for win32")
else()
set (GLUT_glut_LIBRARY opengl32 CACHE STRING "GLUT library for win32")
endif()
endif ()
if(NOT GLUT_glut_LIBRARY)
#-- use old way to find GLUT
find_path( GLUT_INCLUDE_DIR NAMES GL/glut.h
PATHS ${GLUT_ROOT_PATH}/include )
find_library( GLUT_glut_LIBRARY NAMES glut glut32 freeglut
PATHS
${OPENGL_LIBRARY_DIR}
${GLUT_ROOT_PATH}/Release
)
endif(NOT GLUT_glut_LIBRARY)
#include(FindPackageHandleStandardArgs.cmake)
#FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLUT REQUIRED_VARS GLUT_glut_LIBRARY GLUT_INCLUDE_DIR)
if (GLUT_glut_LIBRARY)
message("GLUT library found")
set( GLUT_LIBRARIES ${GLUT_glut_LIBRARY})
#The following deprecated settings are for backwards compatibility with CMake1.4
set (GLUT_LIBRARY ${GLUT_LIBRARIES})
if(NOT GLUT_INCLUDE_DIR)
message("GLUT include directory not found - trying to set OpenGL library")
message("OpenGL library is ${OPENGL_INCLUDE_DIR}")
set(GLUT_INCLUDE_DIR ${OPENGL_INCLUDE_DIR})
set(GLUT_INCLUDE_PATH ${GLUT_INCLUDE_DIR})
set(GLUT_FOUND 1)
else(NOT GLUT_INCLUDE_DIR)
set(GLUT_FOUND 1)
endif(NOT GLUT_INCLUDE_DIR)
endif(GLUT_glut_LIBRARY)
else(WIN32)
find_package(GLUT)
endif(WIN32)
if(OPENGL_FOUND)
include_directories(${OpenGL_INCLUDE_DIRS})
link_directories(${OpenGL_LIBRARY_DIRS})
add_definitions(${OpenGL_DEFINITIONS})
if(GLUT_FOUND)
include_directories(${GLUT_INCLUDE_DIRS})
link_directories(${GLUT_LIBRARY_DIRS})
add_definitions(${GLUT_DEFINITIONS})
add_executable(DrawMatrix ${SOURCE})
target_link_libraries(DrawMatrix ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} inmost)
if(USE_SOLVER_ANI3D)
target_link_libraries(DrawMatrix ani3d)
endif()
if(USE_SOLVER_PETSC)
link_directories(${PETSC_LIBRARY_DIRS})
add_definitions(${PETSC_DEFINITIONS})
target_link_libraries(DrawMatrix ${PETSC_LIBRARIES})
endif()
if(USE_MPI)
target_link_libraries(DrawMatrix ${MPI_LIBRARIES})
if(MPI_LINK_FLAGS)
set_target_properties(DrawMatrix PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")
endif()
endif(USE_MPI)
else(GLUT_FOUND)
message("GLUT not found")
endif(GLUT_FOUND)
else(OPENGL_FOUND)
message("OpenGL not found")
endif(OPENGL_FOUND)
CXX=mpicxx
CC=mpicxx
PETSC_DIR=#/data4t/terekhov/Packages/petsc-3.3-p3
PETSC_ARCH=#arch-linux2-c-opt
INCPATH = -I../../ -I${PETSC_DIR}/${PETSC_ARCH}/include -I${PETSC_DIR}/include
OPENGL = -L/usr/X11R6/lib -lX11 -lXi -lXmu -lGL -lglut -lGLU
#OPENGL = -framework GLUT -framework OpenGL
#OPENGL = -lglut -lgl -lglu32 -lopengl32
#OPENGL = -L/lib -lglu32 -lopengl32
PETSC = -L${PETSC_DIR}/${PETSC_ARCH}/lib/ -lpetsc -L/usr/X11R6/lib -lX11 -lparmetis -lmetis -lmpi_f77 -lflapack -lfblas -lgfortran
ILU2 = ../../ILU2/lib/libilu-2.3.a -lgfortran
#OPTFLAGS= -O0 -g -Wall
OPTFLAGS= -O3
MYLIBS=../../mspp.a
#MYLIBS= ../../msppd.a
CXXFLAGS=$(OPTFLAGS) $(INCPATH)
LDFLAGS=$(OPTFLAGS)
LDLIBS=$(MYLIBS) $(OPENGL) $(PETSC) $(ILU2)
targets=main
all: $(targets)
main: main.o
clean:
rm -f $(targets) *.o
This diff is collapsed.
#if defined (__APPLE__) || defined(MAXOSX)
#include <GLUT/glut.h>
#endif
#if defined(_WIN32)
//#include <GL/glut.h>
// В windows следует скачать тот самый glut по ссылке
// http://www.opengl.org/resources/libraries/glut/
// и положить в папку с компилирующимся файлом
// так же следует установить пару библиотек
#define NOMINMAX
#include <windows.h>
#include <GL/glut.h>
//#include "glut.h"
#pragma comment(lib,"glut32.lib")
#endif
#if defined(__linux__)
#include <GL/glut.h>
#endif
project(MatSolve)
set(SOURCE main.cpp)
add_executable(MatSolve ${SOURCE})
target_link_libraries(MatSolve inmost)
if(USE_MPI)
message("linking MatSolve with MPI")
target_link_libraries(MatSolve ${MPI_LIBRARIES})
if(MPI_LINK_FLAGS)
set_target_properties(MatSolve PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")
endif()
endif(USE_MPI)
if(USE_SOLVER_ANI)
message("linking MatSolve with ani3d")
target_link_libraries(MatSolve ani3d)
endif()
if(USE_SOLVER_PETSC)
message("linking MatSolve with PETSc")
link_directories(${PETSC_LIBRARY_DIRS})
target_link_libraries(MatSolve ${PETSC_LIBRARIES})
endif()
CXX=mpicxx
CC=mpicxx
#links for cluster
PETSC_DIR=/data4t/terekhov/Packages/petsc-3.3-p3
PETSC_ARCH=arch-linux2-c-opt
INCPATH = -I../../ #-I/data4t/terekhov/program/include -I${PETSC_DIR}/${PETSC_ARCH}/include -I${PETSC_DIR}/include
OPTFLAGS= -O0 -g -Wall
#OPTFLAGS= -O3
#MYLIBS=../../mspp.a
MYLIBS= ../../msppd.a
CXXFLAGS=$(OPTFLAGS) $(INCPATH)
LDFLAGS=$(OPTFLAGS)
PETSC = -L${PETSC_DIR}/${PETSC_ARCH}/lib/
#-lpetsc -L/usr/X11R6/lib -lX11 -ldmumps -lmumps_common -lmpi_f77 -lscalapack -lpord -lblacs -lparmetis -lmetis -lflapack -lfblas -lmpi -lHYPRE -lsuperlu_dist_2.4
#PETSC+=-lpetsc -L/usr/X11R6/lib64 -lX11 -lpthread -lmpigc4 -lstdc++ -ldmumps -lmumps_common -lscalapack -lpord -lblacs -lparmetis -lmetis -lmpi -lHYPRE -lflapack -lfblas -L/opt/intel/impi/3.2.2.006/lib64 -L/opt/intel/mpi-rt/3.2.2 -lmpigc4 -lmpigf -lmpi ../../ILU2/lib/libilu-2.3.a -lgfortran
PETSC =-lpetsc -L/usr/X11R6/lib -lX11 -lparmetis -lmetis -lmpi_f77 -lflapack -lfblas -lgfortran
ILU2 = ../../ILU2/lib/libilu-2.3.a -lgfortran
LDLIBS=$(MYLIBS) $(PETSC) $(ILU2)
targets=main
all: $(targets)
main: main.o
clean:
rm -f $(targets) *.o
r petsc_options.txt ~/Documents/MSPP_Solver/CK656.MTX
bt
#include "../../inmost.h"
#include <string>
#include <iostream>
using namespace INMOST;
#if defined(USE_MPI)
#define BARRIER MPI_Barrier(MPI_COMM_WORLD);
#else
#define BARRIER
#endif
int main(int argc, char ** argv)
{
/*
int i;
for (int j = 0; j < 10000; j++)
{
Solver::Matrix A;
double t = Timer();
for(int i = 0; i < 10000; i++)
A[i][i] = 0;
printf("%d %g\n",j,Timer()-t);
}
return 0;
*/
int rank,procs;
if( argc < 3 )
{
std::cout << "usage: " << argv[0] << " method_number<0:Inner,1:ANI3D,2:PETSc,3:Trilinos> matrix.mtx [right_hand_side.rhs] [petsc_options.txt]" << std::endl;
return -1;
}
Solver::Type type;
switch(atoi(argv[1]))
{
case 0: type = Solver::INNER_ILU2; break;
case 1: type = Solver::INNER_MLILUC; break;
case 2: type = Solver::ANI; break;
case 3: type = Solver::PETSC; break;
}
Solver::Initialize(&argc,&argv,argc > 4 ? argv[4] : NULL);
{
#if defined(USE_MPI)
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
MPI_Comm_size(MPI_COMM_WORLD,&procs);
#else
rank = 0;
procs = 1;
#endif
//std::cout << rank << "/" << procs << " " << argv[0] << std::endl;
Solver::Matrix mat("A");
Solver::Vector b("rhs");
Solver::Vector x("sol");
//std::cout << rank << " load matrix from " << std::string(argv[2]) << std::endl;
long double t = Timer(), tt = Timer();
mat.Load(std::string(argv[2])); //if interval parameters not set, matrix will be divided automatically
BARRIER
if( !rank ) std::cout << "load matrix: " << Timer() - t << std::endl;
//mat.Save("test.mtx");
t = Timer();
if( argc > 3 )
{
//std::cout << rank << " load vector from " << std::string(argv[3]) << std::endl;
b.Load(std::string(argv[3]));
}
else
{
INMOST_DATA_ENUM_TYPE mbeg,mend,k;
mat.GetInterval(mbeg,mend);
b.SetInterval(mbeg,mend);
for(k = mbeg; k < mend; k++) b[k] = 1.0;
}
BARRIER
if( !rank ) std::cout << "load vector: " << Timer() - t << std::endl;
bool success = false;
int iters;
double resid, realresid = 0;
{
Solver s(type);
t = Timer();
s.SetMatrix(mat);
BARRIER
if( !rank ) std::cout << "preconditioner: " << Timer() - t << std::endl;
t = Timer();
success = s.Solve(b,x);
BARRIER
if( !rank ) std::cout << "solver: " << Timer() - t << std::endl;
iters = s.Iterations();
resid = s.Residual();
//x.Save("output.rhs");
}
tt = Timer() - tt;
{
double aresid = 0, bresid = 0;
Solver::Vector test;
t = Timer();
Solver::OrderInfo info;
info.PrepareMatrix(mat,0);
info.PrepareVector(x);
info.Update(x);
mat.MatVec(1.0,x,0.0,test);
{
INMOST_DATA_ENUM_TYPE mbeg,mend,k;
info.GetLocalRegion(info.GetRank(),mbeg,mend);
for(k = mbeg; k < mend; k++)
{
aresid += (test[k]-b[k])*(test[k]-b[k]);
bresid += b[k]*b[k];
}
}
double temp[2] = {aresid,bresid}, recv[2] = {aresid,bresid};
#if defined(USE_MPI)
MPI_Reduce(temp,recv,2,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD);
if( info.GetRank() == 0 ) std::cout << "||Ax-b|| " << sqrt(recv[0]) << " ||b|| " << sqrt(recv[1]) << " ||Ax-b||/||b|| " << sqrt(recv[0]/recv[1]) << std::endl;
#endif
realresid = sqrt(recv[0]/recv[1]);
//realresid = sqrt(realresid);
info.RestoreVector(x);
if( !rank ) std::cout << "norms: " << Timer() - t << std::endl;
}
{
if( rank == 0 )
{