// File: /workspace/github_cpp_makefile_star2_O2/ArashPartow[P]exprtk-extras/exprtk_vector_benchmark_multithreaded.cpp
// Function: void run_threaded_benchmark<double>(unsigned long const&, unsigned long const&)
void run_threaded_benchmark(const std::size_t& vec_size, const std::size_t& thread_count)
{
   std::vector<std::thread> thread_list;

   exprtk::timer timer;

   timer.start();

   for (std::size_t i = 0; i < thread_count; ++i)
   {
      thread_list.emplace_back(
         std::thread([vec_size]()
                     {
                        for (std::size_t e = 0; e < global_expression_list_size; ++e)
                        {
                           run_expression_benchmark<T>(
                              vec_size,
                              global_expression_list[e].expression,
                              global_expression_list[e].cost);
                        }
                     }));
   }

   for (auto& t : thread_list)
   {
      t.join();
   }

   timer.stop();

   unsigned long long total_flops = 0;

   for (std::size_t i = 0; i < global_expression_list_size; ++i)
   {
      total_flops += global_expression_list[i].cost;
   }

   total_flops = (total_flops * rounds * vec_size * thread_count);

   printf("Total Time:%10.7f FLOP: %llu Perf: %7.4fGFLOPS\n",
          timer.time(),
          total_flops,
          total_flops / (1e9 * timer.time()));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %rbx
movq %rdi, %r14
xorpd %xmm0, %xmm0
leaq 0x20(%rsp), %r15
movapd %xmm0, (%r15)
andq $0x0, 0x10(%r15)
leaq 0x40(%rsp), %rdi
movb $0x0, (%rdi)
movupd %xmm0, 0x8(%rdi)
movupd %xmm0, 0x18(%rdi)
callq 0x1138d2
xorl %ebp, %ebp
leaq 0x18(%rsp), %r12
leaq 0x10(%rsp), %r13
cmpq (%rbx), %rbp
jae 0x11373b
movq (%r14), %rax
movq %rax, 0x10(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x11391e
movq %r15, %rdi
movq %r12, %rsi
callq 0x1138e0
movq %r12, %rdi
callq 0x113986
incq %rbp
jmp 0x11370b
movq 0x20(%rsp), %r15
movq 0x28(%rsp), %r12
cmpq %r12, %r15
je 0x113758
movq %r15, %rdi
callq 0x110150
addq $0x8, %r15
jmp 0x113745
leaq 0x40(%rsp), %rdi
callq 0x113994
xorl %eax, %eax
leaq 0x2be6c5(%rip), %rcx    # 0x3d1e30
xorl %r15d, %r15d
cmpq $0x640, %rax            # imm = 0x640
je 0x113780
addq (%rax,%rcx), %r15
addq $0x28, %rax
jmp 0x11376e
movq (%r14), %r14
movq (%rbx), %rbx
leaq 0x40(%rsp), %rdi
callq 0x1139a8
movsd %xmm0, 0x8(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x1139a8
imulq %r14, %r15
imulq %rbx, %r15
imulq $0x7d0, %r15, %rsi      # imm = 0x7D0
movq %rsi, %xmm2
punpckldq 0x12a854(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x12a85c(%rip), %xmm2   # 0x23e020
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
mulsd 0x12a898(%rip), %xmm0   # 0x23e070
divsd %xmm0, %xmm1
leaq 0x12fc2d(%rip), %rdi    # 0x243410
movsd 0x8(%rsp), %xmm0
movb $0x2, %al
callq 0x110060
leaq 0x20(%rsp), %rdi
callq 0x1139da
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x11381c
jmp 0x11381c
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x113986
jmp 0x11381f
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x1139da
movq %rbx, %rdi
callq 0x110350