Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#[[Copyright (c) 2018 Hippolyte Barraud, Tsinghua University

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.]]

cmake_minimum_required(VERSION 3.9)
project(GridGraph)

#GLOBALS
set(CMAKE_CXX_STANDARD 14)
set(OPTS -march=native -Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-variable -O3)
file(GLOB CORE_HEADERS "core/*.hpp")
find_package(Threads REQUIRED)

#OUTPUT DIR
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

option(BUILD_EXAMPLES "build examples" ON)

add_subdirectory(tools)

if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
add_definitions(-DLINUX)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_definitions(-DDARWIN)
endif ()

if (BUILD_EXAMPLES)
add_subdirectory(examples)
endif ()
Empty file removed bin/.gitkeep
Empty file.
Binary file added bin/preprocess
Binary file not shown.
9 changes: 5 additions & 4 deletions core/atomic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ Copyright (c) 2014-2015 Xiaowei Zhu, Tsinghua University
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <atomic>

template <class ET>
inline bool cas(ET *ptr, ET oldv, ET newv) {
if (sizeof(ET) == 8) {
return __sync_bool_compare_and_swap((long*)ptr, *((long*)&oldv), *((long*)&newv));
} else if (sizeof(ET) == 4) {
return __sync_bool_compare_and_swap((int*)ptr, *((int*)&oldv), *((int*)&newv));
if (sizeof(ET) == sizeof(uint64_t)) {
return __sync_bool_compare_and_swap((uint64_t*)ptr, (uint64_t)oldv, (uint64_t)newv);
} else if (sizeof(ET) == sizeof(uint32_t)) {
return __sync_bool_compare_and_swap((uint32_t*)ptr, (uint32_t)oldv, (uint32_t)newv);
} else {
assert(false);
}
Expand Down
22 changes: 17 additions & 5 deletions core/bigvector.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright (c) 2014-2015 Xiaowei Zhu, Tsinghua University
Copyright (c) 2018 Hippolyte Barraud, Tsinghua University

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -17,17 +18,28 @@ Copyright (c) 2014-2015 Xiaowei Zhu, Tsinghua University
#ifndef BIGVECTOR_H
#define BIGVECTOR_H

#include <assert.h>
#include <cassert>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#ifdef USE_OPENMP
#include <omp.h>
#endif

#include <thread>
#include <string>

#include "core/filesystem.hpp"
#include "core/partition.hpp"

void *memalign(size_t alignment, size_t size) {
void *ret;
if (posix_memalign(&ret, alignment, size) != 0) {
ret = nullptr;
};
return ret;
}

template <typename T>
class BigVector {
std::string path;
Expand Down Expand Up @@ -68,7 +80,7 @@ class BigVector {
FILE * fout = fopen(path.c_str(), "wb");
fclose(fout);
}
if (file_size(path) != sizeof(T) * length) {
if (static_cast<unsigned>(file_size(path)) != sizeof(T) * length) {
long file_length = sizeof(T) * length;
assert(truncate(path.c_str(), file_length)!=-1);
int fout = open(path.c_str(), O_WRONLY);
Expand All @@ -85,13 +97,13 @@ class BigVector {
}
close(fout);
}
fd = open(path.c_str(), O_RDWR | O_DIRECT);
fd = open(path.c_str(), O_RDWR | O_SYNC);
assert(fd!=-1);
open_mmap();
}
void open_mmap() {
int ret = posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
assert(ret==0);
//int ret = posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL); //This is mostly useless on modern system
//assert(ret==0);
data = (T *)mmap(NULL, sizeof(T) * length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
assert(data!=MAP_FAILED);
is_open = true;
Expand Down
6 changes: 4 additions & 2 deletions core/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ inline void create_directory(std::string path) {
// TODO: only on unix-like systems
inline void remove_directory(std::string path) {
char command[1024];
int dumpVar;
sprintf(command, "rm -rf %s", path.c_str());
system(command);
dumpVar = system(command);
if(dumpVar == -500) return;
}

#endif
#endif
27 changes: 16 additions & 11 deletions core/graph.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright (c) 2014-2015 Xiaowei Zhu, Tsinghua University
Copyright (c) 2018 Hippolyte Barraud, Tsinghua University

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -17,16 +18,18 @@ Copyright (c) 2014-2015 Xiaowei Zhu, Tsinghua University
#ifndef GRAPH_H
#define GRAPH_H

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unistd.h>
#include <malloc.h>
#ifdef USE_OPENMP
#include <omp.h>
#include <string.h>
#endif
#include <cstring>

#include <thread>
#include <vector>
#include <functional>

#include "core/constants.hpp"
#include "core/type.hpp"
Expand Down Expand Up @@ -90,10 +93,11 @@ class Graph {
}

void init(std::string path) {
int c;
this->path = path;

FILE * fin_meta = fopen((path+"/meta").c_str(), "r");
fscanf(fin_meta, "%d %d %ld %d", &edge_type, &vertices, &edges, &partitions);
c = fscanf(fin_meta, "%d %d %ld %d", &edge_type, &vertices, &edges, &partitions);
fclose(fin_meta);

if (edge_type==0) {
Expand Down Expand Up @@ -129,14 +133,15 @@ class Graph {
column_offset = new long [partitions*partitions+1];
int fin_column_offset = open((path+"/column_offset").c_str(), O_RDONLY);
bytes = read(fin_column_offset, column_offset, sizeof(long)*(partitions*partitions+1));
assert(bytes==sizeof(long)*(partitions*partitions+1));
assert(bytes==static_cast<unsigned>(sizeof(long)*(partitions*partitions+1)));
close(fin_column_offset);

row_offset = new long [partitions*partitions+1];
int fin_row_offset = open((path+"/row_offset").c_str(), O_RDONLY);
bytes = read(fin_row_offset, row_offset, sizeof(long)*(partitions*partitions+1));
assert(bytes==sizeof(long)*(partitions*partitions+1));
assert(bytes==static_cast<unsigned>(sizeof(long)*(partitions*partitions+1)));
close(fin_row_offset);
if(c==-500) return;
}

Bitmap * alloc_bitmap() {
Expand Down Expand Up @@ -283,7 +288,7 @@ class Graph {
}
int read_mode;
if (memory_bytes < total_bytes) {
read_mode = O_RDONLY | O_DIRECT;
read_mode = O_RDONLY | O_SYNC;
// printf("use direct I/O\n");
} else {
read_mode = O_RDONLY;
Expand Down Expand Up @@ -321,7 +326,7 @@ class Graph {
}, ti);
}
fin = open((path+"/row").c_str(), read_mode);
posix_fadvise(fin, 0, 0, POSIX_FADV_SEQUENTIAL);
//posix_fadvise(fin, 0, 0, POSIX_FADV_SEQUENTIAL); //This is mostly useless on modern system
for (int i=0;i<partitions;i++) {
if (!should_access_shard[i]) continue;
for (int j=0;j<partitions;j++) {
Expand Down Expand Up @@ -350,7 +355,7 @@ class Graph {
break;
case 1: // target oriented update
fin = open((path+"/column").c_str(), read_mode);
posix_fadvise(fin, 0, 0, POSIX_FADV_SEQUENTIAL);
//posix_fadvise(fin, 0, 0, POSIX_FADV_SEQUENTIAL); //This is mostly useless on modern system

for (int cur_partition=0;cur_partition<partitions;cur_partition+=partition_batch) {
VertexId begin_vid, end_vid;
Expand Down
39 changes: 39 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#[[Copyright (c) 2018 Hippolyte Barraud, Tsinghua University

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.]]

file(GLOB EXAMPLES_SRC "*.cpp")

find_package(OpenMP)

if (OpenMP_CXX_FOUND)
add_definitions(-DUSE_OPENMP)
else()
message(FATAL_ERROR "OpenMP could not be found. Aborting")
endif ()

foreach(EXAMPLE_SRC ${EXAMPLES_SRC})
get_filename_component(TRAGET_NAME ${EXAMPLE_SRC} NAME_WE)
message(STATUS "Configuring ${TRAGET_NAME}")

add_executable(${TRAGET_NAME} ${EXAMPLE_SRC} ${CORE_HEADERS})
target_compile_options(${TRAGET_NAME} PUBLIC ${OPTS})
target_include_directories(${TRAGET_NAME} PUBLIC ..)

if (${OpenMP_CXX_FOUND})
target_link_libraries(${TRAGET_NAME} PUBLIC Threads::Threads OpenMP::OpenMP_CXX )
else()
target_link_libraries(${TRAGET_NAME} PUBLIC Threads::Threads)
endif ()

endforeach(EXAMPLE_SRC)
18 changes: 18 additions & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#[[Copyright (c) 2018 Hippolyte Barraud, Tsinghua University

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.]]

add_executable(preprocess preprocess.cpp ${CORE_HEADERS})
target_compile_options(preprocess PUBLIC ${OPTS})
target_include_directories(preprocess PUBLIC ..)
target_link_libraries(preprocess PUBLIC Threads::Threads)
Loading