// File: btbujiangjun[P]abcdl/include/utils/ParallelOperator.h
// Function: abcdl::utils::ParallelOperator<int>::parallel_reduce_mul2one(int*, unsigned long*, int const*, unsigned long, std::function<void (int*, int const&, unsigned long*, unsigned long)> const&) const
void parallel_reduce_mul2one(T* result_value,
                                 size_t* result_idx,
                                 const T* op1,
                         		 const size_t num_op1,
                         		 const std::function<void(T*, const T&, size_t*, const size_t)> &f) const{
        size_t block_size = get_block_size(num_op1);
        size_t num_thread = get_num_thread(num_op1, block_size);
        std::vector<std::thread> threads(num_thread);
		T* data = new T[num_thread];
		size_t* indices = new size_t[num_thread];

        for(size_t i = 0; i != num_thread; i++){
            threads[i] = std::thread(
                [&op1, &result_value, &result_idx, &data, &indices, i, &f](size_t start_idx, size_t end_idx){
					for(size_t ti = start_idx; ti != end_idx; ti++){
            			if(ti == start_idx){
							data[i] = op1[ti];
                            indices[i] = ti;
						}else{
    						f(&data[i], op1[ti], &indices[i], ti);
                        }
                    }
					f(result_value, data[i], result_idx, indices[i]);
                }, i * block_size, std::min(num_op1, (i + 1) * block_size)
            );
        }

        for(auto& thread : threads){
            thread.join();
        }
		delete[] data;
        delete[] indices;
    }

// Assembly:
subq $0x138, %rsp            # imm = 0x138
movq %rdi, 0x130(%rsp)
movq %rsi, 0x128(%rsp)
movq %rdx, 0x120(%rsp)
movq %rcx, 0x118(%rsp)
movq %r8, 0x110(%rsp)
movq %r9, 0x108(%rsp)
movq 0x130(%rsp), %rdi
movq %rdi, 0x28(%rsp)
movq 0x110(%rsp), %rsi
callq 0xa8e0
movq 0x28(%rsp), %rdi
movq %rax, 0x100(%rsp)
movq 0x110(%rsp), %rsi
movq 0x100(%rsp), %rdx
callq 0xa970
movq %rax, 0xf8(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0xdf(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0xa9f0
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
leaq 0xe0(%rsp), %rdi
callq 0xaa00
jmp 0xc8c3
leaq 0xdf(%rsp), %rdi
callq 0xaa80
movq 0xf8(%rsp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x9030
movq %rax, 0x20(%rsp)
jmp 0xc8fa
movq 0x20(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq 0xf8(%rsp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x9030
movq %rax, 0x18(%rsp)
jmp 0xc931
movq 0x18(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq $0x0, 0xb0(%rsp)
movq 0xb0(%rsp), %rax
cmpq 0xf8(%rsp), %rax
je 0xcacd
leaq 0x118(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x128(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x120(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0xc0(%rsp), %rax
movq %rax, 0x88(%rsp)
leaq 0xb8(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x98(%rsp)
movq 0x108(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0xb0(%rsp), %rax
movq 0x100(%rsp), %rcx
imulq %rcx, %rax
movq %rax, 0x68(%rsp)
movq 0xb0(%rsp), %rax
incq %rax
movq 0x100(%rsp), %rcx
imulq %rcx, %rax
movq %rax, 0x60(%rsp)
leaq 0x110(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0xaa90
movq %rax, 0x10(%rsp)
jmp 0xca18
movq 0x10(%rsp), %rcx
leaq 0xa8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0x68(%rsp), %rdx
callq 0xcb90
jmp 0xca36
movq 0xb0(%rsp), %rsi
leaq 0xe0(%rsp), %rdi
callq 0xaba0
movq %rax, %rdi
leaq 0xa8(%rsp), %rsi
callq 0xabc0
leaq 0xa8(%rsp), %rdi
callq 0xac00
movq 0xb0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xb0(%rsp)
jmp 0xc94a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd0(%rsp)
movl %eax, 0xcc(%rsp)
leaq 0xdf(%rsp), %rdi
callq 0xaa80
jmp 0xcb83
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd0(%rsp)
movl %eax, 0xcc(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0xacf0
jmp 0xcb83
leaq 0xe0(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x58(%rsp), %rdi
callq 0xac20
movq %rax, 0x50(%rsp)
movq 0x58(%rsp), %rdi
callq 0xac50
movq %rax, 0x48(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0xac80
testb $0x1, %al
jne 0xcb0d
jmp 0xcb36
leaq 0x50(%rsp), %rdi
callq 0xacc0
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rdi
callq 0x96c0
jmp 0xcb28
jmp 0xcb2a
leaq 0x50(%rsp), %rdi
callq 0xacd0
jmp 0xcaf8
movq 0xc0(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0xcb53
movq 0x8(%rsp), %rdi
callq 0x9540
movq 0xb8(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0xcb6e
movq (%rsp), %rdi
callq 0x9540
leaq 0xe0(%rsp), %rdi
callq 0xacf0
addq $0x138, %rsp            # imm = 0x138
retq
movq 0xd0(%rsp), %rdi
callq 0x9700