////////////////////////////////////////////////////////////////////////////
// Calculate scalar products of VectorN vectors of ElementN elements on CPU.
// Straight accumulation in double precision.
////////////////////////////////////////////////////////////////////////////
 #include <iostream>

//extern "C"
void Kernel_2_Max_CPU_MPI(int *Max_All_CPU, int *A_Location_All_CPU, int *B_Location_All_CPU, 
						  int *Max_K1     , int *A_Location_K1     , int *B_Location_K1,
						  int K1_Max_Report, int Number, int Kerene2Max)
{
	for (int k=0; k<K1_Max_Report; k++)
	{
		int check=0;
		
		do
		{
			check=0;
			int Max_Val_MPI = 0;
			int Max_Loc_MPI = 0;
			for (int i=0; i<Number; i++)
			{
				if (Max_Val_MPI<Max_All_CPU[i])
				{
					Max_Val_MPI = Max_All_CPU[i];
					Max_Loc_MPI = i;
				}
			}
		//	printf("  --- %i  %i    %i \n", k, Max_Val_MPI, Max_Loc_MPI);
			if (Max_Val_MPI==0)
			{
				check=1;
				k=K1_Max_Report+10;
			}
//			printf("-----  Ata ------    %i       %i       %i    %i     %i  \n", k, Max_Val_MPI,Max_Loc_MPI, K1_Max_Report, Number);
			if (check!=0){
			for (int i=0; i<k; i++)
			{
				if ((A_Location_K1[i*Kerene2Max]==A_Location_All_CPU[Max_Loc_MPI*Kerene2Max])  &&  (B_Location_K1 [i*Kerene2Max]==B_Location_All_CPU[Max_Loc_MPI*Kerene2Max]))
				{
				
					check=1;
					Max_All_CPU[Max_Loc_MPI]=0;
					
	//				printf("-----     %i    %i   %i    %i   %i    %i \n", k, i, A_Location_K1[i],A_Location_All_CPU[Max_Loc_MPI], Max_K1[i],Max_Val_MPI);
					i=k+2*Number;
				}
			}
			}
			

			if (check==0)
			{
				Max_K1[k]        = Max_Val_MPI;
		//		printf("------  %i\n", Max_Val_MPI);
				for (int j=0; j<Kerene2Max; j++)
				{
					A_Location_K1 [k*Kerene2Max+j]= A_Location_All_CPU[Max_Loc_MPI*Kerene2Max+j];
					B_Location_K1 [k*Kerene2Max+j]= B_Location_All_CPU[Max_Loc_MPI*Kerene2Max+j];
				}
				Max_All_CPU[Max_Loc_MPI]=0;
				Max_Val_MPI = 0;
			}
		}while (check!=0);
	}
}

	.file	"tmpxft_00380897_00000000-6_Kernel_2_Max_CPU_MPI.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3638:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3638:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z20Kernel_2_Max_CPU_MPIPiS_S_S_S_S_iii
	.type	_Z20Kernel_2_Max_CPU_MPIPiS_S_S_S_S_iii, @function
_Z20Kernel_2_Max_CPU_MPIPiS_S_S_S_S_iii:
.LFB3635:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rsi, %r10
	movq	%rdx, %r11
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rcx, %r12
	xorl	%ecx, %ecx
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	64(%rsp), %eax
	movl	56(%rsp), %r13d
	movl	72(%rsp), %ebx
	leal	(%rax,%rax), %r14d
.L3:
	cmpl	%r13d, %ecx
	jge	.L17
.L12:
	xorl	%eax, %eax
	xorl	%esi, %esi
	xorl	%edx, %edx
.L4:
	cmpl	%eax, 64(%rsp)
	jle	.L18
	movl	(%rdi,%rax,4), %ebp
	cmpl	%edx, %ebp
	jle	.L5
	movslq	%eax, %rsi
	movl	%ebp, %edx
.L5:
	incq	%rax
	jmp	.L4
.L18:
	movl	%esi, %eax
	imull	%ebx, %eax
	testl	%edx, %edx
	cltq
	je	.L7
	movslq	%ecx, %rbp
	salq	$2, %rax
	movl	%edx, (%r12,%rbp,4)
	movl	%ecx, %edx
	xorl	%ebp, %ebp
	imull	%ebx, %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	jmp	.L8
.L7:
	salq	$2, %rax
	leal	10(%r13), %ecx
	leaq	(%r10,%rax), %r15
	addq	%r11, %rax
	movq	%rax, -8(%rsp)
.L9:
	cmpl	%ecx, %edx
	jge	.L12
	movl	%edx, %ebp
	movl	(%r15), %eax
	imull	%ebx, %ebp
	movslq	%ebp, %rbp
	cmpl	%eax, (%r8,%rbp,4)
	jne	.L10
	movq	-8(%rsp), %rax
	movl	(%rax), %eax
	cmpl	%eax, (%r9,%rbp,4)
	jne	.L10
	movslq	%esi, %rdx
	xorl	%ebp, %ebp
	movl	%ebp, (%rdi,%rdx,4)
	leal	(%r14,%rcx), %edx
