Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

HITS ported from gunrock/gunrock #83

Merged
merged 8 commits into from
Oct 5, 2021
Merged

HITS ported from gunrock/gunrock #83

merged 8 commits into from
Oct 5, 2021

Conversation

li-yi-dong
Copy link
Contributor

Porting HITS algorithm for old GunRock

@neoblizz neoblizz changed the title Dev HITS ported from gunrock/gunrock Jun 23, 2021
@neoblizz neoblizz self-requested a review June 23, 2021 02:22
@neoblizz neoblizz added the 🍍 algorithms New or existing graph algorithms question. label Jun 23, 2021
Comment on lines +75 to +102
void print_result(std::ostream& os = std::cout){
os<<"===Authority\n\n";
for(int i = 0; i < this->auth.size(); i++){
os<<"vertex ID: "<<this->auth_vertex[i]<<std::endl;
os<<"authority: "<<this->auth[i]<<std::endl;
}
os<<"===Hub\n\n";
for(int i = 0; i < this->hub.size(); i++){
os<<"vertex ID: "<<this->hub_vertex[i]<<std::endl;
os<<"authority: "<<this->hub[i]<<std::endl;
}
}

void print_result(int max_vertices, std::ostream& os = std::cout){
int vertices = (max_vertices < this->hub.size())
? max_vertices
: this->hub.size();
os<<"===Authority\n\n";
for(int i = 0; i < vertices; i++){
os<<"vertex ID: "<<this->auth_vertex[i]<<std::endl;
os<<"authority: "<<this->auth[i]<<std::endl;
}
os<<"===Hub\n\n";
for(int i = 0; i < vertices; i++){
os<<"vertex ID: "<<this->hub_vertex[i]<<std::endl;
os<<"authority: "<<this->hub[i]<<std::endl;
}
}
Copy link
Member

@neoblizz neoblizz Jun 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use essential's print utility instead of writing a specialized helper here? It is cluttering the file.

Comment on lines +144 to +155
// Functor for deviding each element with sum and taking the sqrt
template<typename T>
struct op{
private:
float sum;
public:
op(float sum) : sum(sum){}
__device__ __host__
T operator()(const T& x) const {
return sqrt(x/this->sum);
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use C++ lambda functions instead of functors.

}
}

void update_iterator(){++this->iterator;}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not need this, iteration is automatically updated already, just use enactor's iteration for this instead.

Comment on lines +215 to +224
void update_auth(int dest_pos, int source_pos){
gunrock::math::atomic::add(&this->auth_next_p[dest_pos],
hub_curr_p[source_pos]);
}

__device__
void update_hub(int dest_pos, int source_pos){
gunrock::math::atomic::add(&hub_next_p[dest_pos],
auth_curr_p[source_pos]);
}
Copy link
Member

@neoblizz neoblizz Jun 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One line functions? Either use __forceinline__ or just incorporate the contents of the function as the instruction you want to do. i.e. you do not need these to be separate functions. Just use the atomic add and comment that this updates hub or auth.

Copy link
Member

@neoblizz neoblizz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks pretty good, minor clean-up requires before the merge.


bool is_converged(cuda::multi_context_t& context) override {
auto P = this->get_problem();
return P->is_converged();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't the contents of P->is_converged() just part of this function instead? Why does it have to call a function within a function to do something?

}
void reset() override{}

bool is_converged(){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just go in the enactor instead.

auth_next_p = auth_next.data().get();
hub_next_p = hub_next.data().get();
}
void reset() override{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initial fills from https://github.com/gunrock/essentials/pull/83/files#diff-b62c127579eb994567fe8e548f95a87eba8fc88110834e01736092e7d816e04fR166-R172 can be part of reset instead of being part of the constructor. reset() should run on every run of the application to "reset" the intermediate data I am assuming?

thrust::fill(policy, hub_next.begin(), hub_next.end(), 0);
}

void init() override{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Init should be responsible for resizing the given vectors. (see other apps for examples on init and reset)

@neoblizz neoblizz merged commit 6a864c2 into gunrock:dev Oct 5, 2021
@neoblizz
Copy link
Member

neoblizz commented Oct 5, 2021

Merging this anyways.

@li-yi-dong
Copy link
Contributor Author

@neoblizz Sorry, I didn’t see this at that time :(

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🍍 algorithms New or existing graph algorithms question.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants