Commit 8a3d0603 authored by incardon's avatar incardon

First commit OpenFPM_vcluster

parents
This diff is collapsed.
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_CANONICAL_SYSTEM
AC_CONFIG_SRCDIR([src/main.cpp])
AM_INIT_AUTOMAKE
AC_CONFIG_HEADER([src/config.h])
m4_ifdef([MYSQL_FOUND],,[m4_include([m4/ax_lib_mysql.m4])])
m4_ifdef([AX_CHECK_COMPILER_FLAGS],,[m4_include([m4/ax_check_compiler_flags.m4])])
m4_ifdef([ACX_PTHREAD],,[m4_include([m4/acx_pthread.m4])])
m4_ifdef([AX_CHECK_CL],,[m4_include([m4/ax_opencl.m4])])
m4_ifdef([AX_BOOST_BASE],,[m4_include([m4/ax_boost_base.m4])])
m4_ifdef([AX_BOOST_PROGRAM_OPTIONS],,[m4_include([m4/ax_boost_program_options.m4])])
m4_ifdef([AX_BOOST_THREAD],,[m4_include([m4/ax_boost_thread.m4])])
m4_ifdef([ACX_MPI],,[m4_include([m4/acx_mpi.m4])])
m4_ifdef([AX_OPENMP],,[m4_include([m4/ax_openmp.m4])])
m4_ifdef([AX_GCC_X86_CPUID],,[m4_include([m4/ax_gcc_x86_cpuid.m4])])
m4_ifdef([AX_GCC_ARCHFLAG],,[m4_include([m4/ax_gcc_archflag.m4])])
m4_ifdef([AX_CUDA],,[m4_include([m4/ax_cuda.m4])])
CXXFLAGS+=" --std=c++11 "
NVCCFLAGS=" "
# Checks for programs.
AC_PROG_CXX
# Checks g++ flags
AC_CANONICAL_HOST
# Check target architetture
AX_GCC_ARCHFLAG([], [CXXFLAGS="$CXXFLAGS $ax_cv_gcc_archflag"], [])
###### Check for debug compilation
AC_MSG_CHECKING(whether to build with debug information)
debuger=no
AC_ARG_ENABLE(debug,
AC_HELP_STRING(
[--enable-debug],
[enable debug data generation (def=no)]
),
debuger="$enableval"
)
AC_MSG_RESULT($debuger)
if test x"$debuger" = x"yes"; then
AC_DEFINE([DEBUG_MODE],[],[Debug])
AC_DEFINE([DEBUG],[],[Debug])
CXXFLAGS="$CXXFLAGS -g3 -Wall -O0 "
NVCCFLAGS+="$NVCCFLAGS -g -O0 "
else
CXXFLAGS="$CXXFLAGS -Wall -O3 -g3 "
NVCCFLAGS+="$NVCCFLAGS -O3 "
fi
####### Checking for GPU support
AX_CUDA
AC_MSG_CHECKING(whether to build with GPU support)
gpu_support=no
AC_ARG_ENABLE(gpu,
AC_HELP_STRING(
[--enable-gpu],
[enable gpu support]
),
gpu_support="$enableval"
)
AC_MSG_RESULT($gpu_support)
if test x"$gpu_support" = x"yes"; then
AC_DEFINE([GPU],[],[GPU support])
fi
# Set this conditional if cuda is wanted
AM_CONDITIONAL(BUILDCUDA, test ! x$NVCC = x"no")
###########################
no_avx=no
no_sse42=no
no_sse41=no
no_sse3=no
no_sse2=no
no_sse=no
no_mmx=no
AX_CHECK_COMPILER_FLAGS([-msse4.2],[CXXFLAGS="$CXXFLAGS -mavx"],[no_avx=yes])
AX_CHECK_COMPILER_FLAGS([-msse4.2],[CXXFLAGS="$CXXFLAGS -msse4.2"],[no_sse42=yes])
AX_CHECK_COMPILER_FLAGS([-msse4.1],[CXXFLAGS="$CXXFLAGS -msse4.1"],[no_sse41=yes])
AX_CHECK_COMPILER_FLAGS([-msse3],[CXXFLAGS="$CXXFLAGS -msse3"],[no_sse3=yes])
AX_CHECK_COMPILER_FLAGS([-msse2],[CXXFLAGS="$CXXFLAGS -msse2"],[no_sse2=yes])
AX_CHECK_COMPILER_FLAGS([-msse],[CXXFLAGS="$CXXFLAGS -msse"],[no_sse=yes])
AX_CHECK_COMPILER_FLAGS([-mmmx],[CXXFLAGS="$CXXFLAGS -mmmx"],[no_mmx=yes])
AX_CHECK_COMPILER_FLAGS([-Wno-unused-but-set-variable],[CXXFLAGS="$CXXFLAGS -Wno-unused-but-set-variable"],[])
AC_SUBST(NVCCFLAGS)
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_CONFIG_FILES([Makefile src/Makefile])
AC_OUTPUT
echo ""
echo "***********************************"
echo "* *"
arch_str="${ax_cv_gcc_archflag#-march=#-mtune=}"
arch_str="${arch_str#-mtune=}"
n_arch_str=${#arch_str}
for (( X=0; X<23-n_arch_str; X++ ))
do
arch_str="$arch_str "
done
echo "* arch: $arch_str*"
if [ test x"$no_sse42" = x"no" ]; then
echo "* sse4.2: yes *"
else
echo "* sse4.2: no *"
fi
if [ test x"$no_sse41" = x"no" ]; then
echo "* sse4.1: yes *"
else
echo "* sse4.1: no *"
fi
if [ test x"$no_sse3" = x"no" ]; then
echo "* sse3: yes *"
else
echo "* sse3: no *"
fi
if [ test x"$no_sse2" = x"no" ]; then
echo "* sse2: yes *"
else
echo "* sse2: no *"
fi
if [ test x"$no_sse" = x"no" ]; then
echo "* sse: yes *"
else
echo "* sse: no *"
fi
if [ test x"$no_mmx" = x"no" ]; then
echo "* mmx: yes *"
else
echo "* mmx: no *"
fi
if [ test x"$profiler" = x"yes" ]; then
echo "* profiler: yes *"
else
echo "* profiler: no *"
fi
if [ test x"$debuger" = x"yes" ]; then
echo "* debug: yes *"
else
echo "* debug: no *"
fi
if [ test x"$no_64" = x"no" ]; then
echo "* 64 bit: yes *"
else
echo "* 64 bit: no *"
fi
if [ test x"$gpu_support" = x"no" ]; then
echo "* gpu: no *"
else
echo "* gpu: yes *"
fi
echo "* *"
echo "***********************************"
#!/bin/bash
mkdir ${HOME}/MPI
wget http://www.open-mpi.de/software/ompi/v1.8/downloads/openmpi-1.8.1.tar.bz2
tar -xvf openmpi-1.8.1.tar.bz2
cd openmpi-1.8.1
sh ./configure --prefix=${HOME}/MPI --enable-opal-multi-threads --enable-mpi-f90
make
make install
This diff is collapsed.
LINKLIBS = $(PTHREAD_LIBS) $(OPT_LIBS) $(BOOST_LDFLAGS) $(BOOST_PROGRAM_OPTIONS_LIB) $(CUDA_LIBS) $(BOOST_THREAD_LIB)
bin_PROGRAMS = ppline
ppline_SOURCES = main.cpp
ppline_CXXFLAGS = $(CUDA_CFLAGS)
ppline_CFLAGS = $(CUDA_CFLAGS)
ppline_LDADD = $(LINKLIBS) -L/usr/lib64/nvidia-bumblebee/
.cu.o :
$(NVCC) $(NVCCFLAGS) -o $@ -c $<
//
// Project : ThreadPool
// File : TThread.cc
// Author : Ronald Kriemann
// Purpose : baseclass for a thread-able class
//
// arch-tag: aec71576-f8d5-4573-ad31-f3dbddc59934
//
#include <unistd.h>
#include <signal.h>
#include <time.h>
#include <sched.h>
#include <string.h>
#include <iostream>
#include <cmath>
#include "TThread.h"
//
// routine to call TThread::run() method
//
extern "C"
void *
_run_thread ( void *arg )
{
if (arg != NULL)
{
((TThread*) arg)->run();
((TThread*) arg)->reset_running();
}// if
return NULL;
}
////////////////////////////////////////////
//
// constructor and destructor
//
TThread::TThread ( const int thread_no )
: _running( false ), _thread_no(thread_no)
{
}
TThread::~TThread ()
{
// request cancellation of the thread if running
if ( _running )
cancel();
}
////////////////////////////////////////////
//
// access local data
//
void
TThread::set_thread_no ( const int n )
{
_thread_no = n;
}
////////////////////////////////////////////
//
// thread management
//
//
// create thread (actually start it)
//
void
TThread::create ( const bool detached, const bool sscope )
{
if ( ! _running )
{
int status;
if ((status = pthread_attr_init( & _thread_attr )) != 0)
{
std::cerr << "(TThread) create : pthread_attr_init ("
<< strerror( status ) << ")" << std::endl;
return;
}// if
if ( detached )
{
// detache created thread from calling thread
if ((status = pthread_attr_setdetachstate( & _thread_attr,
PTHREAD_CREATE_DETACHED )) != 0)
{
std::cerr << "(TThread) create : pthread_attr_setdetachstate ("
<< strerror( status ) << ")" << std::endl;
return;
}// if
}// if
if ( sscope )
{
// use system-wide scheduling for thread
if ((status = pthread_attr_setscope( & _thread_attr, PTHREAD_SCOPE_SYSTEM )) != 0 )
{
std::cerr << "(TThread) create : pthread_attr_setscope ("
<< strerror( status ) << ")" << std::endl;
return;
}// if
}// if
#if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) && defined(SUNOS)
//
// adjust thread-scheduling for Solaris
//
struct sched_param t_param;
t_param.sched_priority = sched_get_priority_min( SCHED_RR );
if ((status = pthread_attr_setschedpolicy( & _thread_attr, SCHED_RR )) != 0)
std::cerr << "(TThread) create : pthread_attr_setschedpolicy ("
<< strerror( status ) << ")" << std::endl;
if ((status = pthread_attr_setschedparam( & _thread_attr, & t_param )) != 0)
std::cerr << "(TThread) create : pthread_attr_setschedparam ("
<< strerror( status ) << ")" << std::endl;
if ((status = pthread_attr_setinheritsched( & _thread_attr, PTHREAD_EXPLICIT_SCHED )) != 0)
std::cerr << "(TThread) create : pthread_attr_setinheritsched ("
<< strerror( status ) << ")" << std::endl;
#endif
#ifdef HPUX
// on HP-UX we increase the stack-size for a stable behaviour
// (need much memory for this !!!)
pthread_attr_setstacksize( & _thread_attr, 32 * 1024 * 1024 );
#endif
if ((status = pthread_create( & _thread_id, & _thread_attr, _run_thread, this ) != 0))
std::cerr << "(TThread) create : pthread_create ("
<< strerror( status ) << ")" << std::endl;
else
_running = true;
}// if
else
std::cout << "(TThread) create : thread is already running" << std::endl;
}
//
// detach thread
//
void
TThread::detach ()
{
if ( _running )
{
int status;
// detach thread
if ((status = pthread_detach( _thread_id )) != 0)
std::cerr << "(TThread) detach : pthread_detach ("
<< strerror( status ) << ")" << std::endl;
}// if
}
//
// synchronise with thread (wait until finished)
//
void
TThread::join ()
{
if ( _running )
{
int status;
// wait for thread to finish
if ((status = pthread_join( _thread_id, NULL )) != 0)
std::cerr << "(TThread) join : pthread_join ("
<< strerror( status ) << ")" << std::endl;
_running = false;
}// if
}
//
// request cancellation of thread
//
void
TThread::cancel ()
{
if ( _running )
{
int status;
if ((status = pthread_cancel( _thread_id )) != 0)
std::cerr << "(TThread) cancel : pthread_cancel ("
<< strerror( status ) << ")" << std::endl;
}// if
}
////////////////////////////////////////////
//
// functions to be called by a thread itself
//
//
// terminate thread
//
void
TThread::exit ()
{
if ( _running && (pthread_self() == _thread_id))
{
void * ret_val = NULL;
pthread_exit( ret_val );
_running = false;
}// if
}
//
// put thread to sleep (milli + nano seconds)
//
void
TThread::sleep ( const double sec )
{
if ( _running )
{
struct timespec interval;
if ( sec <= 0.0 )
{
interval.tv_sec = 0;
interval.tv_nsec = 0;
}// if
else
{
interval.tv_sec = time_t( std::floor( sec ) );
interval.tv_nsec = long( (sec - interval.tv_sec) * 1e6 );
}// else
nanosleep( & interval, 0 );
}// if
}
#ifndef __TTHREAD_HH
#define __TTHREAD_HH
//
// Project : ThreadPool
// File : TThread.hh
// Author : Ronald Kriemann
// Purpose : baseclass for a thread-able class
//
// arch-tag: d09c570a-520a-48ce-b612-a813b50e87b4
//
#include <stdio.h>
#include <pthread.h>
#ifdef HAVE_CUDA
#include <cuda.h>
#endif
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
//
// baseclass for all threaded classes
// - defines basic interface
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
class TThread
{
protected:
// thread-specific things
pthread_t _thread_id;
pthread_attr_t _thread_attr;
// is the thread running or not
bool _running;
// no of thread
int _thread_no;
public:
////////////////////////////////////////////
//
// constructor and destructor
//
TThread ( const int thread_no = -1 );
virtual ~TThread ();
////////////////////////////////////////////
//
// access local data
//
int thread_no () const { return _thread_no; }
int proc_no () const { return _thread_no; }
void set_thread_no ( const int n );
// compare if given proc-no is local one
bool on_proc ( const int p ) const { return ((p == -1) || (_thread_no == -1) || (p == _thread_no)); }
// resets running-status (used in _run_proc, see TThread.cc)
void reset_running () { _running = false; }
////////////////////////////////////////////
//
// user-interface
//
// actually method the thread executes
virtual void run () = 0;
////////////////////////////////////////////
//
// thread management
//
// create thread (actually start it)
void create ( const bool detached = false, const bool sscope = false );
// detach thread
void detach ();
// synchronise with thread (wait until finished)
void join ();
// request cancellation of thread
void cancel ();
protected:
////////////////////////////////////////////
//
// functions to be called by a thread itself
//
// terminate thread
void exit ();
// put thread to sleep for <sec> seconds
void sleep ( const double sec );
};
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
//
// wrapper for pthread_mutex
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
class TMutex
{
protected:
// the mutex itself and the mutex-attr
pthread_mutex_t _mutex;
pthread_mutexattr_t _mutex_attr;
public:
/////////////////////////////////////////////////
//
// constructor and destructor
//
TMutex ()
{
pthread_mutexattr_init( & _mutex_attr );
pthread_mutex_init( & _mutex, & _mutex_attr );
}
~TMutex ()
{
pthread_mutex_destroy( & _mutex );
pthread_mutexattr_destroy( & _mutex_attr );
}
/////////////////////////////////////////////////
//
// usual behavior of a mutex
//
// lock and unlock mutex (return 0 on success)
int lock () { return pthread_mutex_lock( & _mutex ); }
int unlock () { return pthread_mutex_unlock( & _mutex ); }
// return true if mutex is locked, otherwise false
bool is_locked ()
{
if ( pthread_mutex_trylock( & _mutex ) != 0 )
return true;
else
{
unlock();
return false;
}// else
}
};
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
//
// class for a condition variable
// - derived from mutex to allow locking of condition
// to inspect or modify the predicate
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
class GPUWorker;
class TCondition : public TMutex
{
protected:
// our condition variable
pthread_cond_t _cond;
public:
/////////////////////////////////////////////////
//
// constructor and destructor
//
#ifdef HAVE_CUDA
friend class GPUWorker;
#endif
TCondition () { pthread_cond_init( & _cond, NULL ); }
~TCondition () { pthread_cond_destroy( & _cond ); }
/////////////////////////////////////////////////
//
// condition variable related methods
//
void wait () { pthread_cond_wait( & _cond, & _mutex ); }
void signal () { pthread_cond_signal( & _cond ); }
void broadcast () { pthread_cond_broadcast( & _cond ); }
};
#endif // __TTHREAD_HH
//
// Project : ThreadPool
// File : TThreadPool.cc
// Author : Ronald Kriemann
// Purpose : class for managing a pool of threads
//
// arch-tag: d4739323-4e22-42d9-9fcb-f98f5890d77b
//
#include <pthread.h>
#include "TThreadPool.h"
//
// set to one to enable sequential execution
//
#define THR_SEQUENTIAL 0
//
// global thread-pool
//
TThreadPool * thread_pool = NULL;
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//
// thread handled by threadpool
//
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//
// thread handled by threadpool
//
class TPoolThr : public TThread
{
protected:
// pool we are in
TThreadPool * _pool;
// job to run and data for it
TThreadPool::TJob * _job;
void * _data_ptr;
// should the job be deleted upon completion
bool _del_job;
// condition for job-waiting
TCondition _work_cond;
// indicates end-of-thread
bool _end;
// mutex for preventing premature deletion
TMutex _del_mutex;
public:
//
// constructor
//
TPoolThr ( const int n, TThreadPool * p )
: TThread(n), _pool(p), _job(NULL), _data_ptr(NULL), _del_job(false), _end(false)
{}
~TPoolThr () {}
//
// parallel running method
//
void run ()
{
_del_mutex.lock();
while ( ! _end )
{
//
// append thread to idle-list and wait for work
//
_pool->append_idle( this );
_work_cond.lock();
while (( _job == NULL ) && ! _end )
_work_cond.wait();
_work_cond.unlock();
//
// look if we really have a job to do
// and handle it
//
if ( _job != NULL )
{
// execute job
_job->run( _data_ptr );
_job->unlock();
if ( _del_job )
delete _job;
// reset data
_work_cond.lock();
_job = NULL;
_data_ptr = NULL;
_work_cond.unlock();
}// if
}// while
_del_mutex.