-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add fortran interface for mount and unmount
- Loading branch information
Showing
4 changed files
with
178 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
/* | ||
* Copyright (c) 2017, Lawrence Livermore National Security, LLC. | ||
* Produced at the Lawrence Livermore National Laboratory. | ||
* | ||
* Copyright 2017-2019, UT-Battelle, LLC. | ||
* | ||
* LLNL-CODE-741539 | ||
* All rights reserved. | ||
* | ||
* This is the license for UnifyCR. | ||
* For details, see https://github.com/LLNL/UnifyCR. | ||
* Please read https://github.com/LLNL/UnifyCR/LICENSE for full license text. | ||
*/ | ||
|
||
/* This file compiles a normalized interface for Fortran in which: | ||
* - Fortran link names are in lower case | ||
* - Fortran link names have a single trailing underscore | ||
* - boolean true is expected to be 1 | ||
*/ | ||
|
||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#include "unifycr.h" | ||
|
||
/* TODO: enable UNIFYCR_Fint to be configured to be different type */ | ||
typedef int UNIFYCR_Fint; | ||
|
||
#ifdef USE_FORT_STDCALL | ||
# define FORT_CALL __stdcall | ||
#elif defined (USE_FORT_CDECL) | ||
# define FORT_CALL __cdecl | ||
#else | ||
# define FORT_CALL | ||
#endif | ||
|
||
#ifdef USE_FORT_MIXED_STR_LEN | ||
# define FORT_MIXED_LEN_DECL , UNIFYCR_Fint | ||
# define FORT_END_LEN_DECL | ||
# define FORT_MIXED_LEN(a) , UNIFYCR_Fint a | ||
# define FORT_END_LEN(a) | ||
#else | ||
# define FORT_MIXED_LEN_DECL | ||
# define FORT_END_LEN_DECL , UNIFYCR_Fint | ||
# define FORT_MIXED_LEN(a) | ||
# define FORT_END_LEN(a) , UNIFYCR_Fint a | ||
#endif | ||
|
||
#ifdef HAVE_FORTRAN_API | ||
# ifdef FORTRAN_EXPORTS | ||
# define FORTRAN_API __declspec(dllexport) | ||
# else | ||
# define FORTRAN_API __declspec(dllimport) | ||
# endif | ||
#else | ||
# define FORTRAN_API | ||
#endif | ||
|
||
/* convert a Fortran string to a C string, removing any trailing spaces and terminating with a NULL */ | ||
static int unifycr_fstr2cstr(const char* fstr, int flen, char* cstr, int clen) | ||
{ | ||
int rc = 0; | ||
|
||
/* check that our pointers aren't NULL */ | ||
if (fstr == NULL || cstr == NULL) { | ||
return 1; | ||
} | ||
|
||
/* determine length of Fortran string after subtracting any trailing spaces */ | ||
while (flen > 0 && fstr[flen-1] == ' ') { | ||
flen--; | ||
} | ||
|
||
/* assume we can copy the whole string */ | ||
int len = flen; | ||
if (flen > clen - 1) { | ||
/* Fortran string is longer than C buffer, copy what we can and truncate */ | ||
len = clen - 1; | ||
rc = 1; | ||
} | ||
|
||
/* copy the Fortran string to the C string */ | ||
if (len > 0) { | ||
strncpy(cstr, fstr, len); | ||
} | ||
|
||
/* null-terminate the C string */ | ||
if (len >= 0) { | ||
cstr[len] = '\0'; | ||
} | ||
|
||
return rc; | ||
} | ||
|
||
/* convert a C string to a Fortran string, adding trailing spaces if necessary */ | ||
static int unifycr_cstr2fstr(const char* cstr, char* fstr, int flen) | ||
{ | ||
int rc = 0; | ||
|
||
/* check that our pointers aren't NULL */ | ||
if (cstr == NULL || fstr == NULL) { | ||
return 1; | ||
} | ||
|
||
/* determine length of C string */ | ||
int clen = strlen(cstr); | ||
|
||
/* copy the characters from the Fortran string to the C string */ | ||
if (clen <= flen) { | ||
/* C string will fit within our Fortran buffer, copy it over */ | ||
if (clen > 0) { | ||
strncpy(fstr, cstr, clen); | ||
} | ||
|
||
/* fill in trailing spaces */ | ||
while (clen < flen) { | ||
fstr[clen] = ' '; | ||
clen++; | ||
} | ||
} else { | ||
/* C string is longer than our Fortran buffer, copy what we can then truncate */ | ||
strncpy(fstr, cstr, flen); | ||
rc = 1; | ||
} | ||
|
||
return rc; | ||
} | ||
|
||
/*================================================ | ||
* Init, Finalize, Exit | ||
*================================================*/ | ||
|
||
FORTRAN_API void FORT_CALL unifycr_mount_(char* prefix FORT_MIXED_LEN(prefix_len), int* rank, int* size, int* app_id, int* ierror FORT_END_LEN(prefix_len)) | ||
{ | ||
/* convert name from a Fortran string to C string */ | ||
char prefix_tmp[1024]; | ||
if (unifycr_fstr2cstr(prefix, prefix_len, prefix_tmp, sizeof(prefix_tmp)) != 0) { | ||
*ierror = 1; // !UNIFYCR_SUCCESS | ||
return; | ||
} | ||
|
||
int rank_tmp = *rank; | ||
int size_tmp = *size; | ||
int app_id_tmp = *app_id; | ||
*ierror = unifycr_mount(prefix_tmp, rank_tmp, size_tmp, app_id_tmp); | ||
|
||
return; | ||
} | ||
|
||
FORTRAN_API void FORT_CALL unifycr_unmount_(int* ierror) | ||
{ | ||
*ierror = unifycr_unmount(); | ||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
! Copyright (c) 2017, Lawrence Livermore National Security, LLC. | ||
! Produced at the Lawrence Livermore National Laboratory. | ||
! | ||
! Copyright 2017-2019, UT-Battelle, LLC. | ||
! | ||
! LLNL-CODE-741539 | ||
! All rights reserved. | ||
! | ||
! This is the license for UnifyCR. | ||
! For details, see https://github.com/LLNL/UnifyCR. | ||
! Please read https://github.com/LLNL/UnifyCR/LICENSE for full license text. | ||
! | ||
! return codes | ||
INTEGER UNIFYCR_SUCCESS | ||
PARAMETER (UNIFYCR_SUCCESS=0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters