Last active
February 23, 2021 16:36
-
-
Save IonianIronist/f38640cdf0f3b96fa958ea20d8473177 to your computer and use it in GitHub Desktop.
paral
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/timeb.h> | |
#define N 10000000 | |
#define R 10 | |
int main() { | |
int *a, *b, *c, *d; | |
int i,j; | |
double mflop; | |
struct timeb ts, te; | |
a = (int *)malloc(N*sizeof(int)); | |
if (a==NULL) { exit(1); } | |
b = (int *)malloc(N*sizeof(int)); | |
if (b==NULL) { free(a); exit(1); } | |
c = (int *)malloc(N*sizeof(int)); | |
if (c==NULL) { free(a); free(b); exit(1); } | |
d = (int *)malloc(N*sizeof(int)); | |
if (d==NULL) { free(a); free(b); free(c); exit(1); } | |
ftime(&ts); | |
for (i=0;i<N;i++) { | |
a[i] = i % 100; | |
b[i] = -2*i; | |
c[i] = i%N; | |
d[i] = (int)(&i)*i%100; | |
} | |
for (j=0;j<R;j++) { | |
for (i=0;i<N;i++) { | |
a[i] = b[i]*c[i]+d[i]; | |
/*if (a[i]>50) { | |
b[i] = 1; | |
} | |
else { | |
b[i] = 0; | |
}*/ | |
} | |
} | |
ftime(&te); | |
for (i=0;i<N;i++) { | |
if (a[i] != b[i]*c[i]+d[i] ) { | |
printf("error\n"); | |
break; | |
} | |
} | |
free(b); | |
free(a); | |
int diff = (int) (1000.0 * (te.time - ts.time) | |
+ (te.millitm - ts.millitm)); | |
printf("For N = %d and R = %d\n", N, R); | |
printf("Exec Time (sec) = %f\n", (float)diff/1000); | |
printf("Mflops : %f", (2.0*R*N)/(((float)diff/1000)*1e6)); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.file "app.c" | |
.def ___main; .scl 2; .type 32; .endef | |
.section .rdata,"dr" | |
LC0: | |
.ascii "error\0" | |
LC2: | |
.ascii "Exec Time (millis) = %d\12\0" | |
.section .text.startup,"x" | |
.p2align 4,,15 | |
.globl _main | |
.def _main; .scl 2; .type 32; .endef | |
_main: | |
LFB24: | |
.cfi_startproc | |
pushl %ebp | |
.cfi_def_cfa_offset 8 | |
.cfi_offset 5, -8 | |
movl %esp, %ebp | |
.cfi_def_cfa_register 5 | |
pushl %edi | |
pushl %esi | |
pushl %ebx | |
andl $-16, %esp | |
subl $64, %esp | |
.cfi_offset 7, -12 | |
.cfi_offset 6, -16 | |
.cfi_offset 3, -20 | |
call ___main | |
movl $200000000, (%esp) | |
call _malloc | |
testl %eax, %eax | |
je L21 | |
movl $200000000, (%esp) | |
movl %eax, %ebx | |
call _malloc | |
testl %eax, %eax | |
movl %eax, %esi | |
je L23 | |
movl $200000000, (%esp) | |
call _malloc | |
testl %eax, %eax | |
movl %eax, %edi | |
je L24 | |
movl $200000000, (%esp) | |
call _malloc | |
testl %eax, %eax | |
movl %eax, 24(%esp) | |
je L25 | |
leal 40(%esp), %eax | |
movl %eax, (%esp) | |
call _ftime | |
xorl %eax, %eax | |
movl %ebx, 20(%esp) | |
xorl %ecx, %ecx | |
movl %eax, %ebx | |
.p2align 4,,10 | |
L6: | |
movl $1374389535, %eax | |
movl %ecx, (%edi,%ecx,4) | |
imull %ecx | |
movl %ecx, %eax | |
sarl $31, %eax | |
sarl $5, %edx | |
subl %eax, %edx | |
movl %ecx, %eax | |
imull $100, %edx, %edx | |
subl %edx, %eax | |
movl 20(%esp), %edx | |
movl %eax, (%edx,%ecx,4) | |
movl %ecx, %eax | |
negl %eax | |
addl %eax, %eax | |
movl %eax, (%esi,%ecx,4) | |
movl $1374389535, %eax | |
imull %ebx | |
movl %ebx, %eax | |
sarl $31, %eax | |
sarl $5, %edx | |
subl %eax, %edx | |
movl %ebx, %eax | |
imull $100, %edx, %edx | |
subl %edx, %eax | |
movl 24(%esp), %edx | |
movl %eax, (%edx,%ecx,4) | |
leal 36(%esp), %eax | |
addl $1, %ecx | |
addl %eax, %ebx | |
cmpl $50000000, %ecx | |
jne L6 | |
movl $10, %ecx | |
movl 20(%esp), %ebx | |
movl $50000000, 36(%esp) | |
movl %ecx, 20(%esp) | |
movl %edx, %ecx | |
.p2align 4,,10 | |
L8: | |
xorl %eax, %eax | |
.p2align 4,,10 | |
L7: | |
movl (%esi,%eax), %edx | |
imull (%edi,%eax), %edx | |
addl (%ecx,%eax), %edx | |
movl %edx, (%ebx,%eax) | |
addl $4, %eax | |
cmpl $200000000, %eax | |
jne L7 | |
subl $1, 20(%esp) | |
jne L8 | |
leal 52(%esp), %eax | |
movl %eax, (%esp) | |
call _ftime | |
movl (%edi), %eax | |
movl 24(%esp), %ecx | |
imull (%esi), %eax | |
movl $0, 36(%esp) | |
addl (%ecx), %eax | |
cmpl %eax, (%ebx) | |
jne L11 | |
movl 24(%esp), %ecx | |
movl $1, 36(%esp) | |
movl $1, %eax | |
.p2align 4,,10 | |
L12: | |
movl (%esi,%eax,4), %edx | |
imull (%edi,%eax,4), %edx | |
addl (%ecx,%eax,4), %edx | |
cmpl %edx, (%ebx,%eax,4) | |
jne L11 | |
addl $1, %eax | |
cmpl $50000000, %eax | |
jne L12 | |
L10: | |
movl %esi, (%esp) | |
call _free | |
movl %ebx, (%esp) | |
call _free | |
fnstcw 30(%esp) | |
movl 52(%esp), %eax | |
subl 40(%esp), %eax | |
movswl 44(%esp), %edx | |
movl $LC2, (%esp) | |
movl %eax, 24(%esp) | |
movswl 56(%esp), %eax | |
fildl 24(%esp) | |
fmuls LC1 | |
subl %edx, %eax | |
movl %eax, 24(%esp) | |
movzwl 30(%esp), %eax | |
fildl 24(%esp) | |
movb $12, %ah | |
movw %ax, 28(%esp) | |
faddp %st, %st(1) | |
fldcw 28(%esp) | |
fistpl 4(%esp) | |
fldcw 30(%esp) | |
call _printf | |
leal -12(%ebp), %esp | |
xorl %eax, %eax | |
popl %ebx | |
.cfi_remember_state | |
.cfi_restore 3 | |
popl %esi | |
.cfi_restore 6 | |
popl %edi | |
.cfi_restore 7 | |
popl %ebp | |
.cfi_restore 5 | |
.cfi_def_cfa 4, 4 | |
ret | |
L11: | |
.cfi_restore_state | |
movl $LC0, (%esp) | |
call _puts | |
jmp L10 | |
L25: | |
movl %ebx, (%esp) | |
call _free | |
movl %esi, (%esp) | |
call _free | |
movl %edi, (%esp) | |
call _free | |
movl $1, (%esp) | |
call _exit | |
L24: | |
movl %ebx, (%esp) | |
call _free | |
movl %esi, (%esp) | |
call _free | |
movl $1, (%esp) | |
call _exit | |
L23: | |
movl %ebx, (%esp) | |
call _free | |
L21: | |
movl $1, (%esp) | |
call _exit | |
.cfi_endproc | |
LFE24: | |
.section .rdata,"dr" | |
.align 4 | |
LC1: | |
.long 1148846080 | |
.ident "GCC: (MinGW.org GCC-6.3.0-1) 6.3.0" | |
.def _malloc; .scl 2; .type 32; .endef | |
.def _ftime; .scl 2; .type 32; .endef | |
.def _free; .scl 2; .type 32; .endef | |
.def _printf; .scl 2; .type 32; .endef | |
.def _puts; .scl 2; .type 32; .endef | |
.def _exit; .scl 2; .type 32; .endef |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
outputs : | |
For N = 10000000 and R = 10 | |
Exec Time (sec) = 1.520000 | |
Mflops : 131.578947 | |
For N = 1000000 and R = 100 | |
Exec Time (sec) = 1.397000 | |
Mflops : 143.163923 | |
For N = 100000 and R = 1000 | |
Exec Time (sec) = 1.421000 | |
Mflops : 140.745954 | |
For N = 10000 and R = 10000 | |
Exec Time (sec) = 1.239000 | |
Mflops : 161.420500 | |
For N = 1000 and R = 100000 | |
Exec Time (sec) = 1.137000 | |
Mflops : 175.901495 | |
For N = 100 and R = 1000000 | |
Exec Time (sec) = 1.129000 | |
Mflops : 177.147919 | |
For N = 10 and R = 10000000 | |
Exec Time (sec) = 1.249000 | |
Mflops : 160.128102 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment