Skip to content

Commit

Permalink
Float comparison, better local includes
Browse files Browse the repository at this point in the history
  • Loading branch information
SemaiCZE committed Jun 27, 2018
1 parent 6b390de commit be323a5
Show file tree
Hide file tree
Showing 62 changed files with 161 additions and 131 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ set(SOURCE_FILES
${HELPERS_DIR}/logger.cpp
${HELPERS_DIR}/string_utils.h
${HELPERS_DIR}/string_utils.cpp
${HELPERS_DIR}/type_utils.h
${HELPERS_DIR}/format.h

${CONFIG_DIR}/worker_config.cpp
Expand Down Expand Up @@ -214,6 +215,8 @@ set(SOURCE_FILES
${COMMAND_DIR}/jobs_client_commands.h
)

include_directories(AFTER, ${SRC_DIR})


add_executable(${EXEC_NAME} ${SOURCE_FILES})

Expand Down
6 changes: 3 additions & 3 deletions src/commands/command_holder.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include <functional>
#include <map>
#include <zmq.hpp>
#include "../helpers/logger.h"
#include "../job/job_evaluator_interface.h"
#include "../config/worker_config.h"
#include "helpers/logger.h"
#include "job/job_evaluator_interface.h"
#include "config/worker_config.h"


/**
Expand Down
6 changes: 3 additions & 3 deletions src/commands/jobs_client_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#define RECODEX_WORKER_JOBS_CLIENT_COMMANDS_H

#include "command_holder.h"
#include "../helpers/zmq_socket.h"
#include "../eval_request.h"
#include "../eval_response.h"
#include "helpers/zmq_socket.h"
#include "eval_request.h"
#include "eval_response.h"

/**
* Commands from worker "main" thread.
Expand Down
10 changes: 6 additions & 4 deletions src/config/sandbox_limits.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <tuple>
#include <utility>
#include <algorithm>
#include "helpers/type_utils.h"


/**
Expand Down Expand Up @@ -132,10 +133,11 @@ struct sandbox_limits {
bool operator==(const sandbox_limits &second) const
{
return (memory_usage == second.memory_usage && extra_memory == second.extra_memory &&
cpu_time == second.cpu_time && wall_time == second.wall_time && extra_time == second.extra_time &&
stack_size == second.stack_size && files_size == second.files_size && disk_size == second.disk_size &&
disk_files == second.disk_files && processes == second.processes && share_net == second.share_net &&
environ_vars == second.environ_vars && bound_dirs == second.bound_dirs);
helpers::almost_equal(cpu_time, second.cpu_time) && helpers::almost_equal(wall_time, second.wall_time) &&
helpers::almost_equal(extra_time, second.extra_time) && stack_size == second.stack_size &&
files_size == second.files_size && disk_size == second.disk_size && disk_files == second.disk_files &&
processes == second.processes && share_net == second.share_net && environ_vars == second.environ_vars &&
bound_dirs == second.bound_dirs);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/config/worker_config.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "worker_config.h"
#include "../helpers/config.h"
#include "helpers/config.h"

worker_config::worker_config() = default;

Expand Down
2 changes: 1 addition & 1 deletion src/config/worker_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace fs = boost::filesystem;

#include "log_config.h"
#include "fileman_config.h"
#include "../sandbox/sandbox_base.h"
#include "sandbox/sandbox_base.h"


/**
Expand Down
2 changes: 1 addition & 1 deletion src/fileman/cache_manager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "cache_manager.h"
#include "../helpers/string_utils.h"
#include "helpers/string_utils.h"


cache_manager::cache_manager(std::shared_ptr<spdlog::logger> logger)
Expand Down
2 changes: 1 addition & 1 deletion src/fileman/cache_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <string>
#include <memory>
#include "file_manager_interface.h"
#include "../helpers/logger.h"
#include "helpers/logger.h"

#define BOOST_FILESYSTEM_NO_DEPRECATED
#define BOOST_NO_CXX11_SCOPED_ENUMS
Expand Down
4 changes: 2 additions & 2 deletions src/fileman/http_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <string>
#include <memory>
#include "file_manager_interface.h"
#include "../helpers/logger.h"
#include "../config/fileman_config.h"
#include "helpers/logger.h"
#include "config/fileman_config.h"


/**
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include <memory>
#include <yaml-cpp/yaml.h>
#include "../config/job_metadata.h"
#include "../config/task_metadata.h"
#include "config/job_metadata.h"
#include "config/task_metadata.h"


namespace helpers
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/filesystem.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef RECODEX_WORKER_HELPERS_FILESYSTEM_HPP
#define RECODEX_WORKER_HELPERS_FILESYSTEM_HPP

#include "../config/sandbox_limits.h"
#include "config/sandbox_limits.h"
#define BOOST_FILESYSTEM_NO_DEPRECATED
#define BOOST_NO_CXX11_SCOPED_ENUMS
#include <boost/filesystem.hpp>
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/topological_sort.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <queue>
#include <stack>
#include <set>
#include "../tasks/task_base.h"
#include "tasks/task_base.h"


namespace helpers
Expand Down
24 changes: 24 additions & 0 deletions src/helpers/type_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef RECODEX_WORKER_HELPERS_TYPE_UTILS_HPP
#define RECODEX_WORKER_HELPERS_TYPE_UTILS_HPP

#include <cmath>
#include <limits>
#include <type_traits>
#include <algorithm>

namespace helpers
{

template <class T>
typename std::enable_if<!std::numeric_limits<T>::is_integer, bool>::type almost_equal(T x, T y, int ulp = 2)
{
// the machine epsilon has to be scaled to the magnitude of the values used
// and multiplied by the desired precision in ULPs (units in the last place)
return std::abs(x - y) <= std::numeric_limits<T>::epsilon() * std::abs(x + y) * ulp
// unless the result is subnormal
|| std::abs(x - y) < std::numeric_limits<T>::min();
}

} // namespace helpers

#endif // RECODEX_WORKER_HELPERS_TYPE_UTILS_HPP
7 changes: 4 additions & 3 deletions src/job/job.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "job.h"
#include "job_exception.h"
#include "helpers/type_utils.h"

job::job(std::shared_ptr<job_metadata> job_meta,
std::shared_ptr<worker_config> worker_conf,
Expand Down Expand Up @@ -206,17 +207,17 @@ void job::process_task_limits(const std::shared_ptr<sandbox_limits> &limits)
std::string msg = " item is bigger than default worker value";

// we have to load defaults from worker_config if necessary and check for bigger limits than in worker_config
if (limits->cpu_time == FLT_MAX) {
if (helpers::almost_equal(limits->cpu_time, FLT_MAX)) {
limits->cpu_time = worker_limits.cpu_time;
} else {
if (limits->cpu_time > worker_limits.cpu_time) { throw job_exception("time" + msg); }
}
if (limits->wall_time == FLT_MAX) {
if (helpers::almost_equal(limits->wall_time, FLT_MAX)) {
limits->wall_time = worker_limits.wall_time;
} else {
if (limits->wall_time > worker_limits.wall_time) { throw job_exception("wall-time" + msg); }
}
if (limits->extra_time == FLT_MAX) {
if (helpers::almost_equal(limits->extra_time, FLT_MAX)) {
limits->extra_time = worker_limits.extra_time;
} else {
if (limits->extra_time > worker_limits.extra_time) { throw job_exception("extra-time" + msg); }
Expand Down
16 changes: 8 additions & 8 deletions src/job/job.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
namespace fs = boost::filesystem;

#include "spdlog/spdlog.h"
#include "../helpers/logger.h"
#include "../helpers/topological_sort.h"
#include "../helpers/filesystem.h"
#include "../config/worker_config.h"
#include "../config/job_metadata.h"
#include "../config/task_metadata.h"
#include "../tasks/task_factory_interface.h"
#include "../sandbox/sandbox_base.h"
#include "helpers/logger.h"
#include "helpers/topological_sort.h"
#include "helpers/filesystem.h"
#include "config/worker_config.h"
#include "config/job_metadata.h"
#include "config/task_metadata.h"
#include "tasks/task_factory_interface.h"
#include "sandbox/sandbox_base.h"
#include "progress_callback_interface.h"


Expand Down
8 changes: 4 additions & 4 deletions src/job/job_evaluator.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "job_evaluator.h"
#include "job_exception.h"
#include "../config/job_metadata.h"
#include "../fileman/fallback_file_manager.h"
#include "../fileman/prefixed_file_manager.h"
#include "../helpers/config.h"
#include "config/job_metadata.h"
#include "fileman/fallback_file_manager.h"
#include "fileman/prefixed_file_manager.h"
#include "helpers/config.h"

job_evaluator::job_evaluator(std::shared_ptr<spdlog::logger> logger,
std::shared_ptr<worker_config> config,
Expand Down
12 changes: 6 additions & 6 deletions src/job/job_evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
#include <fstream>
#include <vector>
#include <utility>
#include "../helpers/logger.h"
#include "helpers/logger.h"

#define BOOST_FILESYSTEM_NO_DEPRECATED
#define BOOST_NO_CXX11_SCOPED_ENUMS
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;

#include "job.h"
#include "../config/worker_config.h"
#include "../fileman/file_manager_interface.h"
#include "../tasks/task_factory.h"
#include "../archives/archivator.h"
#include "../helpers/filesystem.h"
#include "config/worker_config.h"
#include "fileman/file_manager_interface.h"
#include "tasks/task_factory.h"
#include "archives/archivator.h"
#include "helpers/filesystem.h"
#include "job_evaluator_interface.h"


Expand Down
4 changes: 2 additions & 2 deletions src/job/job_evaluator_interface.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef RECODEX_WORKER_JOB_EVALUATOR_BASE_H
#define RECODEX_WORKER_JOB_EVALUATOR_BASE_H

#include "../eval_request.h"
#include "../eval_response.h"
#include "eval_request.h"
#include "eval_response.h"


/**
Expand Down
10 changes: 5 additions & 5 deletions src/job/job_receiver.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "job_receiver.h"
#include "../connection_proxy.h"
#include "../eval_request.h"
#include "../eval_response.h"
#include "../helpers/zmq_socket.h"
#include "../commands/jobs_client_commands.h"
#include "connection_proxy.h"
#include "eval_request.h"
#include "eval_response.h"
#include "helpers/zmq_socket.h"
#include "commands/jobs_client_commands.h"


job_receiver::job_receiver(const std::shared_ptr<zmq::context_t> &context,
Expand Down
4 changes: 2 additions & 2 deletions src/job/job_receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <vector>
#include <string>
#include "job_evaluator_interface.h"
#include "../commands/command_holder.h"
#include "../helpers/logger.h"
#include "commands/command_holder.h"
#include "helpers/logger.h"

/**
* Job receiver handles incoming requests from broker_connection and
Expand Down
6 changes: 3 additions & 3 deletions src/job/progress_callback.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "progress_callback.h"
#include "../helpers/zmq_socket.h"
#include "../helpers/logger.h"
#include "../connection_proxy.h"
#include "helpers/zmq_socket.h"
#include "helpers/logger.h"
#include "connection_proxy.h"

progress_callback::progress_callback(
const std::shared_ptr<zmq::context_t> &context, std::shared_ptr<spdlog::logger> logger)
Expand Down
2 changes: 1 addition & 1 deletion src/sandbox/isolate_sandbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define BOOST_FILESYSTEM_NO_DEPRECATED
#define BOOST_NO_CXX11_SCOPED_ENUMS
#include <boost/filesystem.hpp>
#include "../helpers/filesystem.h"
#include "helpers/filesystem.h"

namespace fs = boost::filesystem;

Expand Down
4 changes: 2 additions & 2 deletions src/sandbox/isolate_sandbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

#include <memory>
#include <vector>
#include "../helpers/logger.h"
#include "helpers/logger.h"
#include "sandbox_base.h"
#include "../config/sandbox_config.h"
#include "config/sandbox_config.h"

/**
* Class implementing operations with Isolate sandbox.
Expand Down
6 changes: 3 additions & 3 deletions src/sandbox/sandbox_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include <vector>
#include <sstream>
#include "spdlog/spdlog.h"
#include "../config/sandbox_limits.h"
#include "../config/task_results.h"
#include "../helpers/format.h"
#include "config/sandbox_limits.h"
#include "config/task_results.h"
#include "helpers/format.h"


/**
Expand Down
8 changes: 4 additions & 4 deletions src/tasks/create_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

#include <memory>
#include <spdlog/spdlog.h>
#include "../config/worker_config.h"
#include "../config/sandbox_config.h"
#include "../config/sandbox_limits.h"
#include "../config/task_metadata.h"
#include "config/worker_config.h"
#include "config/sandbox_config.h"
#include "config/sandbox_limits.h"
#include "config/task_metadata.h"

/** data for proper construction of @ref external_task class */
struct create_params {
Expand Down
6 changes: 3 additions & 3 deletions src/tasks/external_task.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "external_task.h"
#include "../sandbox/isolate_sandbox.h"
#include "../helpers/string_utils.h"
#include "../helpers/filesystem.h"
#include "sandbox/isolate_sandbox.h"
#include "helpers/string_utils.h"
#include "helpers/filesystem.h"
#include <fstream>
#include <algorithm>
#define BOOST_FILESYSTEM_NO_DEPRECATED
Expand Down
4 changes: 2 additions & 2 deletions src/tasks/external_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include <memory>
#include "task_base.h"
#include "create_params.h"
#include "../sandbox/sandbox_base.h"
#include "../config/sandbox_limits.h"
#include "sandbox/sandbox_base.h"
#include "config/sandbox_limits.h"


/**
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/internal/archivate_task.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "archivate_task.h"
#include "../../archives/archivator.h"
#include "archives/archivator.h"


archivate_task::archivate_task(size_t id, std::shared_ptr<task_metadata> task_meta) : task_base(id, task_meta)
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/internal/archivate_task.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef RECODEX_WORKER_INTERNAL_ARCHIVATE_TASK_H
#define RECODEX_WORKER_INTERNAL_ARCHIVATE_TASK_H

#include "../task_base.h"
#include "tasks/task_base.h"


/**
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/internal/cp_task.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef RECODEX_WORKER_INTERNAL_CP_TASK_H
#define RECODEX_WORKER_INTERNAL_CP_TASK_H

#include "../task_base.h"
#include "tasks/task_base.h"


/**
Expand Down
Loading

0 comments on commit be323a5

Please sign in to comment.