Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
ptSpar
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
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
coregraphie
ptSpar
Commits
a730de6b
Commit
a730de6b
authored
1 year ago
by
gianlucarossi15
Browse files
Options
Downloads
Patches
Plain Diff
openMP implementation
parent
6f06be83
No related branches found
No related tags found
1 merge request
!1
New code version
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
(p,t)_sparsification/main.cpp
+40
-18
40 additions, 18 deletions
(p,t)_sparsification/main.cpp
with
40 additions
and
18 deletions
(p,t)_sparsification/main.cpp
+
40
−
18
View file @
a730de6b
...
@@ -74,37 +74,59 @@ int main(int argc, char *argv[]) {
...
@@ -74,37 +74,59 @@ int main(int argc, char *argv[]) {
auto
start
=
chrono
::
steady_clock
::
now
();
auto
start
=
chrono
::
steady_clock
::
now
();
string
execMode
=
var
[
"algorithm"
].
as
<
string
>
();
string
execMode
=
var
[
"algorithm"
].
as
<
string
>
();
for
(
int
i
=
0
;
i
<
NUM_TRIALS
;
i
++
)
{
#include
<omp.h>
pthread_create
(
&
threads
[
i
],
NULL
,
handler
,
NULL
);
#include
<chrono>
if
(
execMode
==
"Random"
)
{
#include
<vector>
g2
=
compress_graph_basic
(
g
,
var
[
"depth"
].
as
<
int
>
(),
var
[
"proportions"
].
as
<
vector
<
double
>>
(),
#include
<string>
// Assuming NUM_TRIALS and other variables are defined somewhere
#pragma omp parallel for
for
(
int
i
=
0
;
i
<
NUM_TRIALS
;
i
++
)
{
// Inside the loop, each thread will execute one iteration
// Each thread will create a separate graph instance, so make sure g2 is declared inside the loop
Graph
g2
;
// Other variables like edges_original and edges_compressed need to be declared thread-safe or local to each thread
auto
start
=
std
::
chrono
::
steady_clock
::
now
();
if
(
var
[
"algorithm"
].
as
<
std
::
string
>
()
==
"Random"
)
{
g2
=
compress_graph_basic
(
g
,
var
[
"depth"
].
as
<
int
>
(),
var
[
"proportions"
].
as
<
std
::
vector
<
double
>>
(),
var
[
"directed"
].
as
<
bool
>
());
var
[
"directed"
].
as
<
bool
>
());
}
else
if
(
execMode
==
"LP"
)
{
}
else
if
(
var
[
"algorithm"
].
as
<
std
::
string
>
()
==
"LP"
)
{
g2
=
compress_graph_LP
(
g
,
e_s
,
var
[
"depth"
].
as
<
int
>
(),
var
[
"proportions"
].
as
<
vector
<
double
>>
(),
g2
=
compress_graph_LP
(
g
,
e_s
,
var
[
"depth"
].
as
<
int
>
(),
var
[
"proportions"
].
as
<
std
::
vector
<
double
>>
(),
var
[
"directed"
].
as
<
bool
>
());
var
[
"directed"
].
as
<
bool
>
());
}
else
if
(
execMode
==
"SA"
)
{
}
else
if
(
var
[
"algorithm"
].
as
<
std
::
string
>
()
==
"SA"
)
{
g2
=
Simulated_annealing
(
1000
,
10
,
0.99
,
g
,
var
[
"directed"
].
as
<
bool
>
(),
var
[
"depth"
].
as
<
int
>
(),
g2
=
Simulated_annealing
(
1000
,
10
,
0.99
,
g
,
var
[
"directed"
].
as
<
bool
>
(),
var
[
"depth"
].
as
<
int
>
(),
var
[
"proportions"
].
as
<
vector
<
double
>>
());
var
[
"proportions"
].
as
<
std
::
vector
<
double
>>
());
}
else
if
(
execMode
==
"Greedy"
)
{
}
else
if
(
var
[
"algorithm"
].
as
<
std
::
string
>
()
==
"Greedy"
)
{
g2
=
compress_graph_greedy
(
g
,
var
[
"depth"
].
as
<
int
>
(),
var
[
"proportions"
].
as
<
vector
<
double
>>
(),
g2
=
compress_graph_greedy
(
g
,
var
[
"depth"
].
as
<
int
>
(),
var
[
"proportions"
].
as
<
std
::
vector
<
double
>>
(),
var
[
"directed"
].
as
<
bool
>
());
var
[
"directed"
].
as
<
bool
>
());
}
}
auto
finish
=
chrono
::
steady_clock
::
now
();
auto
finish
=
std
::
chrono
::
steady_clock
::
now
();
vector
<
edge
>
edges_original
=
get_edges
(
g
,
var
[
"directed"
].
as
<
bool
>
());
edges_compressed
+=
get_edges
(
g2
,
var
[
"directed"
].
as
<
bool
>
()).
size
();
// It's important to calculate and update edges_compressed and elapsed_time inside the loop in a thread-safe manner
elapsed_time
+=
chrono
::
duration_cast
<
chrono
::
duration
<
double
>>
(
finish
-
start
).
count
();
// Each thread should update its own local variables or use reduction clauses for summation
// compression_rate = ((double) (edges_original.size() - edges_compressed.size()) /
// edges_original.size());
// c.push_back(compression_rate);
// s.push_back(edges_compressed);
// Update edges_compressed and elapsed_time in a thread-safe manner
#pragma omp critical
{
vector
<
edge
>
edges_original
=
get_edges
(
g
,
var
[
"directed"
].
as
<
bool
>
());
edges_compressed
+=
get_edges
(
g2
,
var
[
"directed"
].
as
<
bool
>
()).
size
();
elapsed_time
+=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
duration
<
double
>>
(
finish
-
start
).
count
();
}
// You may also need to handle compression_rate, c, and s variables inside the loop, ensuring thread safety.
}
}
//graph_to_file(var, elapsed_time, compression_rate, edges_compressed);
//graph_to_file(var, elapsed_time, compression_rate, edges_compressed);
// cout << "compression rate: " << compression_rate << endl;
// cout << "compression rate: " << compression_rate << endl;
cout
<<
endl
<<
"compression time: "
<<
elapsed_time
/
NUM_TRIALS
<<
endl
;
cout
<<
endl
<<
"compression time: "
<<
elapsed_time
/
NUM_TRIALS
<<
endl
;
...
...
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