Skip to content
This repository was archived by the owner on May 11, 2024. It is now read-only.
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
32 changes: 19 additions & 13 deletions .build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,29 @@ VERSION="1.10.8"
DIRECTORY="asio-$VERSION"

if [ ! -f /usr/local/lib/libprotobuf.so ]; then
./.protobuf_dl.sh
echo "Downloading and installing protobuf and protoc (silent)..."
./.protobuf_dl.sh 1>/dev/null 2>&1
echo "Finished setting up protobuf with code $?"
fi

# this should be false on users, but true on travis
if [ ! -f protobuf_files/MIST.pb.h ]; then
echo "MIST.pb files not found. Generating from protoc..."
protoc -I=protobuf_files/ --cpp_out=protobuf_files/ protobuf_files/MIST.proto
echo "protoc exited with code: $?"
fi

if [ ! -d "$DIRECTORY" ]; then
wget "http://learn612.000webhostapp.com/asio-1.10.8.tar.gz"
tar -xvf "asio-1.10.8.tar.gz"
tar -xf "asio-1.10.8.tar.gz"
fi

anum="$#"

if [ "$anum" -gt 0 ]; then
printf "\nBuilding with $1\n"
build="g++ $1 -std=c++1y -Iasio-1.10.8/include/ -Iinclude/ -Iprotobuf_files/ -lpthread -lprotobuf -c -o a.o"
eval $build
else
printf "\nBuilding...\n"
g++ -std=c++1y -Iasio-1.10.8/include/ -Iinclude/ -Iprotobuf_files -c -lpthread src/MIST.cpp -lprotobuf -o a.o
fi
mkdir .build/
cd .build/
export cpp_vers=11
cmake ..
make

printf "Exited with code $?\n"
exitval=$?
printf "Exited with code $exitval\n"
exit $exitval
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ a

#boost
boost_1_62_0/*

#build system
.build/
Empty file modified .protobuf_dl.sh
100644 → 100755
Empty file.
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@ complier: g++
sudo: required
before-install:
- chmod +x .build.sh
- chmod +x .protobuf_dl.sh
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.9
- g++-5
- gcc-5
- libboost-dev
- libboost-system-dev
- git
- autoconf
- automake
- libtool
- curl
- cmake
- make
- unzip
install:
- CC=gcc-4.9 CXX=g++-4.9
script: ./.build.sh
- CC=gcc-5 CXX=g++-5
script: travis_wait 30 ./.build.sh

#what?
27 changes: 27 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
cmake_minimum_required (VERSION 2.8)

project(Mist-Computing-Library CXX)
set(CMAKE_CXX_STANDARD $ENV{cpp_vers})
set(CMAKE_CXX_STANDARD_REQUIRED on)

include_directories(${CMAKE_SOURCE_DIR}/protobuf_files/)
include_directories(${CMAKE_SOURCE_DIR}/protobuf/src/)
include_directories(${CMAKE_SOURCE_DIR}/asio-1.10.8/include/)
include_directories(${CMAKE_SOURCE_DIR}/include/)

IF(UNIX)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y")
ENDIF(UNIX)

add_definitions(-DASIO_STANDALONE)

file(GLOB_RECURSE Mist_Files ${CMAKE_SOURCE_DIR}/include/*.hpp)

add_library(MistComputingLibrary SHARED ${Mist_files} src/MIST.cpp)
add_library(MistComputingLibraryStatic STATIC ${Mist_files} src/MIST.cpp)

set_target_properties(MistComputingLibrary PROPERTIES OUTPUT_NAME Mist)
set_target_properties(MistComputingLibraryStatic PROPERTIES OUTPUT_NAME MistStatic)

set_target_properties(MistComputingLibrary PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(MistComputingLibraryStatic PROPERTIES LINKER_LANGUAGE CXX)
13 changes: 13 additions & 0 deletions include/LibMIST.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "Machine.hpp"
#include "MIST_Global.hpp"
#include "MIST_Internal.hpp"
#include "MIST.hpp"
#include "Scheduler.hpp"
#include "Task.hpp"
#include "networking/ReceiveData.hpp"
#include "networking/SendData.hpp"
#include "shared_variable/SharedBool.hpp"
#include "shared_variable/SharedDouble.hpp"
#include "shared_variable/SharedInt.hpp"
#include "shared_variable/SharedVariable.hpp"
#include "shared_variable/SharedVariableBase.hpp"
99 changes: 42 additions & 57 deletions include/MIST.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,78 +9,63 @@
#include <vector>
#include <memory>
#include <asio.hpp>
#include <Machine.hpp>

namespace MIST {
class MIST {
private:

struct computerHardware
{
unsigned long allowedThreads;
unsigned long long allowedMemory;
bool enableHT;
};

struct MISTHost
{
std::string name;
bool isLocal; //is it this computer?
std::string address; //what address is it? "local" for if it's local
computerHardware computer; //What hardware does it have?
};

computerHardware thisComputer; //this computer
MISTHost local; //this computer

std::vector<MISTHost> Hosts;
Machine* local;
std::shared_ptr<Scheduler> scheduler;
bool is_master;
std::vector<Machine> machines;
bool is_master; //unimplemented for now
public:
MIST(bool is_master, Machine local) {
scheduler = std::make_shared<Scheduler>();
machines.push_back(local);
this->is_master = is_master;
this->local = &local;
}

/*void send(auto message) {
//send message using ASIO
}*/
~MIST() {
scheduler.reset();
machines.empty();
delete local;
}

public:
MIST(bool is_master) {
MIST(bool is_master, std::vector<Machine> machines, int local_index = 0) {
scheduler = std::make_shared<Scheduler>();
this->machines = machines;
this->is_master = is_master;
local = &this->machines[local_index];
}

~MIST() = default;
//LOCAL INITIALIZATION
void add_machine(Machine machine) {
this->machines.push_back(machine);
}

void InitComputer(unsigned long threads = 1, unsigned long long memory = 2048, std::string name = "Unnamed, Unloved Computer", std::string address = "0.0.0.0", bool enableHT = false) {
local.isLocal = true;
local.address = "local";
local.computer.allowedMemory = memory;
local.computer.allowedThreads = threads;
local.name = name;
local.computer.enableHT = enableHT;
}
void setThreads(unsigned long threads) {
local.computer.allowedThreads = threads;
}
void setMemory(unsigned long long memory) {
local.computer.allowedMemory = memory;
}
void enableHT(bool enableHT) {
local.computer.enableHT = enableHT;
}
void setName(std::string computerName) {
local.name = computerName;
}
void setAddress(std::string address) {
local.address = address;
}
void remove_machine(std::string name) {
std::vector<Machine> v;
for(auto m : this->machines) {
if(!(m.name == name)) {
v.push_back(m);
}
}

//NETWORK INITIALIZATION
void inviteMachine(std::string IP) { //invites machine to network (changed from addMachine to signify that only master machine can do this)
//Perhaps accomplish this by creating an invite task in MIST.hpp that sends information back to this machine?
machines = v;
}

/* void sendTask(std::shared_ptr<Task<auto>> task) {
send(task.getID());
}*/
Machine* get_local() { return local; }

void add_task(std::string id, MIST_taskfunc fn) {
scheduler->update_task_vector(id, fn);
}

void send_task(std::string serialized_task, std::string machine_name, short int port = 8008) {
for(auto machine : machines) {
if(machine.name == machine_name) {
scheduler->send_task(serialized_task, machine, port);
}
}
}
};
}
2 changes: 1 addition & 1 deletion include/MIST_Internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <iostream>
#include <thread>
#include <functional>
#include "asio.hpp"
#include <asio.hpp>

typedef void (*MIST_taskfunc)(void);

Expand Down
21 changes: 21 additions & 0 deletions include/Machine.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include <string>

namespace MIST {
struct Machine {
std::string name;
std::string address;
bool isLocal; //is it this computer?
bool HT; //unimplemented feature for now
int memory; //approximate memory in gb, unimplemented feature

Machine(std::string name, std::string address = "localhost", bool isLocal = true, bool HT = false, int memory = 4) {
this->name = name;
this->address = address;
this->isLocal = isLocal;
this->HT = HT;
this->memory = memory;
}
};
}
50 changes: 42 additions & 8 deletions include/Scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,37 @@

#include <MIST_Internal.hpp>
#include <networking/ReceiveData.hpp>
#include <networking/SendData.hpp>
#include <MIST.pb.h>
#include <Task.hpp>
#include <vector>
#include <memory>
#include <thread>
#include <Machine.hpp>

class Scheduler {
private:
std::vector<MIST::Task*> task_queue;
bool running = false;
std::thread* checker;

public:
Scheduler(std::vector<MIST::Task*> task_queue = {}) {
this->task_queue = task_queue;
Start();
start();
}

~Scheduler() {
//Make sure threads are close
Stop();
stop();
//empty task_queue to prevent evil raw pointers from ruining program
task_queue.empty();
}

void updateTaskVector(std::string id, MIST_taskfunc fn) {
inline void update_task_vector(std::string id, MIST_taskfunc fn) {
task_queue.push_back(new MIST::Task(id, fn));
}

void removeTask(std::string id) {
inline void remove_task(std::string id) {
std::vector<MIST::Task*> copy = {};
for(auto t : task_queue) {
if(t->getID() != id) {
Expand All @@ -41,7 +42,7 @@ class Scheduler {
task_queue = copy;
}

void check_for_tasks() {
inline void check_for_tasks() {
while(this->running) {
auto rdo = std::make_shared<ReceiveData>();
bool end = false;
Expand Down Expand Up @@ -74,12 +75,45 @@ class Scheduler {
}
}

void Start() {
inline void start() {
this->running = true;
this->checker = new std::thread(&Scheduler::check_for_tasks, this);
}

void Stop() {
//run in new thread
inline void run_task(std::string id) {
for(auto task : this->task_queue) {
if(id == task->getID()) {
task->run();
}
}
}

//run all specified tasks concurrently
inline void run_task(std::vector<std::string> ids) {
std::vector<std::thread*> threads;
for(auto id : ids) {
for(auto task : task_queue) {
if(task->getID() == id) {
threads.push_back(new std::thread(&MIST::Task::run, task));
}
}
}

for(auto thread : threads) {
thread->join();
}

threads.empty();
}

inline void send_task(std::string task, MIST::Machine machine, short int port) {
SendData* sd = new SendData(machine.address, port);
sd->send(task, (char)182);
delete sd;
}

inline void stop() {
this->running = false;
delete checker;
}
Expand Down
4 changes: 2 additions & 2 deletions include/networking/ReceiveData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ReceiveData {
ReceiveData(ushort port = 8008) : acceptor(service, tcp::endpoint(tcp::v4(), port)),
socket(service) { }

//Can return any amount on the socket stream
// Can return any amount on the socket stream
template<size_t N>
inline std::string receive() {
std::string message;
Expand Down Expand Up @@ -47,7 +47,7 @@ class ReceiveData {
return message;
}

void inline stop() {
inline void stop() {
asio::error_code error;
socket.shutdown(tcp::socket::shutdown_type::shutdown_send, error);
}
Expand Down
Loading