-
Notifications
You must be signed in to change notification settings - Fork 10
/
wordrank.cpp
78 lines (65 loc) · 2.38 KB
/
wordrank.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* Copyright (c) 2015 Shihao Ji and Hyokun Yun. All Rights Reserved.
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
* For more information, bug reports, fixes, contact:
* Shihao Ji ([email protected])
* Hyokun Yun ([email protected])
*/
#include <boost/format.hpp>
#include "parameter.hpp"
#include "data.hpp"
#include "model.hpp"
using std::cout;
using std::cerr;
using std::endl;
using wordrank::Parameter;
using wordrank::Data;
using wordrank::Model;
int main(int argc, char **argv) {
int numtasks, rank, hostname_len;
char hostname[MPI_MAX_PROCESSOR_NAME];
// retrieve MPI task info
int mpi_thread_provided;
MPI_Init_thread(nullptr, nullptr, MPI_THREAD_MULTIPLE, &mpi_thread_provided);
if (mpi_thread_provided != MPI_THREAD_MULTIPLE) {
cerr << "MPI multiple thread not provided!!! (" << mpi_thread_provided << " != " << MPI_THREAD_MULTIPLE << ")" << endl;
exit(1);
}
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
MPI_Get_processor_name(hostname, &hostname_len);
cout << boost::format("processor name: %s, number of tasks: %d, rank: %d") % hostname % numtasks % rank << endl;
Parameter param;
Data data;
int ret_code;
if ((ret_code = param.read_arguments(argc, argv)) != 0) {
return ret_code;
}
param.numtasks_ = numtasks;
param.rank_ = rank;
if ((ret_code = load_data(data, param.data_path_, param.random_seed_, rank, numtasks, param.numthreads_,
param.xmax_, param.epsilon_)) != 0) {
return ret_code;
}
Model model(param, data);
model.run();
MPI_Finalize();
return 0;
}