Skip to content

Commit

Permalink
add fortran interface for mount and unmount
Browse files Browse the repository at this point in the history
  • Loading branch information
adammoody committed Apr 3, 2019
1 parent 24c254e commit 5e08823
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 2 deletions.
8 changes: 6 additions & 2 deletions client/src/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
lib_LTLIBRARIES = libunifycr.la libunifycr_gotcha.la
lib_LTLIBRARIES = libunifycr.la libunifycr_gotcha.la libunifycrf.la

libunifycrdir = $(includedir)
libunifycr_gotchadir = $(includedir)

AM_CFLAGS = -Wall -Wno-strict-aliasing

include_HEADERS = unifycr.h
include_HEADERS = unifycr.h unifycrf.h

CLIENT_COMMON_CPPFLAGS = \
-I$(top_builddir)/client \
Expand Down Expand Up @@ -68,3 +68,7 @@ libunifycr_gotcha_la_CFLAGS = $(CLIENT_COMMON_CFLAGS) $(GOTCHA_CFLAGS)
libunifycr_gotcha_la_LDFLAGS = $(CLIENT_COMMON_LDFLAGS) $(GOTCHA_LDFLAGS)
libunifycr_gotcha_la_LIBADD = $(CLIENT_COMMON_LIBADD) -lgotcha

libunifycrf_la_SOURCES = unifycrf.c
libunifycrf_la_CPPFLAGS = $(CLIENT_COMMON_CPPFLAGS)
libunifycrf_la_CFLAGS = $(AM_CFLAGS) $(CLIENT_COMMON_CFLAGS)
libunifycrf_la_LIBADD = libunifycr_gotcha.la
155 changes: 155 additions & 0 deletions client/src/unifycrf.c
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;
}
15 changes: 15 additions & 0 deletions client/src/unifycrf.h
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)
2 changes: 2 additions & 0 deletions common/src/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
lib_LTLIBRARIES = libunifycr_common.la

include_HEADERS = unifycr_const.h err_enumerator.h

libunifycr_commondir = $(includedir)

BASE_SRCS = \
Expand Down

0 comments on commit 5e08823

Please sign in to comment.