Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-graph
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
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
Platform
Development
swh-graph
Commits
d2e89046
Commit
d2e89046
authored
1 year ago
by
vlorentz
Browse files
Options
Downloads
Patches
Plain Diff
Implement MAPS step
parent
0001fe30
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!347
Add Rust rewrite of the Java code
Pipeline
#4428
failed
1 year ago
Stage: external
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
rust/src/bin/compress.rs
+46
-9
46 additions, 9 deletions
rust/src/bin/compress.rs
rust/src/map/node2swhid.rs
+2
-2
2 additions, 2 deletions
rust/src/map/node2swhid.rs
with
48 additions
and
11 deletions
rust/src/bin/compress.rs
+
46
−
9
View file @
d2e89046
...
...
@@ -707,6 +707,7 @@ pub fn main() -> Result<()> {
let
_
=
parse_allowed_node_types
(
&
allowed_node_types
);
println!
(
"Loading permutation"
);
let
order
=
MappedPermutation
::
load
(
num_nodes
,
order
.as_path
())
.with_context
(||
format!
(
"Could not load {}"
,
order
.display
()))
?
;
match
mph_algo
{
...
...
@@ -715,13 +716,13 @@ pub fn main() -> Result<()> {
}
let
file
=
File
::
open
(
&
function
)
.with_context
(||
format!
(
"Cannot read {}"
,
function
.display
()))
?
;
println!
(
"
R
eading MPH"
);
println!
(
"
Permutation loaded, r
eading MPH"
);
let
mph
=
fmph
::
Function
::
read
(
&
mut
BufReader
::
new
(
file
))
.context
(
"Could not parse mph"
)
?
;
println!
(
"MPH loaded, sorting arcs"
);
let
node2swhid
=
Mutex
::
new
(
Node2SWHID
::
new
(
node2swhid
,
num_nodes
)
?
)
;
let
node2type
=
Mutex
::
new
(
Node2Type
::
new
(
node2type
,
num_nodes
)
?
);
let
mut
swhids
:
Vec
<
SWHID
>
=
Vec
::
with_capacity
(
num_nodes
);
let
swhids_uninit
=
swhids
.spare_capacity_mut
(
);
let
mut
pl
=
ProgressLogger
::
default
()
.display_memory
();
pl
.item_name
=
"node"
;
...
...
@@ -729,7 +730,6 @@ pub fn main() -> Result<()> {
pl
.expected_updates
=
Some
(
num_nodes
);
pl
.start
(
"Computing node2swhid"
);
// TODO: Keep parallelism low? the mutexes are a tight bottleneck
par_iter_lines_from_dir
(
&
swhids_dir
,
Arc
::
new
(
Mutex
::
new
(
pl
)))
.for_each
(
|
line
:
[
u8
;
50
]|
{
let
node_id
=
order
.get
(
mph
.get
(
&
line
)
.expect
(
"Failed to hash line"
)
as
usize
);
...
...
@@ -744,13 +744,50 @@ pub fn main() -> Result<()> {
num_nodes
);
let
mut
node2swhid
=
node2swhid
.lock
()
.unwrap
();
let
mut
node2type
=
node2type
.lock
()
.unwrap
();
// Safe because we just checked it does not write past the end.
unsafe
{
node2swhid
.set_unchecked
(
node_id
,
swhid
)
};
unsafe
{
node2type
.set_unchecked
(
node_id
,
swhid
.node_type
)
};
// Safe because we checked node_id < num_nodes
unsafe
{
swhids_uninit
.as_ptr
()
.offset
(
node_id
as
isize
)
.cast_mut
()
.write
(
std
::
mem
::
MaybeUninit
::
new
(
swhid
));
}
},
);
// Assuming the MPH and permutation are correct, we wrote an item at every
// index.
unsafe
{
swhids
.set_len
(
num_nodes
)
};
let
mut
node2swhid
=
Node2SWHID
::
new
(
node2swhid
,
num_nodes
)
?
;
let
mut
node2type
=
Node2Type
::
new
(
node2type
,
num_nodes
)
?
;
std
::
thread
::
scope
(|
s
|
{
s
.spawn
(||
{
let
mut
pl
=
ProgressLogger
::
default
()
.display_memory
();
pl
.item_name
=
"swhid"
;
pl
.local_speed
=
true
;
pl
.expected_updates
=
Some
(
num_nodes
);
pl
.start
(
"Writing node2swhid"
);
for
i
in
0
..
num_nodes
{
pl
.light_update
();
unsafe
{
node2swhid
.set_unchecked
(
i
,
*
swhids
.get_unchecked
(
i
))
}
}
pl
.done
();
});
s
.spawn
(||
{
let
mut
pl
=
ProgressLogger
::
default
()
.display_memory
();
pl
.item_name
=
"type"
;
pl
.local_speed
=
true
;
pl
.expected_updates
=
Some
(
num_nodes
);
pl
.start
(
"Writing node2type"
);
for
i
in
0
..
num_nodes
{
pl
.light_update
();
unsafe
{
node2type
.set_unchecked
(
i
,
swhids
.get_unchecked
(
i
)
.node_type
)
}
}
pl
.done
();
});
});
}
Commands
::
HashSwhids
{
swhids
,
mph
}
=>
{
...
...
This diff is collapsed.
Click to expand it.
rust/src/map/node2swhid.rs
+
2
−
2
View file @
d2e89046
...
...
@@ -107,7 +107,7 @@ impl<B: AsRef<[u8]>> Node2SWHID<B> {
}
impl
<
B
:
AsMut
<
[
u8
]
>
+
AsRef
<
[
u8
]
>>
Node2SWHID
<
B
>
{
///
Conver
t a node_i
t to a SWHID
///
Se
t a node_i
d to map to a given SWHID, without checking bounds
///
/// # Safety
/// This function is unsafe because it does not check that `node_id` is
...
...
@@ -122,7 +122,7 @@ impl<B: AsMut<[u8]> + AsRef<[u8]>> Node2SWHID<B> {
.copy_from_slice
(
&
bytes
[
..
]);
}
///
Conver
t a node_i
t to a
SWHID
///
Se
t a node_i
d to map to a given
SWHID
#[inline]
pub
fn
set
(
&
mut
self
,
node_id
:
usize
,
swhid
:
SWHID
)
{
let
bytes
:
[
u8
;
SWHID
::
BYTES_SIZE
]
=
swhid
.into
();
...
...
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