#![allow(clippy::large_enum_variant, clippy::type_complexity, clippy::too_many_arguments)] use criterion::{black_box, criterion_group, criterion_main, Criterion}; use mpstthree::generate; use mpstthree::binary::struct_trait::{end::End, recv::Recv, send::Send}; use mpstthree::role::broadcast::RoleBroadcast; use mpstthree::role::end::RoleEnd; use std::error::Error; // Create new roles generate!( "rec_and_cancel", MeshedChannels, A, B, C, D, E, F, G, H, I, J, K ); // Types // A enum Branching0fromKtoA { Forward( MeshedChannels< Send<(), End>, End, End, End, End, End, End, End, End, RecursAtoK, RoleB>, NameA, >, ), Backward( MeshedChannels< Recv<(), End>, End, End, End, End, End, End, End, End, RecursAtoK, RoleB>, NameA, >, ), Done(MeshedChannels), } type RecursAtoK = Recv; // B enum Branching0fromKtoB { Forward( MeshedChannels< Recv<(), End>, Send<(), End>, End, End, End, End, End, End, End, RecursBtoK, RoleA>>, NameB, >, ), Backward( MeshedChannels< Send<(), End>, Recv<(), End>, End, End, End, End, End, End, End, RecursBtoK, RoleC>>, NameB, >, ), Done(MeshedChannels), } type RecursBtoK = Recv; // C enum Branching0fromKtoC { Forward( MeshedChannels< End, Recv<(), End>, Send<(), End>, End, End, End, End, End, End, RecursCtoK, RoleB>>, NameC, >, ), Backward( MeshedChannels< End, Send<(), End>, Recv<(), End>, End, End, End, End, End, End, RecursCtoK, RoleD>>, NameC, >, ), Done(MeshedChannels), } type RecursCtoK = Recv; // D enum Branching0fromKtoD { Forward( MeshedChannels< End, End, Recv<(), End>, Send<(), End>, End, End, End, End, End, RecursDtoK, RoleC>>, NameD, >, ), Backward( MeshedChannels< End, End, Send<(), End>, Recv<(), End>, End, End, End, End, End, RecursDtoK, RoleE>>, NameD, >, ), Done(MeshedChannels), } type RecursDtoK = Recv; // E enum Branching0fromKtoE { Forward( MeshedChannels< End, End, End, Recv<(), End>, Send<(), End>, End, End, End, End, RecursEtoK, RoleD>>, NameE, >, ), Backward( MeshedChannels< End, End, End, Send<(), End>, Recv<(), End>, End, End, End, End, RecursEtoK, RoleF>>, NameE, >, ), Done(MeshedChannels), } type RecursEtoK = Recv; // F enum Branching0fromKtoF { Forward( MeshedChannels< End, End, End, End, Recv<(), End>, Send<(), End>, End, End, End, RecursFtoK, RoleE>>, NameF, >, ), Backward( MeshedChannels< End, End, End, End, Send<(), End>, Recv<(), End>, End, End, End, RecursFtoK, RoleG>>, NameF, >, ), Done(MeshedChannels), } type RecursFtoK = Recv; // G enum Branching0fromKtoG { Forward( MeshedChannels< End, End, End, End, End, Recv<(), End>, Send<(), End>, End, End, RecursGtoK, RoleF>>, NameG, >, ), Backward( MeshedChannels< End, End, End, End, End, Send<(), End>, Recv<(), End>, End, End, RecursGtoK, RoleH>>, NameG, >, ), Done(MeshedChannels), } type RecursGtoK = Recv; // H enum Branching0fromKtoH { Forward( MeshedChannels< End, End, End, End, End, End, Recv<(), End>, Send<(), End>, End, RecursHtoK, RoleG>>, NameH, >, ), Backward( MeshedChannels< End, End, End, End, End, End, Send<(), End>, Recv<(), End>, End, RecursHtoK, RoleI>>, NameH, >, ), Done(MeshedChannels), } type RecursHtoK = Recv; // I enum Branching0fromKtoI { Forward( MeshedChannels< End, End, End, End, End, End, End, Recv<(), End>, Send<(), End>, RecursItoK, RoleH>>, NameI, >, ), Backward( MeshedChannels< End, End, End, End, End, End, End, Send<(), End>, Recv<(), End>, RecursItoK, RoleJ>>, NameI, >, ), Done(MeshedChannels), } type RecursItoK = Recv; // J enum Branching0fromKtoJ { Forward( MeshedChannels< End, End, End, End, End, End, End, End, Recv<(), End>, Send<(), RecursJtoK>, RoleI>>, NameJ, >, ), Backward( MeshedChannels< End, End, End, End, End, End, End, End, Send<(), End>, Recv<(), RecursJtoK>, RoleK>>, NameJ, >, ), Done(MeshedChannels), } type RecursJtoK = Recv; // K type Choose0fromKtoA = Send; type Choose0fromKtoB = Send; type Choose0fromKtoC = Send; type Choose0fromKtoD = Send; type Choose0fromKtoE = Send; type Choose0fromKtoF = Send; type Choose0fromKtoG = Send; type Choose0fromKtoH = Send; type Choose0fromKtoI = Send; type Choose0fromKtoJ = Send; type EndpointForwardK = MeshedChannels< Choose0fromKtoA, Choose0fromKtoB, Choose0fromKtoC, Choose0fromKtoD, Choose0fromKtoE, Choose0fromKtoF, Choose0fromKtoG, Choose0fromKtoH, Choose0fromKtoI, Recv<(), Choose0fromKtoJ>, RoleJ, NameK, >; type EndpointBackwardK = MeshedChannels< Choose0fromKtoA, Choose0fromKtoB, Choose0fromKtoC, Choose0fromKtoD, Choose0fromKtoE, Choose0fromKtoF, Choose0fromKtoG, Choose0fromKtoH, Choose0fromKtoI, Send<(), Choose0fromKtoJ>, RoleJ, NameK, >; // Creating the MP sessions type EndpointA = MeshedChannels< End, End, End, End, End, End, End, End, End, RecursAtoK, RoleK, NameA, >; type EndpointB = MeshedChannels< End, End, End, End, End, End, End, End, End, RecursBtoK, RoleK, NameB, >; type EndpointC = MeshedChannels< End, End, End, End, End, End, End, End, End, RecursCtoK, RoleK, NameC, >; type EndpointD = MeshedChannels< End, End, End, End, End, End, End, End, End, RecursDtoK, RoleK, NameD, >; type EndpointE = MeshedChannels< End, End, End, End, End, End, End, End, End, RecursEtoK, RoleK, NameE, >; type EndpointF = MeshedChannels< End, End, End, End, End, End, End, End, End, RecursFtoK, RoleK, NameF, >; type EndpointG = MeshedChannels< End, End, End, End, End, End, End, End, End, RecursGtoK, RoleK, NameG, >; type EndpointH = MeshedChannels< End, End, End, End, End, End, End, End, End, RecursHtoK, RoleK, NameH, >; type EndpointI = MeshedChannels< End, End, End, End, End, End, End, End, End, RecursItoK, RoleK, NameI, >; type EndpointJ = MeshedChannels< End, End, End, End, End, End, End, End, End, RecursJtoK, RoleK, NameJ, >; type EndpointK = MeshedChannels< Choose0fromKtoA, Choose0fromKtoB, Choose0fromKtoC, Choose0fromKtoD, Choose0fromKtoE, Choose0fromKtoF, Choose0fromKtoG, Choose0fromKtoH, Choose0fromKtoI, Choose0fromKtoJ, RoleBroadcast, NameK, >; fn endpoint_a(s: EndpointA) -> Result<(), Box> { offer_mpst!(s, { Branching0fromKtoA::Done(s) => { s.close() }, Branching0fromKtoA::Forward(s) => { let s = s.send(())?; endpoint_a(s) }, Branching0fromKtoA::Backward(s) => { let (_, s) = s.recv()?; endpoint_a(s) }, }) } fn endpoint_b(s: EndpointB) -> Result<(), Box> { offer_mpst!(s, { Branching0fromKtoB::Done(s) => { s.close() }, Branching0fromKtoB::Forward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_b(s) }, Branching0fromKtoB::Backward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_b(s) }, }) } fn endpoint_c(s: EndpointC) -> Result<(), Box> { offer_mpst!(s, { Branching0fromKtoC::Done(s) => { s.close() }, Branching0fromKtoC::Forward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_c(s) }, Branching0fromKtoC::Backward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_c(s) }, }) } fn endpoint_d(s: EndpointD) -> Result<(), Box> { offer_mpst!(s, { Branching0fromKtoD::Done(s) => { s.close() }, Branching0fromKtoD::Forward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_d(s) }, Branching0fromKtoD::Backward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_d(s) }, }) } fn endpoint_e(s: EndpointE) -> Result<(), Box> { offer_mpst!(s, { Branching0fromKtoE::Done(s) => { s.close() }, Branching0fromKtoE::Forward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_e(s) }, Branching0fromKtoE::Backward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_e(s) }, }) } fn endpoint_f(s: EndpointF) -> Result<(), Box> { offer_mpst!(s, { Branching0fromKtoF::Done(s) => { s.close() }, Branching0fromKtoF::Forward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_f(s) }, Branching0fromKtoF::Backward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_f(s) }, }) } fn endpoint_g(s: EndpointG) -> Result<(), Box> { offer_mpst!(s, { Branching0fromKtoG::Done(s) => { s.close() }, Branching0fromKtoG::Forward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_g(s) }, Branching0fromKtoG::Backward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_g(s) }, }) } fn endpoint_h(s: EndpointH) -> Result<(), Box> { offer_mpst!(s, { Branching0fromKtoH::Done(s) => { s.close() }, Branching0fromKtoH::Forward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_h(s) }, Branching0fromKtoH::Backward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_h(s) }, }) } fn endpoint_i(s: EndpointI) -> Result<(), Box> { offer_mpst!(s, { Branching0fromKtoI::Done(s) => { s.close() }, Branching0fromKtoI::Forward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_i(s) }, Branching0fromKtoI::Backward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_i(s) }, }) } fn endpoint_j(s: EndpointJ) -> Result<(), Box> { offer_mpst!(s, { Branching0fromKtoJ::Done(s) => { s.close() }, Branching0fromKtoJ::Forward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_j(s) }, Branching0fromKtoJ::Backward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_j(s) }, }) } fn endpoint_k(s: EndpointK) -> Result<(), Box> { recurs_k(s, LOOPS) } fn recurs_k(s: EndpointK, index: i64) -> Result<(), Box> { match index { 0 => { let s = choose_mpst_k_to_all!( s, Branching0fromKtoA::Done, Branching0fromKtoB::Done, Branching0fromKtoC::Done, Branching0fromKtoD::Done, Branching0fromKtoE::Done, Branching0fromKtoF::Done, Branching0fromKtoG::Done, Branching0fromKtoH::Done, Branching0fromKtoI::Done, Branching0fromKtoJ::Done ); s.close() } i if i % 2 == 0 => { let s: EndpointForwardK = choose_mpst_k_to_all!( s, Branching0fromKtoA::Forward, Branching0fromKtoB::Forward, Branching0fromKtoC::Forward, Branching0fromKtoD::Forward, Branching0fromKtoE::Forward, Branching0fromKtoF::Forward, Branching0fromKtoG::Forward, Branching0fromKtoH::Forward, Branching0fromKtoI::Forward, Branching0fromKtoJ::Forward ); let (_, s) = s.recv()?; recurs_k(s, i - 1) } i => { let s: EndpointBackwardK = choose_mpst_k_to_all!( s, Branching0fromKtoA::Backward, Branching0fromKtoB::Backward, Branching0fromKtoC::Backward, Branching0fromKtoD::Backward, Branching0fromKtoE::Backward, Branching0fromKtoF::Backward, Branching0fromKtoG::Backward, Branching0fromKtoH::Backward, Branching0fromKtoI::Backward, Branching0fromKtoJ::Backward ); let s = s.send(())?; recurs_k(s, i - 1) } } } fn aux() { let ( thread_a, thread_b, thread_c, thread_d, thread_e, thread_f, thread_g, thread_h, thread_i, thread_j, thread_k, ) = fork_mpst( black_box(endpoint_a), black_box(endpoint_b), black_box(endpoint_c), black_box(endpoint_d), black_box(endpoint_e), black_box(endpoint_f), black_box(endpoint_g), black_box(endpoint_h), black_box(endpoint_i), black_box(endpoint_j), black_box(endpoint_k), ); thread_a.join().unwrap(); thread_b.join().unwrap(); thread_c.join().unwrap(); thread_d.join().unwrap(); thread_e.join().unwrap(); thread_f.join().unwrap(); thread_g.join().unwrap(); thread_h.join().unwrap(); thread_i.join().unwrap(); thread_j.join().unwrap(); thread_k.join().unwrap(); } ///////////////////////// static LOOPS: i64 = 100; pub fn ring(c: &mut Criterion) { c.bench_function( &format!("ring eleven baking AMPST {LOOPS}"), |b| b.iter(aux) ); } ///////////////////////// criterion_group! { name = bench; config = Criterion::default().significance_level(0.05).without_plots().sample_size(100000); targets = ring, } criterion_main! { bench }