#include <time.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <cuda_runtime.h>


void CPUEuler(float t_0, float y_0, float delta_t){
	int n=10/delta_t +1;
	float *y = (float*) malloc(sizeof(float)*n);
	y[0]=y_0;
	for (int i=0;i<n-1;i++){
		y[i+1]=y[i]+delta_t*(9*powf(i*delta_t,2)-4*(i*delta_t)+5);
	}
	free(y);
	//return y;
}

int main(int argc, char const *argv[]) {
	
	printf("seccion 1.a\n");
	clock_t start, end;
	for(int i=1;i<7;i++) {
		float delta_t=powf(10,-i);
		start=clock();
		CPUEuler(0,4,delta_t);
		end=clock();
		double cpu_time_used = ((double) (end - start)) * 1000 / CLOCKS_PER_SEC;
		printf("%f\n",cpu_time_used);
		
	}

	return 0;
}
	.file	"tmpxft_00349232_00000000-6_pregunta1a_mejorada.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2031:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2031:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z8CPUEulerfff
	.type	_Z8CPUEulerfff, @function
_Z8CPUEulerfff:
.LFB2027:
	.cfi_startproc
	endbr64
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z8CPUEulerfff, .-_Z8CPUEulerfff
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"seccion 1.a\n"
.LC4:
	.string	"%f\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	orl	$-1, %ebx
	pushq	%rcx
	.cfi_def_cfa_offset 32
	call	__printf_chk@PLT
.L4:
	cvtsi2ssl	%ebx, %xmm1
	movss	.LC1(%rip), %xmm0
	decl	%ebx
	call	powf@PLT
	call	clock@PLT
	movq	%rax, %rbp
	call	clock@PLT
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	subq	%rbp, %rax
	cvtsi2sdq	%rax, %xmm0
	mulsd	.LC2(%rip), %xmm0
	movb	$1, %al
	divsd	.LC3(%rip), %xmm0
	call	__printf_chk@PLT
	cmpl	$-7, %ebx
	jne	.L4
	popq	%rdx
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2054:
	.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
.LFE2054:
	.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
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC1:
	.long	1092616192
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC2:
	.long	0
	.long	1083129856
	.align 8
.LC3:
	.long	0
	.long	1093567616
	.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:

#include <time.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <hip/hip_runtime.h>


void CPUEuler(float t_0, float y_0, float delta_t){
	int n=10/delta_t +1;
	float *y = (float*) malloc(sizeof(float)*n);
	y[0]=y_0;
	for (int i=0;i<n-1;i++){
		y[i+1]=y[i]+delta_t*(9*powf(i*delta_t,2)-4*(i*delta_t)+5);
	}
	free(y);
	//return y;
}

int main(int argc, char const *argv[]) {
	
	printf("seccion 1.a\n");
	clock_t start, end;
	for(int i=1;i<7;i++) {
		float delta_t=powf(10,-i);
		start=clock();
		CPUEuler(0,4,delta_t);
		end=clock();
		double cpu_time_used = ((double) (end - start)) * 1000 / CLOCKS_PER_SEC;
		printf("%f\n",cpu_time_used);
		
	}

	return 0;
}
	.text
	.file	"pregunta1a_mejorada.hip"
	.globl	_Z8CPUEulerfff                  # -- Begin function _Z8CPUEulerfff
	.type	_Z8CPUEulerfff,@function
_Z8CPUEulerfff:                         # @_Z8CPUEulerfff
	.cfi_startproc
# %bb.0:                                # %._crit_edge
	retq
.Lfunc_end0:
	.size	_Z8CPUEulerfff, .Lfunc_end0-_Z8CPUEulerfff
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI1_0:
	.long	0x41200000                      # float 10
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI1_1:
	.quad	0x408f400000000000              # double 1000
.LCPI1_2:
	.quad	0x412e848000000000              # double 1.0E+6
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %rbp, -16
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$-1, %ebp
.LBB1_1:                                # %_Z8CPUEulerfff.exit
                                        # =>This Inner Loop Header: Depth=1
	xorps	%xmm1, %xmm1
	cvtsi2ss	%ebp, %xmm1
	movss	.LCPI1_0(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	callq	powf
	callq	clock
	movq	%rax, %rbx
	callq	clock
	subq	%rbx, %rax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	mulsd	.LCPI1_1(%rip), %xmm0
	divsd	.LCPI1_2(%rip), %xmm0
	movl	$.L.str.1, %edi
	movb	$1, %al
	callq	printf
	decl	%ebp
	cmpl	$-7, %ebp
	jne	.LBB1_1
# %bb.2:
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"%f\n"
	.size	.L.str.1, 4

	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"seccion 1.a"
	.size	.Lstr, 12

	.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
