Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
Training_Test
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
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
petros.anastasiadis
Training_Test
Commits
f25189ff
Commit
f25189ff
authored
Sep 25, 2017
by
petros.anastasiadis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update 25/09/2017
parent
b884aedf
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
59 deletions
+58
-59
MPI/MPI-OpenMP.c
MPI/MPI-OpenMP.c
+9
-13
MPI/MPI.c
MPI/MPI.c
+9
-13
OpenMP/OpenMP.c
OpenMP/OpenMP.c
+11
-9
OpenMP/OpenMP_aff.c
OpenMP/OpenMP_aff.c
+15
-13
Serial/Serial.c
Serial/Serial.c
+14
-11
No files found.
MPI/MPI-OpenMP.c
View file @
f25189ff
...
...
@@ -12,29 +12,26 @@ int main(int argc, char ** argv) {
int
global_nm
[
2
],
local_nm
[
2
];
//global matrix dimensions and local matrix dimensions (2D-domain, 2D-subdomain)
int
global_padded_nm
[
2
];
//padded global matrix dimensions (if padding is not needed, global_padded=global)
int
i
,
j
,
k
,
sparse
=
0
,
*
cooCol
,
n_z
,
*
I
;
MPI_Datatype
dummy
;
//dummy datatype used to align user-defined datatypes in memory
double
*
M
,
*
A
,
*
x
,
*
y
,
*
local_y
,
*
cooVal
,
comm_t
,
comp_t
;
//Global matrix, local current and previous matrices, pointer to swap between current and previous
double
*
M
,
*
A
,
*
x
,
*
y
,
*
local_y
,
*
cooVal
,
comm_t
,
comp_t
;
MPI_Init
(
&
argc
,
&
argv
);
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
size
);
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
rank
);
/* Read n,m from stdin */
if
(
argc
<
2
)
error
(
"Too few Arguments"
);
else
if
(
argc
==
2
)
/* ./Program Input_File */
else
if
(
argc
==
2
)
/* ./Program Input_File
-> File Input to COO
*/
{
if
(
!
mtx_read
(
&
I
,
&
cooCol
,
&
cooVal
,
&
global_nm
[
0
],
&
global_nm
[
1
],
&
n_z
,
argv
[
1
]))
error
(
"input and/or COO convertion failed"
);
sparse
=
1
;
}
else
if
(
argc
==
3
)
{
/*./Program N M */
else
if
(
argc
==
3
)
{
/*./Program N M
-> Generate random NxM matrix
*/
global_nm
[
0
]
=
atoi
(
argv
[
1
]);
global_nm
[
1
]
=
atoi
(
argv
[
2
]);
}
else
error
(
"Too many Arguments"
);
/* Padd
n
if needed */
/* Padd
N
if needed */
local_nm
[
1
]
=
global_nm
[
1
];
global_padded_nm
[
1
]
=
global_nm
[
1
];
...
...
@@ -76,8 +73,7 @@ int main(int argc, char ** argv) {
//printf( "Initialize data Thread=%d i=%d\n", omp_get_thread_num(), i);
}
//----Rank 0 scatters the global matrix----//
/* Rank 0 scatters the global matrix */
double
*
gsendbuf
;
if
(
rank
==
0
){
gsendbuf
=
&
(
M
[
0
]);
...
...
@@ -103,14 +99,14 @@ int main(int argc, char ** argv) {
local_y
[
k
]
=
yi
;
}
}
MPI_Barrier
(
MPI_COMM_WORLD
);
if
(
rank
==
0
)
comp_t
=
MPI_Wtime
()
-
comp_t
;
MPI_Gather
(
local_y
,
local_nm
[
0
],
MPI_DOUBLE
,
y
,
local_nm
[
0
],
MPI_DOUBLE
,
0
,
MPI_COMM_WORLD
);
//MPI_Reduce(local_y, y, global_nm[0], MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
if
(
rank
==
0
)
comm_t
=
MPI_Wtime
()
-
comm_t
-
comp_t
;
#ifdef _DEBUG_
/* Output y in a file for debug purposes */
#ifdef _DEBUG_
/* Output y vector to a file for debugging */
if
(
rank
==
0
)
{
FILE
*
fp
;
char
*
filename
=
"/users/guest/petyros/Training/Outputs/Debug/MPI-OpenMP.out"
;
...
...
MPI/MPI.c
View file @
f25189ff
...
...
@@ -12,29 +12,26 @@ int main(int argc, char ** argv) {
int
global_nm
[
2
],
local_nm
[
2
];
//global matrix dimensions and local matrix dimensions (2D-domain, 2D-subdomain)
int
global_padded_nm
[
2
];
//padded global matrix dimensions (if padding is not needed, global_padded=global)
int
i
,
j
,
k
,
sparse
=
0
,
*
cooCol
,
n_z
,
*
I
;
MPI_Datatype
dummy
;
//dummy datatype used to align user-defined datatypes in memory
double
*
M
,
*
A
,
*
x
,
*
y
,
*
local_y
,
*
cooVal
,
comm_t
,
comp_t
;
//Global matrix, local current and previous matrices, pointer to swap between current and previous
double
*
M
,
*
A
,
*
x
,
*
y
,
*
local_y
,
*
cooVal
,
comm_t
,
comp_t
;
MPI_Init
(
&
argc
,
&
argv
);
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
size
);
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
rank
);
/* Read n,m from stdin */
if
(
argc
<
2
)
error
(
"Too few Arguments"
);
else
if
(
argc
==
2
)
/* ./Program Input_File */
else
if
(
argc
==
2
)
/* ./Program Input_File
-> File Input to COO
*/
{
if
(
!
mtx_read
(
&
I
,
&
cooCol
,
&
cooVal
,
&
global_nm
[
0
],
&
global_nm
[
1
],
&
n_z
,
argv
[
1
]))
error
(
"input and/or COO convertion failed"
);
sparse
=
1
;
}
else
if
(
argc
==
3
)
{
/*./Program N M */
else
if
(
argc
==
3
)
{
/*./Program N M
-> Generate random NxM matrix
*/
global_nm
[
0
]
=
atoi
(
argv
[
1
]);
global_nm
[
1
]
=
atoi
(
argv
[
2
]);
}
else
error
(
"Too many Arguments"
);
/* Padd
n
if needed */
/* Padd
N
if needed */
local_nm
[
1
]
=
global_nm
[
1
];
global_padded_nm
[
1
]
=
global_nm
[
1
];
...
...
@@ -70,8 +67,7 @@ int main(int argc, char ** argv) {
A
=
(
double
*
)
malloc
(
local_nm
[
0
]
*
local_nm
[
1
]
*
sizeof
(
*
M
));
//----Rank 0 scatters the global matrix----//
/* Rank 0 scatters the global matrix */
double
*
gsendbuf
;
if
(
rank
==
0
){
gsendbuf
=
&
(
M
[
0
]);
...
...
@@ -96,14 +92,14 @@ int main(int argc, char ** argv) {
local_y
[
k
]
=
yi
;
}
}
MPI_Barrier
(
MPI_COMM_WORLD
);
if
(
rank
==
0
)
comp_t
=
MPI_Wtime
()
-
comp_t
;
MPI_Gather
(
local_y
,
local_nm
[
0
],
MPI_DOUBLE
,
y
,
local_nm
[
0
],
MPI_DOUBLE
,
0
,
MPI_COMM_WORLD
);
//MPI_Reduce(local_y, y, global_nm[0], MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
if
(
rank
==
0
)
comm_t
=
MPI_Wtime
()
-
comm_t
-
comp_t
;
#ifdef _DEBUG_
/* Output y in a file for debug purposes */
#ifdef _DEBUG_
/* Output y vector to a file for debugging */
if
(
rank
==
0
)
{
FILE
*
fp
;
char
*
filename
=
"/users/guest/petyros/Training/Outputs/Debug/MPI.out"
;
...
...
OpenMP/OpenMP.c
View file @
f25189ff
...
...
@@ -21,20 +21,19 @@ int main(int argc, char **argv)
int
*
I
,
*
cooCol
,
n_z
,
sparse
=
0
;
double
*
cooVal
,
timer
;
/* File Input to COO */
if
(
argc
<
2
)
error
(
"Too few Arguments"
);
else
if
(
argc
==
2
)
/* ./Program Input_File */
else
if
(
argc
==
2
)
/* ./Program Input_File
-> File Input to COO
*/
{
if
(
!
mtx_read
(
&
I
,
&
cooCol
,
&
cooVal
,
&
n
,
&
m
,
&
n_z
,
argv
[
1
]))
error
(
"input and/or COO convertion failed"
);
sparse
=
1
;
}
else
if
(
argc
==
3
)
{
/*./Program N M */
else
if
(
argc
==
3
)
{
/*./Program N M
-> Generate random NxM matrix
*/
n
=
atoi
(
argv
[
1
]);
m
=
atoi
(
argv
[
2
]);
}
else
error
(
"Too many Arguments"
);
/* Allocate space */
double
*
x
=
(
double
*
)
malloc
(
m
*
sizeof
(
*
x
));
double
*
y
=
(
double
*
)
malloc
(
n
*
sizeof
(
*
y
));
double
**
M
=
(
double
**
)
malloc
(
n
*
sizeof
(
*
M
));
...
...
@@ -65,13 +64,16 @@ int main(int argc, char **argv)
}
}
timer
=
csecond
()
-
timer
;
#ifdef _DEBUG_
FILE
*
fp
;
char
*
filename
=
"/users/guest/petyros/Training/Outputs/Debug/OpenMP.out"
;
if
((
fp
=
fopen
(
filename
,
"w"
))
==
NULL
)
error
(
"Output file creation failed
\n
"
);
for
(
k
=
0
;
k
<
n
;
++
k
)
fprintf
(
fp
,
"%lf "
,
y
[
k
])
;
fclose
(
fp
)
;
/* Output y vector to a file for debugging */
FILE
*
fp
;
char
*
filename
=
"/users/guest/petyros/Training/Outputs/Debug/OpenMP.out"
;
if
((
fp
=
fopen
(
filename
,
"w"
))
==
NULL
)
error
(
"Output file creation failed
\n
"
);
for
(
k
=
0
;
k
<
n
;
++
k
)
fprintf
(
fp
,
"%lf "
,
y
[
k
])
;
fclose
(
fp
)
;
#endif
report_results
(
timer
);
...
...
OpenMP/OpenMP_aff.c
View file @
f25189ff
...
...
@@ -20,25 +20,24 @@ int main(int argc, char **argv)
int
*
I
,
*
cooCol
,
n_z
,
sparse
=
0
;
double
*
cooVal
,
timer
;
/* File Input to COO */
if
(
argc
<
2
)
error
(
"Too few Arguments"
);
else
if
(
argc
==
2
)
/* ./Program Input_File */
else
if
(
argc
==
2
)
/* ./Program Input_File
-> File Input to COO
*/
{
if
(
!
mtx_read
(
&
I
,
&
cooCol
,
&
cooVal
,
&
n
,
&
m
,
&
n_z
,
argv
[
1
]))
error
(
"input and/or COO convertion failed"
);
sparse
=
1
;
}
else
if
(
argc
==
3
)
{
/*./Program N M */
else
if
(
argc
==
3
)
{
/*./Program N M
-> Generate random NxM matrix
*/
n
=
atoi
(
argv
[
1
]);
m
=
atoi
(
argv
[
2
]);
}
else
error
(
"Too many Arguments"
);
/* Allocate space */
double
*
x
=
(
double
*
)
malloc
(
m
*
sizeof
(
*
x
));
double
*
y
=
(
double
*
)
malloc
(
n
*
sizeof
(
*
y
));
double
*
M
=
(
double
*
)
malloc
(
n
*
m
*
sizeof
(
*
M
));
#pragma omp parallel for schedule(static)
/* Initialize data for each thread in corresponding socket with first-touch policy */
#pragma omp parallel for schedule(static)
/* Initialize data for each thread in corresponding socket
/cache
with first-touch policy */
for
(
i
=
0
;
i
<
n
;
++
i
){
for
(
j
=
0
;
j
<
m
;
++
j
)
M
[
i
*
m
+
j
]
=
0
.
0
;
//printf( "Initialize data Thread=%d i=%d\n", omp_get_thread_num(), i);
...
...
@@ -58,8 +57,8 @@ int main(int argc, char **argv)
vec_init
(
y
,
n
,
0
.
0
);
/* OpenMP Kernel */
printf
(
"OpenMP Version(N=%d, M=%d, Threads=%s): "
,
n
,
m
,
getenv
(
"OMP_NUM_THREADS"
));
/* OpenMP
Affinity
Kernel */
printf
(
"OpenMP
_aff
Version(N=%d, M=%d, Threads=%s): "
,
n
,
m
,
getenv
(
"OMP_NUM_THREADS"
));
timer
=
csecond
();
for
(
i
=
0
;
i
<
NR_ITER
;
++
i
){
register
double
yi
=
0
;
...
...
@@ -72,13 +71,16 @@ int main(int argc, char **argv)
}
}
timer
=
csecond
()
-
timer
;
#ifdef _DEBUG_
/* Output y in a file for debug purposes */
FILE
*
fp
;
char
*
filename
=
"/users/guest/petyros/Training/Outputs/Debug/OpenMP_aff.out"
;
if
((
fp
=
fopen
(
filename
,
"w"
))
==
NULL
)
error
(
"Output file creation failed
\n
"
);
for
(
k
=
0
;
k
<
n
;
++
k
)
fprintf
(
fp
,
"%lf "
,
y
[
k
])
;
fclose
(
fp
)
;
#ifdef _DEBUG_
/* Output y vector to a file for debugging */
FILE
*
fp
;
char
*
filename
=
"/users/guest/petyros/Training/Outputs/Debug/OpenMP_aff.out"
;
if
((
fp
=
fopen
(
filename
,
"w"
))
==
NULL
)
error
(
"Output file creation failed
\n
"
);
for
(
k
=
0
;
k
<
n
;
++
k
)
fprintf
(
fp
,
"%lf "
,
y
[
k
])
;
fclose
(
fp
)
;
#endif
report_results
(
timer
);
return
0
;
...
...
Serial/Serial.c
View file @
f25189ff
...
...
@@ -20,22 +20,22 @@ int main(int argc, char **argv)
double
*
cooVal
,
timer
;
/* File Input to COO */
if
(
argc
<
2
)
error
(
"Too few Arguments"
);
else
if
(
argc
==
2
)
/* ./Program Input_File */
else
if
(
argc
==
2
)
/* ./Program Input_File
-> File Input to COO
*/
{
if
(
!
mtx_read
(
&
I
,
&
cooCol
,
&
cooVal
,
&
n
,
&
m
,
&
n_z
,
argv
[
1
]))
error
(
"input and/or COO convertion failed"
);
sparse
=
1
;
}
else
if
(
argc
==
3
)
{
/*./Program N M */
else
if
(
argc
==
3
)
{
/*./Program N M
-> Generate random NxM matrix
*/
n
=
atoi
(
argv
[
1
]);
m
=
atoi
(
argv
[
2
]);
}
else
error
(
"Too many Arguments"
);
double
*
x
=
(
double
*
)
malloc
(
m
*
sizeof
(
*
x
));
/* Allocate space */
double
*
x
=
(
double
*
)
malloc
(
m
*
sizeof
(
*
x
));
double
*
y
=
(
double
*
)
malloc
(
n
*
sizeof
(
*
y
));
double
**
M
=
(
double
**
)
malloc
(
n
*
sizeof
(
*
M
));
double
**
M
=
(
double
**
)
malloc
(
n
*
sizeof
(
*
M
));
for
(
i
=
0
;
i
<
n
;
++
i
)
M
[
i
]
=
(
double
*
)
calloc
(
m
,
sizeof
(
double
));
if
(
!
y
||
!
x
||
!
M
)
error
(
"memory allocation failed"
);
...
...
@@ -62,13 +62,16 @@ int main(int argc, char **argv)
}
}
timer
=
csecond
()
-
timer
;
#ifdef _DEBUG_
FILE
*
fp
;
char
*
filename
=
"/users/guest/petyros/Training/Outputs/Debug/Serial.out"
;
if
((
fp
=
fopen
(
filename
,
"w"
))
==
NULL
)
error
(
"Output file creation failed
\n
"
);
for
(
k
=
0
;
k
<
n
;
++
k
)
fprintf
(
fp
,
"%lf "
,
y
[
k
])
;
fclose
(
fp
)
;
/* Output y vector to a file for debugging */
FILE
*
fp
;
char
*
filename
=
"/users/guest/petyros/Training/Outputs/Debug/Serial.out"
;
if
((
fp
=
fopen
(
filename
,
"w"
))
==
NULL
)
error
(
"Output file creation failed
\n
"
);
for
(
k
=
0
;
k
<
n
;
++
k
)
fprintf
(
fp
,
"%lf "
,
y
[
k
])
;
fclose
(
fp
)
;
#endif
report_results
(
timer
);
return
0
;
...
...
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