.L10:
	incl	%edx
	jmp	.L9
.L8:
	cmpl	%ebx, %ebp
	jge	.L19
	movl	(%r10,%rax), %r15d
	incl	%ebp
	movl	%r15d, (%r8,%rdx)
	movl	(%r11,%rax), %r15d
	addq	$4, %rax
	movl	%r15d, (%r9,%rdx)
	addq	$4, %rdx
	jmp	.L8
.L19:
	xorl	%eax, %eax
	incl	%ecx
	movl	%eax, (%rdi,%rsi,4)
	jmp	.L3
.L17:
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3635:
	.size	_Z20Kernel_2_Max_CPU_MPIPiS_S_S_S_S_iii, .-_Z20Kernel_2_Max_CPU_MPIPiS_S_S_S_S_iii
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3661:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3661:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

////////////////////////////////////////////////////////////////////////////
// Calculate scalar products of VectorN vectors of ElementN elements on CPU.
// Straight accumulation in double precision.
////////////////////////////////////////////////////////////////////////////
 
#include <hip/hip_runtime.h>
#include <iostream>

//extern "C"
void Kernel_2_Max_CPU_MPI(int *Max_All_CPU, int *A_Location_All_CPU, int *B_Location_All_CPU, 
						  int *Max_K1     , int *A_Location_K1     , int *B_Location_K1,
						  int K1_Max_Report, int Number, int Kerene2Max)
{
	for (int k=0; k<K1_Max_Report; k++)
	{
		int check=0;
		
		do
		{
			check=0;
			int Max_Val_MPI = 0;
			int Max_Loc_MPI = 0;
			for (int i=0; i<Number; i++)
			{
				if (Max_Val_MPI<Max_All_CPU[i])
				{
					Max_Val_MPI = Max_All_CPU[i];
					Max_Loc_MPI = i;
				}
			}
		//	printf("  --- %i  %i    %i \n", k, Max_Val_MPI, Max_Loc_MPI);
			if (Max_Val_MPI==0)
			{
				check=1;
				k=K1_Max_Report+10;
			}
//			printf("-----  Ata ------    %i       %i       %i    %i     %i  \n", k, Max_Val_MPI,Max_Loc_MPI, K1_Max_Report, Number);
			if (check!=0){
			for (int i=0; i<k; i++)
			{
				if ((A_Location_K1[i*Kerene2Max]==A_Location_All_CPU[Max_Loc_MPI*Kerene2Max])  &&  (B_Location_K1 [i*Kerene2Max]==B_Location_All_CPU[Max_Loc_MPI*Kerene2Max]))
				{
				
					check=1;
					Max_All_CPU[Max_Loc_MPI]=0;
					
	//				printf("-----     %i    %i   %i    %i   %i    %i \n", k, i, A_Location_K1[i],A_Location_All_CPU[Max_Loc_MPI], Max_K1[i],Max_Val_MPI);
					i=k+2*Number;
				}
			}
			}
			

			if (check==0)
			{
				Max_K1[k]        = Max_Val_MPI;
		//		printf("------  %i\n", Max_Val_MPI);
				for (int j=0; j<Kerene2Max; j++)
				{
					A_Location_K1 [k*Kerene2Max+j]= A_Location_All_CPU[Max_Loc_MPI*Kerene2Max+j];
					B_Location_K1 [k*Kerene2Max+j]= B_Location_All_CPU[Max_Loc_MPI*Kerene2Max+j];
				}
				Max_All_CPU[Max_Loc_MPI]=0;
				Max_Val_MPI = 0;
			}
		}while (check!=0);
	}
}

	.text
	.file	"Kernel_2_Max_CPU_MPI.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z20Kernel_2_Max_CPU_MPIPiS_S_S_S_S_iii # -- Begin function _Z20Kernel_2_Max_CPU_MPIPiS_S_S_S_S_iii
	.type	_Z20Kernel_2_Max_CPU_MPIPiS_S_S_S_S_iii,@function
_Z20Kernel_2_Max_CPU_MPIPiS_S_S_S_S_iii: # @_Z20Kernel_2_Max_CPU_MPIPiS_S_S_S_S_iii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rcx, -16(%rsp)                 # 8-byte Spill
	movl	56(%rsp), %eax
	testl	%eax, %eax
	jle	.LBB0_17
# %bb.1:                                # %.critedge77.preheader.lr.ph
	movl	72(%rsp), %r10d
	movl	64(%rsp), %r15d
	movl	56(%rsp), %eax
	leal	10(%rax), %ebx
	movl	%r15d, %r14d
	leal	(%rax,%r15,2), %r11d
	addl	$10, %r11d
	movl	%r10d, %ecx
	xorl	%r12d, %r12d
	movl	%r11d, -28(%rsp)                # 4-byte Spill
	movq	%rcx, -8(%rsp)                  # 8-byte Spill
	movq	%rdx, -24(%rsp)                 # 8-byte Spill
.LBB0_2:                                # %.critedge77
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_4 Depth 2
                                        #     Child Loop BB0_15 Depth 2
                                        #     Child Loop BB0_8 Depth 2
	movl	$0, %r13d
	testl	%r15d, %r15d
	jle	.LBB0_7
# %bb.3:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB0_2 Depth=1
	xorl	%ebp, %ebp
	xorl	%r13d, %r13d
	xorl	%r11d, %r11d
.LBB0_4:                                # %.lr.ph
                                        #   Parent Loop BB0_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%r11d, %eax
	movl	(%rdi,%rbp,4), %r11d
	cmpl	%r11d, %eax
	cmovgl	%eax, %r11d
	cmovll	%ebp, %r13d
	incq	%rbp
	cmpq	%rbp, %r14
	jne	.LBB0_4
# %bb.5:                                # %._crit_edge
                                        #   in Loop: Header=BB0_2 Depth=1
	testl	%r11d, %r11d
	je	.LBB0_6
# %bb.13:                               # %.critedge
                                        #   in Loop: Header=BB0_2 Depth=1
	movq	%r12, %rdx
	movslq	%r12d, %rax
	movl	%r10d, %ebp
	movq	%rcx, %r10
	movq	-16(%rsp), %rcx                 # 8-byte Reload
	movl	%r11d, (%rcx,%rax,4)
	testl	%ebp, %ebp
	jle	.LBB0_16
# %bb.14:                               # %.lr.ph86
                                        #   in Loop: Header=BB0_2 Depth=1
	movl	%r13d, %eax
	movl	72(%rsp), %r11d
	imull	%r11d, %eax
	movl	%edx, %ecx
	imull	%r11d, %ecx
	cltq
	movslq	%ecx, %rcx
	leaq	(%r8,%rcx,4), %r11
	leaq	(%r9,%rcx,4), %rbp
	leaq	(%rsi,%rax,4), %rcx
	movq	-24(%rsp), %r15                 # 8-byte Reload
	leaq	(%r15,%rax,4), %rax
	xorl	%r12d, %r12d
.LBB0_15:                               #   Parent Loop BB0_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%rcx,%r12,4), %r15d
	movl	%r15d, (%r11,%r12,4)
	movl	(%rax,%r12,4), %r15d
	movl	%r15d, (%rbp,%r12,4)
	incq	%r12
	cmpq	%r12, %r10
	jne	.LBB0_15
.LBB0_16:                               # %.loopexit
                                        #   in Loop: Header=BB0_2 Depth=1
	movslq	%r13d, %rax
	movl	$0, (%rdi,%rax,4)
	movq	%rdx, %r12
	incl	%r12d
	movl	56(%rsp), %eax
	cmpl	%eax, %r12d
	movl	64(%rsp), %r15d
	movl	-28(%rsp), %r11d                # 4-byte Reload
	movq	%r10, %rcx
	movq	-24(%rsp), %rdx                 # 8-byte Reload
	movl	72(%rsp), %r10d
	jl	.LBB0_2
	jmp	.LBB0_17
.LBB0_6:                                #   in Loop: Header=BB0_2 Depth=1
	movl	-28(%rsp), %r11d                # 4-byte Reload
.LBB0_7:                                # %.lr.ph83
                                        #   in Loop: Header=BB0_2 Depth=1
	movslq	%r13d, %r12
	imull	%r10d, %r13d
	movslq	%r13d, %r13
	xorl	%ebp, %ebp
.LBB0_8:                                #   Parent Loop BB0_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%ebp, %eax
	imull	%r10d, %eax
	cltq
	movl	(%r8,%rax,4), %ecx
	cmpl	(%rsi,%r13,4), %ecx
	jne	.LBB0_11
# %bb.9:                                #   in Loop: Header=BB0_8 Depth=2
	movl	(%r9,%rax,4), %eax
	cmpl	(%rdx,%r13,4), %eax
	jne	.LBB0_11
# %bb.10:                               #   in Loop: Header=BB0_8 Depth=2
	movl	$0, (%rdi,%r12,4)
	movl	%r11d, %ebp
.LBB0_11:                               #   in Loop: Header=BB0_8 Depth=2
	incl	%ebp
	cmpl	%ebx, %ebp
	jl	.LBB0_8
# %bb.12:                               #   in Loop: Header=BB0_2 Depth=1
	movl	%ebx, %r12d
	movq	-8(%rsp), %rcx                  # 8-byte Reload
	jmp	.LBB0_2
.LBB0_17:                               # %._crit_edge89
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z20Kernel_2_Max_CPU_MPIPiS_S_S_S_S_iii, .Lfunc_end0-_Z20Kernel_2_Max_CPU_MPIPiS_S_S_S_S_iii
	.cfi_endproc
                                        # -- End function
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_

	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
