Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
M2-supercomputing
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
Admin message
GitLab upgrade completed. Current version is 17.11.4.
Show more breadcrumbs
GMYS Jan
M2-supercomputing
Commits
d13d6252
Commit
d13d6252
authored
2 years ago
by
GMYS Jan
Browse files
Options
Downloads
Patches
Plain Diff
triad
parent
dae3a1e0
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
OpenMP/Code/triad.c
+53
-0
53 additions, 0 deletions
OpenMP/Code/triad.c
with
53 additions
and
0 deletions
OpenMP/Code/triad.c
0 → 100644
+
53
−
0
View file @
d13d6252
#include
<stdio.h>
#include
<stdlib.h>
#include
<time.h>
#include
<omp.h>
void
triad
(
const
float
*
a
,
const
float
*
b
,
const
float
*
c
,
float
*
d
,
const
size_t
n
,
const
size_t
m
)
{
for
(
size_t
i
=
0
;
i
<
n
;
i
++
){
#pragma omp parallel for
for
(
size_t
j
=
0
;
j
<
m
;
j
++
){
d
[
j
]
=
c
[
j
]
+
a
[
j
]
*
b
[
j
];
}
}
}
int
main
(
int
argc
,
char
**
argv
)
{
size_t
m
;
//aka long unsigned int
if
(
argc
==
2
){
m
=
atoi
(
argv
[
1
]);
}
else
{
printf
(
"need an argument (vector length)!
\n
"
);
}
unsigned
long
long
int
n
=
(
1ULL
<<
32
);
n
/=
m
;
float
*
a
,
*
b
,
*
c
,
*
d
;
a
=
(
float
*
)
malloc
(
m
*
sizeof
(
float
));
b
=
(
float
*
)
malloc
(
m
*
sizeof
(
float
));
c
=
(
float
*
)
malloc
(
m
*
sizeof
(
float
));
d
=
(
float
*
)
malloc
(
m
*
sizeof
(
float
));
for
(
int
i
=
0
;
i
<
m
;
i
++
){
a
[
i
]
=
i
+
1
;
b
[
i
]
=
i
+
2
;
c
[
i
]
=
i
+
3
;
}
struct
timespec
tstart
,
tstop
;
clock_gettime
(
CLOCK_MONOTONIC
,
&
tstart
);
triad
(
a
,
b
,
c
,
d
,
n
,
m
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
tstop
);
double
elapsed
=
(
tstop
.
tv_sec
-
tstart
.
tv_sec
)
+
(
tstop
.
tv_nsec
-
tstart
.
tv_nsec
)
/
1e9
;
printf
(
"m=%lu %llu
\t
elapsed time: %f
\t
Mflops: %f
\n
"
,
m
,
n
,
elapsed
,(
2
.
0
*
n
*
m
/
elapsed
)
/
(
1024
.
0
*
1024
.
0
));
free
(
a
);
free
(
b
);
free
(
c
);
free
(
d
);
}
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