Commit a53c88e8 authored by Martin Perdacher's avatar Martin Perdacher

unif generator, cleanup

parent 13cbd564
......@@ -5,8 +5,6 @@ project(ego2)
# export CC=/opt/gcc6.1.0/usr/local/bin/gcc
# export CXX=/opt/gcc6.1.0/usr/local/bin/g++
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp hilbertjoin/egojoin.cpp util/arguments.cpp util/dataIo.cpp util/chrisutil.cpp hilbertjoin/hilloop.cpp measure/energy.cpp measure/timer.cpp util/allocation.cpp)
#####################
......@@ -14,17 +12,49 @@ set(SOURCE_FILES main.cpp hilbertjoin/egojoin.cpp util/arguments.cpp util/dataIo
#####################
# set(CMAKE_CXX_FLAGS "-std=c++11 -march=knl -mtune=knl -fpic -ffast-math -O3 -DNDDEBUG -fopenmp")
set(CMAKE_CXX_FLAGS "-std=c++11 -march=knl -mtune=knl -ffast-math -fassociative-math -O3 -DNDDEBUG -fopenmp -lmemkind")
# adding MKL include directory
include_directories($ENV{MKLROOT}/include)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -march=knl -mtune=knl -ffast-math -fassociative-math -O3 -fopenmp -lmkl_core -lmkl_intel_lp64 -lmkl_intel_thread -liomp5 -lboost_system")
# xeon-phi
link_directories($ENV{MKLROOT}/lib/intel64)
include_directories($ENV{BOOST_HOME}/include/boost)
link_directories($ENV{BOOST_HOME}/lib)
# mkl libraries
find_library ( mkl_lp64_LIB NAMES libmkl_intel_lp64.a
PATHS $ENV{MKLROOT} PATH_SUFFIXES lib)
find_library ( mkl_core_LIB NAMES libmkl_core.a
PATHS $ENV{MKLROOT} PATH_SUFFIXES lib)
find_library ( mkl_thread_LIB NAMES libmkl_intel_thread.a
PATHS $ENV{MKLROOT} PATH_SUFFIXES lib)
find_library ( mkl_omp_LIB NAMES libiomp5.a
PATHS $ENV{MKLROOT} PATH_SUFFIXES lib)
####################
# build type: Debug
####################
# cmake -DCMAKE_BUILD_TYPE=Debug ..
# and ignore the warning: "Manually-specified variables were not used by the project: CMAKE_BUID_TYPE"
set(CMAKE_CXX_FLAGS_DEBUG "-std=c++11 -march=knl -mtune=knl -fpic -ffast-math -O0 -DNDDEBUG -fopenmp")
set(CMAKE_CXX_FLAGS_DEBUG "-std=c++11 -march=knl -mtune=knl -fpic -ffast-math -O0 -DNDDEBUG -fopenmp -lboost_system -lmkl_core -lmkl_intel_lp64 -lmkl_intel_thread -liomp5")
# add_executable(egoHilb ${SOURCE_FILES})
add_executable(egoHilbCountOnly ${SOURCE_FILES})
target_compile_definitions(egoHilbCountOnly PRIVATE -DCOUNT_ONLY)
# target_compile_definitions(egoHilbCountOnly PRIVATE -DOUTPUT)
if ($ENV{KBLOCK})
target_compile_definitions(egoHilbCountOnly PRIVATE -DKBLOCK=$ENV{KBLOCK})
endif()
if ($ENV{OMP_NUM_THREADS})
target_compile_definitions(egoHilbCountOnly PRIVATE -DNUM_THREADS=$ENV{OMP_NUM_THREADS})
endif()
add_executable(egoHilb ${SOURCE_FILES})
# message("MKLROOT is $ENV{MKLROOT}")
# message("CMAKE_CXX_FLAGS is ${CMAKE_CXX_FLAGS}")
......
......@@ -29,87 +29,3 @@ void ddr_free(void *ptrs){
#endif
}
// quadrant mode, nested omp, ddr allocation
void ** ompx_ddr_calloc(size_t bytes){
int np = omp_get_max_threads(); // returns for nested 4,64 --> 4
void ** ptrs = (void**) _mm_malloc(np * sizeof(void*),ALIGNMENT);
// printf("omp_get_max_threads: %d\n", np);
if ( ptrs == NULL ){
fprintf(stderr, "Error in allocating ddr memory!\n");
exit(1);
}
#pragma omp parallel shared(ptrs)
{
int me = omp_get_thread_num();
ptrs[me] = _mm_malloc((bytes / np) + 1,ALIGNMENT);
memset(ptrs[me], 0, (bytes / np) + 1);
}
return ptrs;
}
// quadrant mode, nested omp, ddr free
void ompx_ddr_free(void ** ptrs){
int np = omp_get_max_threads();
printf("omp_get_max_threads: %d, \n", np);
#pragma omp parallel shared(ptrs)
{
int me = omp_get_thread_num();
_mm_free(ptrs[me]);
}
_mm_free(ptrs);
}
// quadrant mode, hbm allocation error handling
void ompx_hbm_errcode_check(int errcode){
if ( errcode != 0 ){
if ( errcode == EINVAL ){
fprintf(stderr, "Error in allocating hbm memory!\n Alginment parameter is not a multiple of 2.\n");
exit(1);
}
if ( errcode == ENOMEM ){
fprintf(stderr, "Error in allocating hbm memory!\n There is insufficient memory to satisfy the request.\n");
exit(1);
}
}
}
// quadrant mode, nested omp, hbm calloc
void ** ompx_hbm_calloc(size_t bytes){
int np = omp_get_max_threads(); // returns for nested 4,64 --> 4
void ** ptrs = NULL;
int errcode = hbw_posix_memalign((void**) &ptrs,ALIGNMENT,np * sizeof(void*));
ompx_hbm_errcode_check(errcode);
#pragma omp parallel shared(ptrs)
{
int me = omp_get_thread_num();
int all = omp_get_max_threads();
errcode = hbw_posix_memalign((void**) &ptrs[me],ALIGNMENT,(bytes/all) + 1);
ompx_hbm_errcode_check(errcode);
memset(ptrs[me], 0, (bytes/all) + 1);
}
return ptrs;
}
// nested omp, hbm free
void ompx_hbm_free(void ** ptrs){
int np = omp_get_max_threads();
// printf("omp_get_max_threads: %d, \n", np);
#pragma omp parallel shared(ptrs)
{
int me = omp_get_thread_num();
hbw_free(ptrs[me]);
}
hbw_free(ptrs);
}
......@@ -25,12 +25,4 @@
void * ddr_alloc(size_t bytes);
void ddr_free(void * ptrs);
void ** ompx_ddr_calloc(size_t bytes);
void ompx_ddr_free(void ** ptrs);
void ompx_hbm_errcode_check(int errcode);
void ** ompx_hbm_calloc(size_t bytes);
void ompx_hbm_free(void ** ptrs);
#endif
#include "dataIo.h"
void random_init_unif(double *array, const int N, const int D, const int INIT_SEED){
#pragma omp parallel
{
const int ME = omp_get_thread_num();
const int ALL_THREADS = omp_get_num_threads();
VSLStreamStatePtr stream;
const int SEED=(ME + 15) * INIT_SEED;
const double LOWER_BOUND=0.0;
const double UPPER_BOUND=1.0;
int errcode = vslNewStream( &stream, VSL_BRNG_MCG31, SEED);
if ( errcode != VSL_ERROR_OK && errcode != VSL_STATUS_OK ){
printf("vslNewStream error. dataIo.cpp line 9.\n");
exit(1);
}
const int imin = (N / ALL_THREADS) * ME;
const int imax = (ME == ALL_THREADS - 1 ) ? N : (N / ALL_THREADS) * (ME+1);
const int MY_N = imax - imin;
errcode = vdRngUniform(VSL_RNG_METHOD_UNIFORM_STD, stream, MY_N * D, &array[imin*D], LOWER_BOUND, UPPER_BOUND);
if ( errcode != VSL_ERROR_OK && errcode != VSL_STATUS_OK ){
printf("vslNewStream error. dataIo.cpp line 24.\n");
exit(1);
}
}
}
void random_init(double *array, const int N, const int D){
short unsigned seed[3];
int i;
......
......@@ -8,9 +8,12 @@
#include <omp.h>
#include "mkl_vsl.h"
#define MAX_LINE_LENGTH 2049
void random_init(double *array, const int N, const int D);
void random_init_unif(double *array, const int N, const int D, const int INIT_SEED);
void read_file(double *array, const int N, const int D, char filename[], const bool IS_BINARY);
void save_binary_file(double *array, const int N, const int D, char filename[]);
void save_text_file(double *array, const int N, const int D, char filename[]);
......
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