X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/8d3d351ba5e9cb4c4aaa92c56420a6d29d27d1ce..e303bc683c874808621082e409ec13bcc1b17247:/src/smpi/smpi_global.cpp?ds=sidebyside diff --git a/src/smpi/smpi_global.cpp b/src/smpi/smpi_global.cpp index aad63d8f26..25518210f0 100644 --- a/src/smpi/smpi_global.cpp +++ b/src/smpi/smpi_global.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -38,6 +37,10 @@ #include #include +#if HAVE_SENDFILE +#include +#endif + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_kernel, smpi, "Logging specific to SMPI (kernel)"); #include #include /* trim_right / trim_left */ @@ -543,7 +546,28 @@ int smpi_main(const char* executable, int argc, char *argv[]) int fdout = open(target_executable.c_str(), O_WRONLY); xbt_assert(fdout >= 0, "Cannot write into %s", target_executable.c_str()); +#if HAVE_SENDFILE sendfile(fdout, fdin, NULL, fdin_size); +#else + const int bufsize = 1024 * 1024 * 4; + char buf[bufsize]; + while (int got = read(fdin, buf, bufsize)) { + if (got == -1) { + xbt_assert(errno == EINTR, "Cannot read from %s", executable_copy.c_str()); + } else { + char* p = buf; + int todo = got; + while (int done = write(fdout, p, todo)) { + if (done == -1) { + xbt_assert(errno == EINTR, "Cannot write into %s", target_executable.c_str()); + } else { + p += done; + todo -= done; + } + } + } + } +#endif close(fdout); // Load the copy and resolve the entry point: