Commit 67683923 authored by Dominik Charousset's avatar Dominik Charousset

more consistent coding style

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