@@ -32,23 +32,23 @@ namespace collective {
32
32
* @param function The function used to calculate the results.
33
33
* @param args Arguments to the function.
34
34
*/
35
- template <typename Function, typename ... Args>
36
- void ApplyWithLabels (MetaInfo const & info, void * buffer, size_t size, Function&& function,
35
+ template <typename Function, typename T, typename ... Args>
36
+ void ApplyWithLabels (MetaInfo const & info, T * buffer, size_t size, Function&& function,
37
37
Args&&... args) {
38
38
if (info.IsVerticalFederated ()) {
39
39
// We assume labels are only available on worker 0, so the calculation is done there and result
40
40
// broadcast to other workers.
41
- std::vector< char > message ( 1024 ) ;
41
+ std::string message;
42
42
if (collective::GetRank () == 0 ) {
43
43
try {
44
44
std::forward<Function>(function)(std::forward<Args>(args)...);
45
45
} catch (dmlc::Error& e) {
46
- strncpy (&message[0 ], e.what (), message.size ());
47
- message.back () = ' \0 ' ;
46
+ message = e.what ();
48
47
}
49
48
}
50
- collective::Broadcast (&message[0 ], message.size (), 0 );
51
- if (strlen (&message[0 ]) == 0 ) {
49
+
50
+ collective::Broadcast (&message, 0 );
51
+ if (message.empty ()) {
52
52
collective::Broadcast (buffer, size, 0 );
53
53
} else {
54
54
LOG (FATAL) << &message[0 ];
@@ -57,6 +57,5 @@ void ApplyWithLabels(MetaInfo const& info, void* buffer, size_t size, Function&&
57
57
std::forward<Function>(function)(std::forward<Args>(args)...);
58
58
}
59
59
}
60
-
61
60
} // namespace collective
62
61
} // namespace xgboost
0 commit comments