// File: /workspace/github_c_makefile_star2_O2/USArmyResearchLab[P]ARL_OpenSHMEM/test/put64.c
// Function: main
int main (void)
{
	int i, nelement;
	static unsigned int t, tsum;
	static int pWrk[SHMEM_REDUCE_MIN_WRKDATA_SIZE];
	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 nxtpe = me + 1;
	if (nxtpe >= npes) nxtpe -= npes;

	long long* source 
		= (long long*)shmem_align(8192, NELEMENT * sizeof(long long));
	long long* target 
		= (long long*)shmem_align(8192, NELEMENT * sizeof(long long));

	for (i = 0; i < NELEMENT; i++) {
		source[i] = i + 1;
	}

	if (me == 0) {
		printf("# SHMEM Put64 times for variable message size\n" \
			"# Bytes\tLatency (nanoseconds)\n");
	}

	/* For int put we take average of all the times realized by a pair of PEs,
	thus reducing effects of physical location of PEs */
	for (nelement = 1; nelement <= NELEMENT; nelement <<= 1) {

		shmem_barrier_all();
		// 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_put64(target, source, nelement, nxtpe);
		}

		t -= ctimer();

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

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

		shmem_barrier_all();

		int err = 0;

		for (i = 0; i < nelement; i++) if (target[i] != source[i]) err++;

		for (i = nelement; i < NELEMENT; i++) if (target[i] != -90) err++;

		if (err) { 
			printf("# %d: ERROR: %d incorrect value(s) copied\n",
				me, err);
			fflush(stdout);
//		} else {
//			printf("# %d: NO incorrect value(s) copied\n", me);
//			fflush(stdout);
		}
		shmem_barrier_all();
		fflush(stdout);
	}

	shmem_free(target);
	shmem_free(source);

	shmem_finalize();

	return 0;
}

// Assembly:
xorl %eax, %eax
leaq 0x5e1b(%rip), %rcx      # 0x71a0
cmpq $0x50, %rax
je 0x1396
andq $0x0, (%rax,%rcx)
addq $0x8, %rax
jmp 0x1385
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
callq 0x16b8
leaq 0x5d9d(%rip), %rax      # 0x7150
movl (%rax), %ecx
leaq 0x5d98(%rip), %rax      # 0x7154
movl (%rax), %eax
movq %rcx, -0x38(%rbp)
leal 0x1(%rcx), %r15d
xorl %ebx, %ebx
cmpl %eax, %r15d
movl %eax, -0x2c(%rbp)
cmovgel %eax, %ebx
movl $0x2000, %edi           # imm = 0x2000
movl $0x2000, %esi           # imm = 0x2000
callq 0x1660
movq %rax, %r12
movl $0x2000, %edi           # imm = 0x2000
movl $0x2000, %esi           # imm = 0x2000
callq 0x1660
movq %rax, %r13
pushq $0x1
popq %rax
cmpq $0x401, %rax            # imm = 0x401
je 0x140a
movq %rax, -0x8(%r12,%rax,8)
incq %rax
jmp 0x13f8
cmpl $0x0, -0x38(%rbp)
jne 0x141c
leaq 0x2c3d(%rip), %rdi      # 0x4054
callq 0x1080
subl %ebx, %r15d
imull $0xa, -0x2c(%rbp), %eax
movl %eax, -0x3c(%rbp)
pushq $0x1
popq %rax
leaq -0x58(%rbp), %rbx
movl %eax, %r14d
cmpl $0x400, %r14d           # imm = 0x400
ja 0x1639
callq 0x1694
xorl %eax, %eax
cmpq $0x400, %rax            # imm = 0x400
je 0x145a
movq $-0x5a, (%r13,%rax,8)
incq %rax
jmp 0x1444
callq 0x1694
leaq 0x5d8a(%rip), %rdi      # 0x71f0
xorl %esi, %esi
callq 0x1130
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1130
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rcx
subq 0x5d6a(%rip), %rax      # 0x71f0
cvtsi2sd %rax, %xmm0
subq 0x5d66(%rip), %rcx      # 0x71f8
cvtsi2sd %rcx, %xmm1
mulsd 0x2b69(%rip), %xmm1     # 0x4008
mulsd 0x2b69(%rip), %xmm0     # 0x4010
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x2b59(%rip), %xmm0     # 0x4018
cvttsd2si %xmm0, %rdx
andl %ecx, %edx
orl %edx, %eax
notl %eax
movl %eax, 0x5ca0(%rip)      # 0x7170
movq %r14, -0x48(%rbp)
movl %r14d, %r14d
pushq $0xa
popq %rbx
subl $0x1, %ebx
jb 0x14f2
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x30d0
jmp 0x14da
leaq -0x58(%rbp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1130
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rcx
subq 0x5ce1(%rip), %rax      # 0x71f0
cvtsi2sd %rax, %xmm0
subq 0x5cdd(%rip), %rcx      # 0x71f8
cvtsi2sd %rcx, %xmm1
mulsd 0x2ae0(%rip), %xmm1     # 0x4008
mulsd 0x2ae0(%rip), %xmm0     # 0x4010
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x2ad0(%rip), %xmm0     # 0x4018
cvttsd2si %xmm0, %rdx
andl %ecx, %edx
orl %edx, %eax
movl 0x5c19(%rip), %ecx      # 0x7170
addl %ecx, %eax
incl %eax
movl %eax, 0x5c0f(%rip)      # 0x7170
leaq 0x5c0c(%rip), %rdi      # 0x7174
leaq 0x5c01(%rip), %rsi      # 0x7170
pushq $0x1
popq %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
movl -0x2c(%rbp), %r9d
leaq 0x5c1e(%rip), %rax      # 0x71a0
pushq %rax
leaq 0x5bf6(%rip), %rax      # 0x7180
pushq %rax
callq 0x2f24
popq %rax
popq %rcx
cmpl $0x0, -0x38(%rbp)
jne 0x15be
movq -0x48(%rbp), %rax
leal (,%rax,8), %esi
movl 0x5bcb(%rip), %eax      # 0x7174
xorl %edx, %edx
divl -0x3c(%rbp)
leaq 0x2a6b(%rip), %rdi      # 0x4020
movl %eax, %edx
xorl %eax, %eax
callq 0x1100
callq 0x1694
xorl %eax, %eax
xorl %edx, %edx
cmpq %rax, %r14
je 0x15f2
movq (%r13,%rax,8), %rcx
xorl %esi, %esi
cmpq (%r12,%rax,8), %rcx
setne %sil
addl %esi, %edx
incq %rax
jmp 0x15c7
xorl %eax, %eax
cmpq $-0x5a, (%r13,%r14,8)
setne %al
addl %eax, %edx
incq %r14
cmpq $0x3ff, %r14            # imm = 0x3FF
jbe 0x15e2
testl %edx, %edx
movq 0x59d4(%rip), %r14      # 0x6fd8
je 0x1620
leaq 0x2a1c(%rip), %rdi      # 0x4029
movq -0x38(%rbp), %rsi
xorl %eax, %eax
callq 0x1100
movq (%r14), %rdi
callq 0x11d0
callq 0x1694
movq (%r14), %rdi
callq 0x11d0
movq -0x48(%rbp), %r14
addl %r14d, %r14d
jmp 0x1430
movq %r13, %rdi
callq 0x16a0
movq %r12, %rdi
callq 0x16a0
callq 0x1cb1
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop