Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openmp_course
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
scicore
openmp_course
Commits
ee219234
Commit
ee219234
authored
5 years ago
by
Ruben
Browse files
Options
Downloads
Patches
Plain Diff
Addded integration
parent
34f29d5d
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
integration/integration.cpp
+42
-0
42 additions, 0 deletions
integration/integration.cpp
integration/integration.f90
+43
-0
43 additions, 0 deletions
integration/integration.f90
integration/integration.py
+31
-0
31 additions, 0 deletions
integration/integration.py
with
116 additions
and
0 deletions
integration/integration.cpp
0 → 100644
+
42
−
0
View file @
ee219234
#include
<cstdio>
#include
<mpi.h>
int
main
()
{
MPI_Comm
comm
;
int
size
,
rank
;
MPI_Init
(
NULL
,
NULL
);
comm
=
MPI_COMM_WORLD
;
MPI_Comm_rank
(
comm
,
&
rank
);
MPI_Comm_size
(
comm
,
&
size
);
const
int
totalsteps
=
10000
;
const
int
steps
=
totalsteps
/
size
;
const
double
dx
=
1.
/
totalsteps
;
int
ini
=
rank
*
steps
;
int
fin
=
(
rank
+
1
)
*
steps
;
if
(
fin
>=
totalsteps
)
fin
=
totalsteps
;
double
localSum
=
0.0
;
for
(
int
i
=
ini
;
i
<
fin
;
i
++
)
{
double
x
=
(
i
-
0.5
)
*
dx
;
localSum
+=
4.0
/
(
1.0
+
x
*
x
);
}
localSum
=
localSum
*
dx
;
double
globalSum
=
0.0
;
MPI_Allreduce
(
&
localSum
,
&
globalSum
,
1
,
MPI_DOUBLE_PRECISION
,
MPI_SUM
,
comm
);
printf
(
"%f %f
\n
"
,
localSum
,
globalSum
);
MPI_Barrier
(
comm
);
MPI_Finalize
();
return
0
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
integration/integration.f90
0 → 100644
+
43
−
0
View file @
ee219234
program
integration
implicit
none
include
'mpif.h'
integer
ierr
,
comm
,
rank
,
size
integer
i
,
totalsteps
,
steps
,
ini
,
fin
double precision
dx
,
x
,
localSum
,
globalSum
call
MPI_INIT
(
ierr
);
comm
=
MPI_COMM_WORLD
call
MPI_COMM_RANK
(
comm
,
rank
,
ierr
)
call
MPI_COMM_SIZE
(
comm
,
size
,
ierr
)
totalsteps
=
1000000
steps
=
totalsteps
/
size
ini
=
rank
*
steps
fin
=
(
rank
+1
)
*
steps
if
(
fin
.ge.
totalsteps
)
then
fin
=
totalsteps
endif
write
(
*
,
*
)
rank
,
ini
,
fin
dx
=
1.d0
/
totalsteps
x
=
-0.5d0
*
dx
localSum
=
0.d0
do
i
=
ini
,
fin
x
=
(
i
-0.5d0
)
*
dx
localSum
=
localSum
+
4.d0
/
(
1.d0
+
x
*
x
)
enddo
localSum
=
localSum
*
dx
call
MPI_ALLREDUCE
(
localSum
,
globalSum
,
1
,
MPI_DOUBLE_PRECISION
,
MPI_SUM
,
comm
,
ierr
)
write
(
*
,
*
)
localSum
,
globalSum
call
MPI_BARRIER
(
comm
,
ierr
)
call
MPI_FINALIZE
(
ierr
)
end
program
integration
\ No newline at end of file
This diff is collapsed.
Click to expand it.
integration/integration.py
0 → 100644
+
31
−
0
View file @
ee219234
from
mpi4py
import
MPI
import
numpy
comm
=
MPI
.
COMM_WORLD
rank
=
comm
.
Get_rank
()
size
=
comm
.
Get_size
()
totalsteps
=
1000000
steps
=
totalsteps
/
size
ini
=
rank
*
steps
fin
=
(
rank
+
1
)
*
steps
if
fin
>
totalsteps
:
fin
=
totalsteps
print
(
rank
,
ini
,
fin
)
dx
=
1.
/
totalsteps
x
=
-
0.5
*
dx
localSum
=
0.
for
i
in
range
(
int
(
ini
),
int
(
fin
)):
x
=
(
i
-
0.5
)
*
dx
localSum
=
localSum
+
4.
/
(
1.
+
x
*
x
)
localSum
=
localSum
*
dx
globalSum
=
comm
.
allreduce
(
localSum
,
op
=
MPI
.
SUM
)
print
(
localSum
,
globalSum
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment