-/* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2007-2021. The SimGrid Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
}
int PMPI_Get_library_version (char *version,int *len){
- snprintf(version, MPI_MAX_LIBRARY_VERSION_STRING, "SMPI Version %d.%d. Copyright The SimGrid Team 2007-2020",
+ snprintf(version, MPI_MAX_LIBRARY_VERSION_STRING, "SMPI Version %d.%d. Copyright The SimGrid Team 2007-2021",
SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR);
*len = strlen(version) > MPI_MAX_LIBRARY_VERSION_STRING ? MPI_MAX_LIBRARY_VERSION_STRING : strlen(version);
return MPI_SUCCESS;
int PMPI_Get_processor_name(char *name, int *resultlen)
{
- strncpy(name, sg_host_self()->get_cname(),
- strlen(sg_host_self()->get_cname()) < MPI_MAX_PROCESSOR_NAME - 1 ? strlen(sg_host_self()->get_cname()) + 1
- : MPI_MAX_PROCESSOR_NAME - 1);
- *resultlen = strlen(name) > MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
+ int len = std::min<int>(sg_host_self()->get_name().size(), MPI_MAX_PROCESSOR_NAME - 1);
+ std::string(sg_host_self()->get_name()).copy(name, len);
+ name[len] = '\0';
+ *resultlen = len;
return MPI_SUCCESS;
}
int PMPI_Alloc_mem(MPI_Aint size, MPI_Info /*info*/, void* baseptr)
{
void *ptr = xbt_malloc(size);
- if(ptr==nullptr)
- return MPI_ERR_NO_MEM;
- else {
- *static_cast<void**>(baseptr) = ptr;
- return MPI_SUCCESS;
- }
+ *static_cast<void**>(baseptr) = ptr;
+ return MPI_SUCCESS;
}
int PMPI_Free_mem(void *baseptr){
int PMPI_Error_string(int errorcode, char* string, int* resultlen)
{
- static const char* smpi_error_string[] = {FOREACH_ERROR(GENERATE_STRING)};
- constexpr int nerrors = (sizeof smpi_error_string) / (sizeof smpi_error_string[0]);
- if (errorcode < 0 || errorcode >= nerrors || string == nullptr)
+ static const std::vector<const char*> smpi_error_string = {FOREACH_ERROR(GENERATE_STRING)};
+ if (errorcode < 0 || static_cast<size_t>(errorcode) >= smpi_error_string.size() || string == nullptr)
return MPI_ERR_ARG;
int len = snprintf(string, MPI_MAX_ERROR_STRING, "%s", smpi_error_string[errorcode]);