Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Ardhi Putra Pratama
teaching
Commits
b38d2888
Commit
b38d2888
authored
Jan 22, 2018
by
Ardhi Putra Pratama
Browse files
add hpc stuff
parent
9efe8323
Changes
2
Hide whitespace changes
Inline
Side-by-side
hpc/prime/prime_c.c
0 → 100644
View file @
b38d2888
#include
<stdio.h>
#include
<math.h>
int
main
()
{
int
lower
,
upper
,
total
,
i
,
j
;
int
isprime
;
total
=
0
;
lower
=
2
;
upper
=
1234567
;
for
(
i
=
lower
;
i
<=
upper
;
i
++
)
{
isprime
=
1
;
for
(
j
=
2
;
j
<
i
;
j
++
)
{
if
(
i
%
j
==
0
)
{
isprime
=
0
;
break
;
}
}
total
+=
isprime
;
}
printf
(
"Number of Prime Numbers from %d to %d=%d
\n
"
,
lower
,
upper
,
total
);
}
hpc/prime/prime_mpi.c
0 → 100644
View file @
b38d2888
#include
<stdio.h>
#include
"mpi.h"
#include
<stdlib.h>
#include
<assert.h>
int
main
(
int
argc
,
char
*
argv
[])
{
int
lower
,
upper
,
total
,
i
,
j
,
isprime
;
int
rank
,
size
;
int
local_total
=
0
;
int
global_total
=
0
;
double
time_initial
,
time_current
,
time
;
MPI_Init
(
&
argc
,
&
argv
);
time_initial
=
MPI_Wtime
();
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
rank
);
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
size
);
local_total
=
0
;
lower
=
2
;
upper
=
1234567
;
MPI_Bcast
(
&
upper
,
1
,
MPI_INT
,
0
,
MPI_COMM_WORLD
);
for
(
i
=
lower
+
rank
;
i
<=
upper
;
i
=
i
+
size
)
{
isprime
=
1
;
for
(
j
=
2
;
j
<
i
;
j
++
)
{
if
(
i
%
j
==
0
)
{
isprime
=
0
;
break
;
}
}
local_total
+=
isprime
;
}
MPI_Reduce
(
&
local_total
,
&
global_total
,
1
,
MPI_INT
,
MPI_SUM
,
0
,
MPI_COMM_WORLD
);
time_current
=
MPI_Wtime
();
time
=
time_current
-
time_initial
;
if
(
rank
==
0
)
{
printf
(
"Total Prime Numbers = %d
\n
"
,
global_total
);
printf
(
"ElapsedTime=%.3f
\n
"
,
time
);
}
MPI_Barrier
(
MPI_COMM_WORLD
);
MPI_Finalize
();
return
0
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment