Fix compiler warnings. (#9055)

This commit is contained in:
Jiaming Yuan 2023-04-21 02:26:47 +08:00 committed by GitHub
parent 2acd78b44b
commit a7b3dd3176
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,23 +32,23 @@ namespace collective {
* @param function The function used to calculate the results. * @param function The function used to calculate the results.
* @param args Arguments to the function. * @param args Arguments to the function.
*/ */
template <typename Function, typename... Args> template <typename Function, typename T, typename... Args>
void ApplyWithLabels(MetaInfo const& info, void* buffer, size_t size, Function&& function, void ApplyWithLabels(MetaInfo const& info, T* buffer, size_t size, Function&& function,
Args&&... args) { Args&&... args) {
if (info.IsVerticalFederated()) { if (info.IsVerticalFederated()) {
// We assume labels are only available on worker 0, so the calculation is done there and result // We assume labels are only available on worker 0, so the calculation is done there and result
// broadcast to other workers. // broadcast to other workers.
std::vector<char> message(1024); std::string message;
if (collective::GetRank() == 0) { if (collective::GetRank() == 0) {
try { try {
std::forward<Function>(function)(std::forward<Args>(args)...); std::forward<Function>(function)(std::forward<Args>(args)...);
} catch (dmlc::Error& e) { } catch (dmlc::Error& e) {
strncpy(&message[0], e.what(), message.size()); message = e.what();
message.back() = '\0';
} }
} }
collective::Broadcast(&message[0], message.size(), 0);
if (strlen(&message[0]) == 0) { collective::Broadcast(&message, 0);
if (message.empty()) {
collective::Broadcast(buffer, size, 0); collective::Broadcast(buffer, size, 0);
} else { } else {
LOG(FATAL) << &message[0]; LOG(FATAL) << &message[0];
@ -57,6 +57,5 @@ void ApplyWithLabels(MetaInfo const& info, void* buffer, size_t size, Function&&
std::forward<Function>(function)(std::forward<Args>(args)...); std::forward<Function>(function)(std::forward<Args>(args)...);
} }
} }
} // namespace collective } // namespace collective
} // namespace xgboost } // namespace xgboost