// File: /workspace/github_c_makefile_star2_O0/USArmyResearchLab[P]ARL_OpenSHMEM/test/reduce.c
// Function: main
int main (void)
{
	int i, nelement;
	static unsigned int t, tsum;
	static long pSync[SHMEM_REDUCE_SYNC_SIZE];
	for (i = 0; i < SHMEM_REDUCE_SYNC_SIZE; i++) {
		pSync[i] = SHMEM_SYNC_VALUE;
	}

	shmem_init();
	int me = shmem_my_pe();
	int npes = shmem_n_pes();

	int pwrk_elems = NELEMENT/2 + 1;
	pwrk_elems = (pwrk_elems > SHMEM_REDUCE_MIN_WRKDATA_SIZE) ? 
		pwrk_elems : SHMEM_REDUCE_MIN_WRKDATA_SIZE;

	int* source = (int*)shmem_malloc(NELEMENT * sizeof (int) * 1000);
	int* target = (int*)shmem_malloc(NELEMENT * sizeof (int) * 1000);
	int* pwrk   = (int*)shmem_malloc(pwrk_elems * sizeof(int) * 1000);
	for (i = 0; i < NELEMENT; i++) {
		source[i] = i;
	}

	if (me == 0) {
		printf("# SHMEM Reduction times for NPES = %d\n" \
			"# Nelements \tLatency (nanoseconds)\n", npes);
	}

	for (nelement = 1; nelement <= NELEMENT; nelement <<= 1) {

		// reset values for each iteration
		for (i = 0; i < NELEMENT; i++) {
			target[i] = -90;
		}
		shmem_barrier_all();
		ctimer_start();

		t = ctimer();
		for (i = 0; i < NLOOP; i++) {
			shmem_int_sum_to_all(target,source,nelement,0,0,npes, pwrk, pSync);
		}
		t -= ctimer();

		shmem_int_sum_to_all(&tsum, &t, 1, 0, 0, npes, pwrk, pSync);

		if (me == 0) {
			unsigned int nsec = ctimer_nsec(tsum / (npes * NLOOP));
			printf("%5d %7u\n", nelement, nsec);
		}

		int err = 0;
		for (i = 0; i < nelement; i++) {
			if (target[i] != i*npes) {
				printf("%d# error %d %d %d\n",me,i,target[i],i*npes);
				err++;
			}
		}
		if (err) printf("# %d: ERRORS %d\n", me, err);
	}

	shmem_free(target);
	shmem_free(source);

	shmem_finalize();

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movslq -0x38(%rbp), %rax
cmpq $0xa, %rax
jae 0x1381
movslq -0x38(%rbp), %rcx
leaq 0x5df2(%rip), %rax      # 0x7160
movq $0x0, (%rax,%rcx,8)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1359
callq 0x1780
leaq 0x5da3(%rip), %rax      # 0x7130
movl (%rax), %eax
movl %eax, -0x40(%rbp)
leaq 0x5d9b(%rip), %rax      # 0x7134
movl (%rax), %eax
movl %eax, -0x44(%rbp)
movl $0x401, -0x48(%rbp)     # imm = 0x401
movslq -0x48(%rbp), %rax
cmpq $0x8, %rax
jbe 0x13b9
movslq -0x48(%rbp), %rax
movq %rax, -0x70(%rbp)
jmp 0x13c4
movl $0x8, %eax
movq %rax, -0x70(%rbp)
jmp 0x13c4
movq -0x70(%rbp), %rax
movl %eax, -0x48(%rbp)
movl $0x7d0000, %edi         # imm = 0x7D0000
callq 0x2120
movq %rax, -0x50(%rbp)
movl $0x7d0000, %edi         # imm = 0x7D0000
callq 0x2120
movq %rax, -0x58(%rbp)
movslq -0x48(%rbp), %rax
shlq $0x2, %rax
imulq $0x3e8, %rax, %rdi      # imm = 0x3E8
callq 0x2120
movq %rax, -0x60(%rbp)
movl $0x0, -0x38(%rbp)
cmpl $0x800, -0x38(%rbp)     # imm = 0x800
jge 0x1428
movl -0x38(%rbp), %edx
movq -0x50(%rbp), %rax
movslq -0x38(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1406
cmpl $0x0, -0x40(%rbp)
jne 0x143f
movl -0x44(%rbp), %esi
leaq 0x3be8(%rip), %rdi      # 0x5020
movb $0x0, %al
callq 0x10e0
movl $0x1, -0x3c(%rbp)
cmpl $0x800, -0x3c(%rbp)     # imm = 0x800
jg 0x16e7
movl $0x0, -0x38(%rbp)
cmpl $0x800, -0x38(%rbp)     # imm = 0x800
jge 0x147d
movq -0x58(%rbp), %rax
movslq -0x38(%rbp), %rcx
movl $0xffffffa6, (%rax,%rcx,4) # imm = 0xFFFFFFA6
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x145a
callq 0x1740
callq 0x1710
xorl %eax, %eax
movl %eax, %esi
leaq -0x18(%rbp), %rdi
callq 0x1110
movq 0x5d15(%rip), %rdx      # 0x71b0
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
subq %rdx, %rcx
cvtsi2sd %rcx, %xmm0
movq 0x5d06(%rip), %rcx      # 0x71b8
subq %rcx, %rax
cvtsi2sd %rax, %xmm1
movsd 0x3b46(%rip), %xmm2     # 0x5008
mulsd %xmm2, %xmm1
movsd 0x3b42(%rip), %xmm2     # 0x5010
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x3b2b(%rip), %xmm1     # 0x5018
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x8(%rbp)
movq $-0x1, %rax
subq -0x8(%rbp), %rax
movl %eax, 0x5c3f(%rip)      # 0x7150
movl $0x0, -0x38(%rbp)
cmpl $0xa, -0x38(%rbp)
jge 0x1557
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
movl -0x3c(%rbp), %edx
movl -0x44(%rbp), %r9d
movq -0x60(%rbp), %r10
xorl %r8d, %r8d
leaq 0x5c25(%rip), %rax      # 0x7160
movl %r8d, %ecx
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x4320
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1518
xorl %eax, %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0x1110
movq 0x5c45(%rip), %rdx      # 0x71b0
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rax
subq %rdx, %rcx
cvtsi2sd %rcx, %xmm0
movq 0x5c36(%rip), %rcx      # 0x71b8
subq %rcx, %rax
cvtsi2sd %rax, %xmm1
movsd 0x3a76(%rip), %xmm2     # 0x5008
mulsd %xmm2, %xmm1
movsd 0x3a72(%rip), %xmm2     # 0x5010
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x3a5b(%rip), %xmm1     # 0x5018
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x20(%rbp)
movq $-0x1, %rcx
subq -0x20(%rbp), %rcx
movl 0x5b6f(%rip), %eax      # 0x7150
subq %rcx, %rax
movl %eax, 0x5b66(%rip)      # 0x7150
movl -0x44(%rbp), %r9d
movq -0x60(%rbp), %r10
leaq 0x5b5b(%rip), %rdi      # 0x7154
leaq 0x5b50(%rip), %rsi      # 0x7150
movl $0x1, %edx
xorl %r8d, %r8d
leaq 0x5b51(%rip), %rax      # 0x7160
movl %r8d, %ecx
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x4320
cmpl $0x0, -0x40(%rbp)
jne 0x1654
movl 0x5b28(%rip), %eax      # 0x7154
imull $0xa, -0x44(%rbp), %ecx
xorl %edx, %edx
divl %ecx
movl %eax, %eax
movl %eax, %edi
callq 0x1730
movl %eax, -0x64(%rbp)
movl -0x3c(%rbp), %esi
movl -0x64(%rbp), %edx
leaq 0x3a1d(%rip), %rdi      # 0x506a
movb $0x0, %al
callq 0x10e0
movl $0x0, -0x68(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x16be
movq -0x58(%rbp), %rax
movslq -0x38(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl -0x38(%rbp), %ecx
imull -0x44(%rbp), %ecx
cmpl %ecx, %eax
je 0x16b1
movl -0x40(%rbp), %esi
movl -0x38(%rbp), %edx
movq -0x58(%rbp), %rax
movslq -0x38(%rbp), %rcx
movl (%rax,%rcx,4), %ecx
movl -0x38(%rbp), %r8d
imull -0x44(%rbp), %r8d
leaq 0x39d2(%rip), %rdi      # 0x5073
movb $0x0, %al
callq 0x10e0
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x16b3
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1662
cmpl $0x0, -0x68(%rbp)
je 0x16d8
movl -0x40(%rbp), %esi
movl -0x68(%rbp), %edx
leaq 0x39b6(%rip), %rdi      # 0x5087
movb $0x0, %al
callq 0x10e0
jmp 0x16da
movl -0x3c(%rbp), %eax
shll %eax
movl %eax, -0x3c(%rbp)
jmp 0x1446
movq -0x58(%rbp), %rdi
callq 0x1750
movq -0x50(%rbp), %rdi
callq 0x1750
callq 0x2110
xorl %eax, %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)