Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
HPC
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alexandru Dura
HPC
Commits
24780675
Commit
24780675
authored
Mar 15, 2020
by
Alexandru Dura
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Describe the diffusion problem
parent
9a5cd392
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
142 additions
and
3 deletions
+142
-3
project/src/Field.h
project/src/Field.h
+10
-0
project/src/Main.cpp
project/src/Main.cpp
+7
-1
project/src/Makefile
project/src/Makefile
+6
-2
project/src/Problem.cpp
project/src/Problem.cpp
+78
-0
project/src/Problem.h
project/src/Problem.h
+41
-0
No files found.
project/src/Field.h
View file @
24780675
// -*-c++-*-
#pragma once
#include <ostream>
class
RowView
{
...
...
@@ -13,6 +15,10 @@ public:
return
row
[
i
];
}
double
operator
[](
unsigned
i
)
const
{
return
row
[
i
];
}
double
*
raw
()
{
return
row
;
}
...
...
@@ -41,6 +47,10 @@ public:
return
RowView
(
field
+
i
*
n
);
}
RowView
operator
[](
unsigned
i
)
const
{
return
RowView
(
field
+
i
*
n
);
}
RowView
firstRow
()
{
return
operator
[](
1
);
}
...
...
project/src/Main.cpp
View file @
24780675
#include <mpi.h>
#include "Field.h"
int
main
(
int
argc
,
char
**
argv
)
{
void
addGates
(
Field
&
f
,
int
nGates
,
double
gateSize
)
{
}
int
main
(
int
argc
,
char
**
argv
)
{
MPI
::
Init
();
MPI
::
Finalize
();
return
0
;
}
project/src/Makefile
View file @
24780675
...
...
@@ -4,12 +4,16 @@ CPP_SOURCE_FILES = $(filter-out $(ENTRY_POINTS), $(wildcard *.cpp))
C_SOURCE_FILES
=
$(
wildcard
*
.c
)
HEADER_FILES
=
$(
wildcard
*
.h
)
MPIFLAGS
=
$(
shell
mpic++
-showme
:compile
)
MPI_LD_FLAGS
=
$(
shell
mpic++
-showme
:link
)
CXX
=
g++
MPICXX
=
mpic++
CXX_FLAGS
=
-O3
CXX_FLAGS
=
-O3
-I
/usr/lib/x86_64-linux-gnu/openmpi/include/
main
:
Main.cpp $(CPP_SOURCE_FILES) $(HEADER_FILES)
$(
MPICXX)
-O3
Main.cpp
$(CPP_SOURCE_FILE
S)
-o
main
$(
CXX)
$(MPIFLAGS)
-O3
Main.cpp
$(CPP_SOURCE_FILES)
$(MPI_LD_FLAG
S)
-o
main
test
:
Test.cpp $(CPP_SOURCE_FILES) $(HEADER_FILES)
$(CXX)
-g
-O0
Test.cpp
$(CPP_SOURCE_FILES)
-o
test
...
...
project/src/Problem.cpp
0 → 100644
View file @
24780675
#include "Problem.h"
void
Problem
::
init
()
{
for
(
int
i
=
0
;
i
<
ydim
+
2
;
++
i
)
{
for
(
int
j
=
0
;
j
<
xdim
+
2
;
++
j
)
{
f0
[
i
][
j
]
=
0
;
}
}
}
void
Problem
::
addGates
(
unsigned
xGates
,
unsigned
yGates
,
double
value
)
{
const
double
GATE_WIDTH
=
0.1
;
if
(
iField
==
0
)
{
// add the xgates
for
(
unsigned
i
=
0
;
i
<
xGates
;
++
i
)
{
unsigned
gateCentre
=
(
1
+
2
*
i
)
*
xdim
/
(
2
*
xGates
);
unsigned
gateStart
=
gateCentre
-
0.5
*
GATE_WIDTH
*
xdim
;
unsigned
gateEnd
=
gateCentre
+
0.5
*
GATE_WIDTH
*
xdim
;
auto
row
=
f0
.
firstHalo
();
for
(
unsigned
j
=
gateStart
;
j
<
gateEnd
;
++
j
)
{
row
[
j
]
=
value
;
}
}
}
unsigned
starty
=
ydim
*
iField
;
unsigned
endy
=
starty
+
ydim
;
// add the ygates
for
(
unsigned
i
=
0
;
i
<
yGates
;
++
i
)
{
unsigned
gateCentre
=
(
1
+
2
*
i
)
*
ydim
/
(
2
*
yGates
);
unsigned
gateStart
=
gateCentre
-
0.5
*
GATE_WIDTH
*
ydim
;
unsigned
gateEnd
=
gateCentre
+
0.5
*
GATE_WIDTH
*
ydim
;
if
(
gateStart
>=
starty
&&
gateStart
<
endy
)
{
for
(
unsigned
j
=
gateStart
;
j
<
std
::
min
(
gateEnd
,
endy
);
j
++
)
{
f0
[
j
-
starty
+
1
][
xdim
]
=
value
;
}
}
}
}
void
Problem
::
step
(
double
cx
,
double
cy
)
{
auto
&
nextf
=
*
this
->
nextf
;
auto
&
f
=
*
this
->
currentf
;
for
(
unsigned
y
=
1
;
y
<
ydim
+
1
;
y
++
)
{
for
(
unsigned
x
=
1
;
x
<
xdim
+
1
;
x
++
)
{
nextf
[
y
][
x
]
=
0.25
*
((
1.0
+
0.5
*
cx
)
*
f
[
y
][
x
+
1
]
+
(
1.0
-
0.5
*
cx
)
*
f
[
y
][
x
-
1
]
+
(
1.0
+
0.5
*
cy
)
*
f
[
y
+
1
][
x
]
+
(
1.0
-
0.5
*
cy
)
*
f
[
y
-
1
][
x
]);
}
}
std
::
swap
(
this
->
nextf
,
this
->
currentf
);
}
double
Problem
::
residual
(
double
cx
,
double
cy
)
const
{
double
res_sqr
=
0.0
;
const
auto
&
solution
=
*
this
->
currentf
;
for
(
unsigned
iy
=
1
;
iy
<
ydim
+
1
;
iy
++
)
{
for
(
unsigned
ix
=
1
;
ix
<
xdim
+
1
;
ix
++
)
{
double
res_i
=
(
1.0
+
0.5
*
cy
)
*
solution
[
iy
+
1
][
ix
]
+
(
1.0
-
0.5
*
cy
)
*
solution
[
iy
-
1
][
ix
]
+
(
1.0
+
0.5
*
cx
)
*
solution
[
iy
][
ix
+
1
]
+
(
1.0
-
0.5
*
cx
)
*
solution
[
iy
][
ix
-
1
]
-
4.0
*
solution
[
iy
][
ix
];
res_sqr
+=
res_i
*
res_i
;
}
}
return
res_sqr
;
}
project/src/Problem.h
0 → 100644
View file @
24780675
#pragma once
#include "Field.h"
class
Problem
{
unsigned
nFields
;
unsigned
iField
;
unsigned
xdim
;
unsigned
ydim
;
Field
f0
;
Field
f1
;
Field
*
currentf
;
Field
*
nextf
;
void
init
();
void
addGates
(
unsigned
xgates
,
unsigned
ygates
,
double
value
);
public:
Problem
(
unsigned
nFields
,
unsigned
iField
,
unsigned
xdim
,
unsigned
ydim
,
unsigned
xgates
,
unsigned
ygates
,
double
gateVal
)
:
nFields
(
nFields
),
iField
(
iField
),
xdim
(
xdim
),
ydim
(
ydim
),
f0
(
xdim
,
ydim
),
f1
(
xdim
,
ydim
),
currentf
(
&
f0
),
nextf
(
&
f1
)
{
init
();
addGates
(
xgates
,
ygates
,
gateVal
);
}
void
step
(
double
cx
,
double
cy
);
double
residual
(
double
cx
,
double
cy
)
const
;
};
Write
Preview
Markdown
is supported
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