Commit 67683923 authored by Dominik Charousset's avatar Dominik Charousset

more consistent coding style

parent d67d10b2
......@@ -34,8 +34,8 @@
#include <iostream>
#include "utility.hpp"
#include "cppa/cppa.hpp"
#include "cppa/sb_actor.hpp"
using namespace std;
using namespace cppa;
......
......@@ -36,21 +36,11 @@
#include <boost/progress.hpp>
#include "utility.hpp"
#include "cppa/cppa.hpp"
#include "cppa/match.hpp"
#include "cppa/actor_proxy.hpp"
using namespace std;
using namespace cppa;
using namespace cppa::placeholders;
#define PRINT_MESSAGE() { \
ostringstream oss; \
oss << to_string(self->parent_process()) << ": " << __PRETTY_FUNCTION__ << " ->" \
<< to_string(self->last_dequeued()) \
<< "\n"; \
cout << oss.str(); \
} ((void) 0)
void usage() {
cout << "Running in server mode:" << endl
......
......@@ -35,24 +35,19 @@
#include <iostream>
#include "utility.hpp"
#include "cppa/cppa.hpp"
#include "cppa/sb_actor.hpp"
using std::cout;
using std::cerr;
using std::endl;
using std::int64_t;
#include "cppa/cppa.hpp"
using namespace std;
using namespace cppa;
struct fsm_receiver : sb_actor<fsm_receiver> {
int64_t m_value;
uint64_t m_value;
behavior init_state;
fsm_receiver(int64_t max) : m_value(0) {
fsm_receiver(uint64_t max) : m_value(0) {
init_state = (
on(atom("msg")) >> [=]() {
++m_value;
if (m_value == max) {
on(atom("msg")) >> [=] {
if (++m_value == max) {
quit();
}
}
......@@ -60,51 +55,57 @@ struct fsm_receiver : sb_actor<fsm_receiver> {
}
};
void receiver(int64_t max) {
int64_t value;
receive_while(gref(value) < max) (
on(atom("msg")) >> [&]() {
void receiver(uint64_t max) {
uint64_t value;
receive_while (gref(value) < max) (
on(atom("msg")) >> [&] {
++value;
}
);
}
void sender(actor_ptr whom, int64_t count) {
void sender(actor_ptr whom, uint64_t count) {
any_tuple msg = make_cow_tuple(atom("msg"));
for (int64_t i = 0; i < count; ++i) {
for (uint64_t i = 0; i < count; ++i) {
whom->enqueue(nullptr, msg);
}
}
void usage() {
cout << "usage: mailbox_performance "
"(stacked|event-based) (sending threads) (msg per thread)" << endl
"(stacked|event-based) NUM_THREADS MSGS_PER_THREAD" << endl
<< endl;
}
enum impl_type { stacked, event_based };
option<impl_type> stoimpl(const std::string& str) {
if (str == "stacked") return stacked;
else if (str == "event-based") return event_based;
return {};
}
int main(int argc, char** argv) {
if (argc == 4) {
int64_t num_sender = rd<int64_t>(argv[2]);
int64_t num_msgs = rd<int64_t>(argv[3]);
actor_ptr testee;
if (strcmp(argv[1], "stacked") == 0) {
testee = spawn(receiver, num_sender * num_msgs);
}
else if (strcmp(argv[1], "event-based") == 0) {
testee = spawn<fsm_receiver>(num_sender * num_msgs);
}
else {
usage();
return 1;
}
for (int64_t i = 0; i < num_sender; ++i) {
std::thread(sender, testee, num_msgs).detach();
}
await_all_others_done();
}
else {
usage();
return 1;
}
return 0;
int result = 1;
vector<string> args(argv + 1, argv + argc);
match (args) (
on(stoimpl, spro<uint64_t>, spro<uint64_t>) >> [&](impl_type impl, uint64_t num_sender, uint64_t num_msgs) {
auto total = num_sender * num_msgs;
auto testee = (impl == stacked) ? spawn(receiver, total)
: spawn<fsm_receiver>(total);
vector<thread> senders;
for (uint64_t i = 0; i < num_sender; ++i) {
senders.emplace_back(sender, testee, num_msgs);
}
for (auto& s : senders) {
s.join();
}
result = 0; // no error occurred
},
others() >> usage
);
await_all_others_done();
shutdown();
return result;
}
......@@ -36,120 +36,109 @@
#include <cstdint>
#include <iostream>
#include "cppa/on.hpp"
#include "cppa/atom.hpp"
#include "cppa/match.hpp"
#include "cppa/cow_tuple.hpp"
#include "cppa/announce.hpp"
#include "utility.hpp"
using std::cout;
using std::cerr;
using std::endl;
using std::list;
using std::string;
using std::int64_t;
#include "cppa/cppa.hpp"
using namespace std;
using namespace cppa;
template<typename T>
T rd(const char* cstr) {
char* endptr = nullptr;
T result = static_cast<T>(strtol(cstr, &endptr, 10));
if (endptr == nullptr || *endptr != '\0') {
std::string errstr;
errstr += "\"";
errstr += cstr;
errstr += "\" is not an integer";
throw std::invalid_argument(errstr);
}
return result;
void usage() {
cout << "usage: matching (cow_tuple|object_array) NUM_LOOPS" << endl;
}
void usage() {
cerr << "usage: matching (cow_tuple|object_array) {NUM_LOOPS}" << endl;
exit(1);
enum impl_type { cow_tuples, obj_arrays };
option<impl_type> implproj(const string& str) {
if (str == "cow_tuple") return cow_tuples;
else if (str == "object_array") return obj_arrays;
return {};
}
int main(int argc, char** argv) {
int result = 1;
announce<list<int>>();
if (argc != 3) usage();
auto num_loops = rd<int64_t>(argv[2]);
any_tuple m1;
any_tuple m2;
any_tuple m3;
any_tuple m4;
any_tuple m5;
any_tuple m6;
if (strcmp(argv[1], "cow_tuple") == 0) {
m1 = make_cow_tuple(atom("msg1"), 0);
m2 = make_cow_tuple(atom("msg2"), 0.0);
m3 = make_cow_tuple(atom("msg3"), list<int>{0});
m4 = make_cow_tuple(atom("msg4"), 0, "0");
m5 = make_cow_tuple(atom("msg5"), 0, 0, 0);
m6 = make_cow_tuple(atom("msg6"), 0, 0.0, "0");
}
else if (strcmp(argv[1], "object_array") == 0) {
auto m1o = new detail::object_array;
m1o->push_back(object::from(atom("msg1")));
m1o->push_back(object::from(0));
m1 = any_tuple{m1o};
auto m2o = new detail::object_array;
m2o->push_back(object::from(atom("msg2")));
m2o->push_back(object::from(0.0));
m2 = any_tuple{m2o};
auto m3o = new detail::object_array;
m3o->push_back(object::from(atom("msg3")));
m3o->push_back(object::from(list<int>{0}));
m3 = any_tuple{m3o};
auto m4o = new detail::object_array;
m4o->push_back(object::from(atom("msg4")));
m4o->push_back(object::from(0));
m4o->push_back(object::from(std::string("0")));
m4 = any_tuple{m4o};
auto m5o = new detail::object_array;
m5o->push_back(object::from(atom("msg5")));
m5o->push_back(object::from(0));
m5o->push_back(object::from(0));
m5o->push_back(object::from(0));
m5 = any_tuple{m5o};
auto m6o = new detail::object_array;
m6o->push_back(object::from(atom("msg6")));
m6o->push_back(object::from(0));
m6o->push_back(object::from(0.0));
m6o->push_back(object::from(std::string("0")));
m6 = any_tuple{m6o};
}
else {
usage();
}
int64_t m1matched = 0;
int64_t m2matched = 0;
int64_t m3matched = 0;
int64_t m4matched = 0;
int64_t m5matched = 0;
int64_t m6matched = 0;
auto part_fun = (
on<atom("msg1"), int>() >> [&]() { ++m1matched; },
on<atom("msg2"), double>() >> [&]() { ++m2matched; },
on<atom("msg3"), list<int> >() >> [&]() { ++m3matched; },
on<atom("msg4"), int, string>() >> [&]() { ++m4matched; },
on<atom("msg5"), int, int, int>() >> [&]() { ++m5matched; },
on<atom("msg6"), int, double, string>() >> [&]() { ++m6matched; }
vector<string> args(argv + 1, argv + argc);
match (args) (
on(implproj, spro<unsigned>) >> [&](impl_type impl, unsigned num_loops) {
result = 0;
any_tuple m1;
any_tuple m2;
any_tuple m3;
any_tuple m4;
any_tuple m5;
any_tuple m6;
if (impl == cow_tuples) {
m1 = make_cow_tuple(atom("msg1"), 0);
m2 = make_cow_tuple(atom("msg2"), 0.0);
m3 = make_cow_tuple(atom("msg3"), list<int>{0});
m4 = make_cow_tuple(atom("msg4"), 0, "0");
m5 = make_cow_tuple(atom("msg5"), 0, 0, 0);
m6 = make_cow_tuple(atom("msg6"), 0, 0.0, "0");
}
else {
auto m1o = new detail::object_array;
m1o->push_back(object::from(atom("msg1")));
m1o->push_back(object::from(0));
m1 = any_tuple{m1o};
auto m2o = new detail::object_array;
m2o->push_back(object::from(atom("msg2")));
m2o->push_back(object::from(0.0));
m2 = any_tuple{m2o};
auto m3o = new detail::object_array;
m3o->push_back(object::from(atom("msg3")));
m3o->push_back(object::from(list<int>{0}));
m3 = any_tuple{m3o};
auto m4o = new detail::object_array;
m4o->push_back(object::from(atom("msg4")));
m4o->push_back(object::from(0));
m4o->push_back(object::from(std::string("0")));
m4 = any_tuple{m4o};
auto m5o = new detail::object_array;
m5o->push_back(object::from(atom("msg5")));
m5o->push_back(object::from(0));
m5o->push_back(object::from(0));
m5o->push_back(object::from(0));
m5 = any_tuple{m5o};
auto m6o = new detail::object_array;
m6o->push_back(object::from(atom("msg6")));
m6o->push_back(object::from(0));
m6o->push_back(object::from(0.0));
m6o->push_back(object::from(std::string("0")));
m6 = any_tuple{m6o};
}
int64_t m1matched = 0;
int64_t m2matched = 0;
int64_t m3matched = 0;
int64_t m4matched = 0;
int64_t m5matched = 0;
int64_t m6matched = 0;
auto part_fun = (
on<atom("msg1"), int>() >> [&]() { ++m1matched; },
on<atom("msg2"), double>() >> [&]() { ++m2matched; },
on<atom("msg3"), list<int> >() >> [&]() { ++m3matched; },
on<atom("msg4"), int, string>() >> [&]() { ++m4matched; },
on<atom("msg5"), int, int, int>() >> [&]() { ++m5matched; },
on<atom("msg6"), int, double, string>() >> [&]() { ++m6matched; }
);
for (int64_t i = 0; i < num_loops; ++i) {
part_fun(m1);
part_fun(m2);
part_fun(m3);
part_fun(m4);
part_fun(m5);
part_fun(m6);
}
assert(m1matched == num_loops);
assert(m2matched == num_loops);
assert(m3matched == num_loops);
assert(m4matched == num_loops);
assert(m5matched == num_loops);
assert(m6matched == num_loops);
result = 0;
},
others() >> usage
);
for (int64_t i = 0; i < num_loops; ++i) {
part_fun(m1);
part_fun(m2);
part_fun(m3);
part_fun(m4);
part_fun(m5);
part_fun(m6);
}
assert(m1matched == num_loops);
assert(m2matched == num_loops);
assert(m3matched == num_loops);
assert(m4matched == num_loops);
assert(m5matched == num_loops);
assert(m6matched == num_loops);
shutdown();
return result;
}
......@@ -36,20 +36,12 @@
#include "utility.hpp"
#include "cppa/cppa.hpp"
#include "cppa/match.hpp"
#include "cppa/sb_actor.hpp"
#include "cppa/context_switching_actor.hpp"
using std::cout;
using std::cerr;
using std::endl;
using std::int64_t;
using std::uint64_t;
typedef std::vector<uint64_t> factors;
using namespace std;
using namespace cppa;
typedef vector<uint64_t> factors;
constexpr uint64_t s_task_n = uint64_t(86028157)*329545133;
constexpr uint64_t s_factor1 = 86028157;
constexpr uint64_t s_factor2 = 329545133;
......@@ -247,44 +239,35 @@ void usage() {
exit(1);
}
enum mode_type { event_based, fiber_based };
enum impl_type { stacked, event_based };
option<int> _2i(const std::string& str) {
char* endptr = nullptr;
int result = static_cast<int>(strtol(str.c_str(), &endptr, 10));
if (endptr == nullptr || *endptr != '\0') {
return {};
}
return result;
option<impl_type> stoimpl(const std::string& str) {
if (str == "stacked") return stacked;
else if (str == "event-based") return event_based;
return {};
}
int main(int argc, char** argv) {
announce<factors>();
if (argc != 6) usage();
// skip argv[0] (app name)
int result = 1;
std::vector<std::string> args{argv + 1, argv + argc};
match(args) (
on(val<std::string>, _2i, _2i, _2i, _2i) >> [](const std::string& mode,
int num_rings,
int ring_size,
int initial_token_value,
int repetitions) {
on(stoimpl, spro<int>, spro<int>, spro<int>, spro<int>)
>> [&](impl_type impl, int num_rings, int ring_size, int initial_token_value, int repetitions) {
int num_msgs = num_rings + (num_rings * repetitions);
if (mode == "event-based") {
auto mc = spawn<fsm_supervisor>(num_msgs);
run_test([&]() { return spawn<fsm_chain_master>(mc); },
num_rings, ring_size, initial_token_value, repetitions);
}
else if (mode == "stacked") {
auto mc = spawn(supervisor, num_msgs);
run_test([&]() { return spawn(chain_master, mc); },
auto sv = (impl == event_based) ? spawn<fsm_supervisor>(num_msgs)
: spawn(supervisor, num_msgs);
if (impl == event_based) {
run_test([sv] { return spawn<fsm_chain_master>(sv); },
num_rings, ring_size, initial_token_value, repetitions);
}
else {
usage();
run_test([sv] { return spawn(chain_master, sv); },
num_rings, ring_size, initial_token_value, repetitions);
}
result = 0; // no error occurred
},
others() >> usage
);
return 0;
return result;
}
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