Commit 304ce17e authored by Kim, Jungwon's avatar Kim, Jungwon

Merge branch 'develop' into 'master'

Add Fortran 90 Binding

See merge request !2
parents 30ee861f b425f34f
......@@ -6,17 +6,28 @@ set(PAPYRUS_VERSION_MAJOR 1)
set(PAPYRUS_VERSION_MINOR 0)
set(PAPYRUS_VERSION_PATCH 0)
set(PAPYRUS_USE_FORTRAN OFF CACHE BOOL "Enable support for Fortran 90")
option(PAPYRUS_BUILD_WITH_SPACK "Bulid with Spack" OFF)
if(PAPYRUS_USE_FORTRAN)
enable_language(Fortran)
endif()
find_package(MPI REQUIRED)
MESSAGE (STATUS "MPI_CXX_COMPILER ${MPI_CXX_COMPILER}")
MESSAGE (STATUS "MPI_C_COMPILER ${MPI_C_COMPILER}")
if ("${MPI_C_COMPILER}" STREQUAL "MPI_C_COMPILER-NOTFOUND")
else()
MESSAGE (STATUS "MPI_Fortran_COMPILER ${MPI_Fortran_COMPILER}")
if (NOT "${MPI_C_COMPILER}" STREQUAL "MPI_C_COMPILER-NOTFOUND")
set(CMAKE_C_COMPILER "${MPI_C_COMPILER}")
endif()
if ("${MPI_CXX_COMPILER}" STREQUAL "MPI_CXX_COMPILER-NOTFOUND")
else()
if (NOT "${MPI_CXX_COMPILER}" STREQUAL "MPI_CXX_COMPILER-NOTFOUND")
set(CMAKE_CXX_COMPILER "${MPI_CXX_COMPILER}")
endif()
if (NOT "${MPI_Fortran_COMPILER}" STREQUAL "MPI_Fortran_COMPILER-NOTFOUND")
set(CMAKE_Fortran_COMPILER "${MPI_Fortran_COMPILER}")
endif()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
......
......@@ -2,5 +2,6 @@
rm -rf build install
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=../install -DMPIEXEC="/opt/intel/compilers_and_libraries_2017.4.196/linux/mpi/intel64/bin/mpirun" -DMPIEXEC_NUMPROC_FLAG="-n"
#cmake .. -DCMAKE_INSTALL_PREFIX=../install -DMPIEXEC="/opt/intel/compilers_and_libraries_2017.4.196/linux/mpi/intel64/bin/mpirun" -DMPIEXEC_NUMPROC_FLAG="-n" # Stampede2
cmake .. -DCMAKE_INSTALL_PREFIX=../install -DMPIEXEC="/opt/slurm/default/bin/srun" -DMPIEXEC_NUMPROC_FLAG="-n" -DPAPYRUS_USE_FORTRAN=ON #Grand Tave
make -j install
......@@ -53,7 +53,7 @@ extern int papyruskv_put(int db, const char* key, size_t keylen, const char* val
extern int papyruskv_get(int db, const char* key, size_t keylen, char** val, size_t* vallen);
extern int papyruskv_get_pos(int db, const char* key, size_t keylen, char** val, size_t* vallen, papyruskv_pos_t* pos);
extern int papyruskv_delete(int db, const char* key, size_t keylen);
extern int papyruskv_free(void* val);
extern int papyruskv_free(char** val);
extern int papyruskv_fence(int db, int level);
extern int papyruskv_barrier(int db, int level);
extern int papyruskv_signal_notify(int signum, int* ranks, int count);
......
add_subdirectory(src)
if(NOT PAPYRUS_BUILD_WITH_SPACK)
add_subdirectory(tests)
endif()
add_subdirectory(bin)
......@@ -36,7 +36,7 @@ int papyruskv_delete(int db, const char* key, size_t keylen) {
return Platform::GetPlatform()->Delete(db, key, keylen);
}
int papyruskv_free(void* val) {
int papyruskv_free(char** val) {
return Platform::GetPlatform()->Free(val);
}
......
include_directories(${PROJECT_SOURCE_DIR}/include)
add_library(papyruskv
set(PAPYRUSKV_SOURCES
Bloom.cpp
CAPI.cpp
Cache.cpp
......@@ -22,4 +22,17 @@ add_library(papyruskv
Timer.cpp
)
if(PAPYRUS_USE_FORTRAN)
set(PAPYRUSKV_SOURCES ${PAPYRUSKV_SOURCES}
C_Binding.f90
)
set(CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/include)
endif()
add_library(papyruskv ${PAPYRUSKV_SOURCES})
install(TARGETS papyruskv DESTINATION lib)
if(PAPYRUS_USE_FORTRAN)
install(FILES ${PROJECT_BINARY_DIR}/include/papyrus.mod DESTINATION include)
endif()
MODULE PAPYRUS
USE, INTRINSIC :: ISO_C_BINDING
IMPLICIT NONE
INTEGER, PARAMETER :: PAPYRUSKV_OK = 0
INTEGER, PARAMETER :: PAPYRUSKV_ERR = -1
INTEGER, PARAMETER :: PAPYRUSKV_MEMTABLE = LSHIFT(1, 0)
INTEGER, PARAMETER :: PAPYRUSKV_SSTABLE = LSHIFT(1, 1)
INTEGER, PARAMETER :: PAPYRUSKV_SEQUENTIAL = LSHIFT(1, 0)
INTEGER, PARAMETER :: PAPYRUSKV_RELAXED = LSHIFT(1, 1)
INTEGER, PARAMETER :: PAPYRUSKV_CREATE = LSHIFT(1, 2)
INTEGER, PARAMETER :: PAPYRUSKV_RDWR = LSHIFT(1, 3)
INTEGER, PARAMETER :: PAPYRUSKV_WRONLY = LSHIFT(1, 4)
INTEGER, PARAMETER :: PAPYRUSKV_RDONLY = LSHIFT(1, 5)
INTEGER, PARAMETER :: PAPYRUSKV_UDONLY = LSHIFT(1, 6)
INTERFACE
INTEGER(C_INT) FUNCTION PAPYRUSKV_INIT_CBIND(ARGC, ARGV, REPOSITORY) &
BIND(C, NAME='papyruskv_init')
USE, INTRINSIC :: ISO_C_BINDING
INTEGER(C_INT), VALUE, INTENT(IN) :: ARGC
CHARACTER(C_CHAR), DIMENSION(*), INTENT(IN) :: ARGV
CHARACTER(C_CHAR), DIMENSION(*), INTENT(IN) :: REPOSITORY
END FUNCTION PAPYRUSKV_INIT_CBIND
INTEGER(C_INT) FUNCTION PAPYRUSKV_FINALIZE_CBIND() &
BIND(C, NAME='papyruskv_finalize')
USE, INTRINSIC :: ISO_C_BINDING
END FUNCTION PAPYRUSKV_FINALIZE_CBIND
INTEGER(C_INT) FUNCTION PAPYRUSKV_OPEN_CBIND(NAME, FLAGS, OPT, DB) &
BIND(C, NAME='papyruskv_open')
USE, INTRINSIC :: ISO_C_BINDING
CHARACTER(C_CHAR), DIMENSION(*), INTENT(IN) :: NAME
INTEGER(C_INT), VALUE, INTENT(IN) :: FLAGS
TYPE(C_PTR), VALUE, INTENT(IN) :: OPT
INTEGER(C_INT), INTENT(OUT) :: DB
END FUNCTION PAPYRUSKV_OPEN_CBIND
INTEGER(C_INT) FUNCTION PAPYRUSKV_CLOSE_CBIND(DB) &
BIND(C, NAME='papyruskv_close')
USE, INTRINSIC :: ISO_C_BINDING
INTEGER(C_INT), VALUE, INTENT(IN) :: DB
END FUNCTION PAPYRUSKV_CLOSE_CBIND
INTEGER(C_INT) FUNCTION PAPYRUSKV_PUT_CBIND(DB, KEY, KEYLEN, VAL, VALLEN) &
BIND(C, NAME='papyruskv_put')
USE, INTRINSIC :: ISO_C_BINDING
INTEGER(C_INT), VALUE, INTENT(IN) :: DB
CHARACTER(C_CHAR), DIMENSION(*), INTENT(IN) :: KEY
INTEGER(C_SIZE_T), VALUE, INTENT(IN) :: KEYLEN
CHARACTER(C_CHAR), DIMENSION(*), INTENT(IN) :: VAL
INTEGER(C_SIZE_T), VALUE, INTENT(IN) :: VALLEN
END FUNCTION PAPYRUSKV_PUT_CBIND
INTEGER(C_INT) FUNCTION PAPYRUSKV_GET_CBIND(DB, KEY, KEYLEN, VAL, VALLEN) &
BIND(C, NAME='papyruskv_get')
USE, INTRINSIC :: ISO_C_BINDING
INTEGER(C_INT), VALUE, INTENT(IN) :: DB
CHARACTER(C_CHAR), DIMENSION(*), INTENT(IN) :: KEY
INTEGER(C_SIZE_T), VALUE, INTENT(IN) :: KEYLEN
TYPE(C_PTR), INTENT(OUT) :: VAL
INTEGER(C_SIZE_T), INTENT(OUT) :: VALLEN
END FUNCTION PAPYRUSKV_GET_CBIND
INTEGER(C_INT) FUNCTION PAPYRUSKV_DELETE_CBIND(DB, KEY, KEYLEN) &
BIND(C, NAME='papyruskv_delete')
USE, INTRINSIC :: ISO_C_BINDING
INTEGER(C_INT), VALUE, INTENT(IN) :: DB
CHARACTER(C_CHAR), DIMENSION(*), INTENT(IN) :: KEY
INTEGER(C_SIZE_T), VALUE, INTENT(IN) :: KEYLEN
END FUNCTION PAPYRUSKV_DELETE_CBIND
INTEGER(C_INT) FUNCTION PAPYRUSKV_FREE_CBIND(VAL) &
BIND(C, NAME='papyruskv_free')
USE, INTRINSIC :: ISO_C_BINDING
TYPE(C_PTR), INTENT(IN) :: VAL
END FUNCTION PAPYRUSKV_FREE_CBIND
INTEGER(C_INT) FUNCTION PAPYRUSKV_FENCE_CBIND(DB, LEVEL) &
BIND(C, NAME='papyruskv_fence')
USE, INTRINSIC :: ISO_C_BINDING
INTEGER(C_INT), VALUE, INTENT(IN) :: DB
INTEGER(C_INT), VALUE, INTENT(IN) :: LEVEL
END FUNCTION PAPYRUSKV_FENCE_CBIND
INTEGER(C_INT) FUNCTION PAPYRUSKV_BARRIER_CBIND(DB, LEVEL) &
BIND(C, NAME='papyruskv_barrier')
USE, INTRINSIC :: ISO_C_BINDING
INTEGER(C_INT), VALUE, INTENT(IN) :: DB
INTEGER(C_INT), VALUE, INTENT(IN) :: LEVEL
END FUNCTION PAPYRUSKV_BARRIER_CBIND
INTEGER(C_INT) FUNCTION PAPYRUSKV_SIGNAL_NOTIFY_CBIND(SIGNUM, RANKS, COUNT) &
BIND(C, NAME='papyruskv_signal_notify')
USE, INTRINSIC :: ISO_C_BINDING
INTEGER(C_INT), VALUE, INTENT(IN) :: SIGNUM
INTEGER(C_INT), DIMENSION(*), INTENT(IN) :: RANKS
INTEGER(C_INT), VALUE, INTENT(IN) :: COUNT
END FUNCTION PAPYRUSKV_SIGNAL_NOTIFY_CBIND
INTEGER(C_INT) FUNCTION PAPYRUSKV_SIGNAL_WAIT_CBIND(SIGNUM, RANKS, COUNT) &
BIND(C, NAME='papyruskv_signal_wait')
USE, INTRINSIC :: ISO_C_BINDING
INTEGER(C_INT), VALUE, INTENT(IN) :: SIGNUM
INTEGER(C_INT), DIMENSION(*), INTENT(IN) :: RANKS
INTEGER(C_INT), VALUE, INTENT(IN) :: COUNT
END FUNCTION PAPYRUSKV_SIGNAL_WAIT_CBIND
INTEGER(C_INT) FUNCTION PAPYRUSKV_CONSISTENCY_CBIND(DB, CONSISTENCY) &
BIND(C, NAME='papyruskv_consistency')
USE, INTRINSIC :: ISO_C_BINDING
INTEGER(C_INT), VALUE, INTENT(IN) :: DB
INTEGER(C_INT), VALUE, INTENT(IN) :: CONSISTENCY
END FUNCTION PAPYRUSKV_CONSISTENCY_CBIND
INTEGER(C_INT) FUNCTION PAPYRUSKV_PROTECT_CBIND(DB, PROT) &
BIND(C, NAME='papyruskv_protect')
USE, INTRINSIC :: ISO_C_BINDING
INTEGER(C_INT), VALUE, INTENT(IN) :: DB
INTEGER(C_INT), VALUE, INTENT(IN) :: PROT
END FUNCTION PAPYRUSKV_PROTECT_CBIND
INTEGER(C_INT) FUNCTION PAPYRUSKV_DESTROY_CBIND(DB, EVENT) &
BIND(C, NAME='papyruskv_destroy')
USE, INTRINSIC :: ISO_C_BINDING
INTEGER(C_INT), VALUE, INTENT(IN) :: DB
INTEGER(C_INT), INTENT(OUT) :: EVENT
END FUNCTION PAPYRUSKV_DESTROY_CBIND
INTEGER(C_INT) FUNCTION PAPYRUSKV_CHECKPOINT_CBIND(DB, PATH, EVENT) &
BIND(C, NAME='papyruskv_checkpoint')
USE, INTRINSIC :: ISO_C_BINDING
INTEGER(C_INT), VALUE, INTENT(IN) :: DB
CHARACTER(C_CHAR), DIMENSION(*), INTENT(IN) :: PATH
INTEGER(C_INT), INTENT(OUT) :: EVENT
END FUNCTION PAPYRUSKV_CHECKPOINT_CBIND
INTEGER(C_INT) FUNCTION PAPYRUSKV_RESTART_CBIND(PATH, NAME, FLAGS, OPT, DB, EVENT) &
BIND(C, NAME='papyruskv_restart')
USE, INTRINSIC :: ISO_C_BINDING
CHARACTER(C_CHAR), DIMENSION(*), INTENT(IN) :: PATH
CHARACTER(C_CHAR), DIMENSION(*), INTENT(IN) :: NAME
INTEGER(C_INT), VALUE, INTENT(IN) :: FLAGS
TYPE(C_PTR), VALUE, INTENT(IN) :: OPT
INTEGER(C_INT), INTENT(OUT) :: DB
INTEGER(C_INT), INTENT(OUT) :: EVENT
END FUNCTION PAPYRUSKV_RESTART_CBIND
INTEGER(C_INT) FUNCTION PAPYRUSKV_WAIT_CBIND(DB, EVENT) &
BIND(C, NAME='papyruskv_wait')
USE, INTRINSIC :: ISO_C_BINDING
INTEGER(C_INT), VALUE, INTENT(IN) :: DB
INTEGER(C_INT), VALUE, INTENT(IN) :: EVENT
END FUNCTION PAPYRUSKV_WAIT_CBIND
END INTERFACE
CONTAINS
SUBROUTINE PAPYRUSKV_INIT(REPOSITORY, IERROR)
CHARACTER, DIMENSION(*), INTENT(IN) :: REPOSITORY
INTEGER, INTENT(OUT) :: IERROR
CHARACTER, POINTER :: ARGV(:)
IERROR = PAPYRUSKV_INIT_CBIND(0, ARGV, REPOSITORY)
END SUBROUTINE PAPYRUSKV_INIT
SUBROUTINE PAPYRUSKV_FINALIZE(IERROR)
INTEGER, INTENT(OUT) :: IERROR
IERROR = PAPYRUSKV_FINALIZE_CBIND()
END SUBROUTINE PAPYRUSKV_FINALIZE
SUBROUTINE PAPYRUSKV_OPEN(NAME, FLAGS, DB, IERROR)
CHARACTER, DIMENSION(*), INTENT(IN) :: NAME
INTEGER, INTENT(IN) :: FLAGS
INTEGER, INTENT(OUT) :: DB
INTEGER, INTENT(OUT) :: IERROR
TYPE(C_PTR) :: OPT
OPT = C_NULL_PTR
IERROR = PAPYRUSKV_OPEN_CBIND(NAME, FLAGS, OPT, DB)
END SUBROUTINE PAPYRUSKV_OPEN
SUBROUTINE PAPYRUSKV_CLOSE(DB, IERROR)
INTEGER, INTENT(IN) :: DB
INTEGER, INTENT(OUT) :: IERROR
IERROR = PAPYRUSKV_CLOSE_CBIND(DB)
END SUBROUTINE PAPYRUSKV_CLOSE
SUBROUTINE PAPYRUSKV_PUT(DB, KEY, KEYLEN, VAL, VALLEN, IERROR)
INTEGER, INTENT(IN) :: DB
CHARACTER, DIMENSION(*), INTENT(IN) :: KEY
INTEGER(KIND=8), INTENT(IN) :: KEYLEN
CHARACTER, DIMENSION(*), INTENT(IN) :: VAL
INTEGER(KIND=8), INTENT(IN) :: VALLEN
INTEGER, INTENT(OUT) :: IERROR
IERROR = PAPYRUSKV_PUT_CBIND(DB, KEY, KEYLEN, VAL, VALLEN)
END SUBROUTINE PAPYRUSKV_PUT
SUBROUTINE PAPYRUSKV_GET(DB, KEY, KEYLEN, VAL, VALLEN, IERROR)
INTEGER, INTENT(IN) :: DB
CHARACTER, DIMENSION(*), INTENT(IN) :: KEY
INTEGER(KIND=8), INTENT(IN) :: KEYLEN
CHARACTER, POINTER, INTENT(OUT) :: VAL(:)
INTEGER(KIND=8), INTENT(OUT) :: VALLEN
INTEGER, INTENT(OUT) :: IERROR
TYPE(C_PTR) :: VAL_CPTR
LOGICAL :: VAL_NULL_PTR
IF (ASSOCIATED(VAL)) THEN
VAL_CPTR = C_LOC(VAL)
VAL_NULL_PTR = .FALSE.
ELSE
VAL_CPTR = C_NULL_PTR
VAL_NULL_PTR = .TRUE.
END IF
IERROR = PAPYRUSKV_GET_CBIND(DB, KEY, KEYLEN, VAL_CPTR, VALLEN)
IF (VAL_NULL_PTR) THEN
CALL C_F_POINTER(VAL_CPTR, VAL, [VALLEN])
END IF
END SUBROUTINE PAPYRUSKV_GET
SUBROUTINE PAPYRUSKV_DELETE(DB, KEY, KEYLEN, IERROR)
INTEGER, INTENT(IN) :: DB
CHARACTER, DIMENSION(*), INTENT(IN) :: KEY
INTEGER(KIND=8), INTENT(IN) :: KEYLEN
INTEGER, INTENT(OUT) :: IERROR
IERROR = PAPYRUSKV_DELETE_CBIND(DB, KEY, KEYLEN)
END SUBROUTINE PAPYRUSKV_DELETE
SUBROUTINE PAPYRUSKV_FREE(VAL, IERROR)
CHARACTER, POINTER, INTENT(INOUT) :: VAL(:)
INTEGER, INTENT(OUT) :: IERROR
TYPE(C_PTR) :: VAL_CPTR
VAL_CPTR = C_LOC(VAL)
IERROR = PAPYRUSKV_FREE_CBIND(VAL_CPTR)
NULLIFY(VAL)
END SUBROUTINE PAPYRUSKV_FREE
SUBROUTINE PAPYRUSKV_FENCE(DB, LEVEL, IERROR)
INTEGER, INTENT(IN) :: DB
INTEGER, INTENT(IN) :: LEVEL
INTEGER, INTENT(OUT) :: IERROR
IERROR = PAPYRUSKV_FENCE_CBIND(DB, LEVEL)
END SUBROUTINE PAPYRUSKV_FENCE
SUBROUTINE PAPYRUSKV_BARRIER(DB, LEVEL, IERROR)
INTEGER, INTENT(IN) :: DB
INTEGER, INTENT(IN) :: LEVEL
INTEGER, INTENT(OUT) :: IERROR
IERROR = PAPYRUSKV_BARRIER_CBIND(DB, LEVEL)
END SUBROUTINE PAPYRUSKV_BARRIER
SUBROUTINE PAPYRUSKV_SIGNAL_NOTIFY(SIGNUM, RANKS, COUNT, IERROR)
INTEGER, INTENT(IN) :: SIGNUM
INTEGER, DIMENSION(*), INTENT(IN) :: RANKS
INTEGER, INTENT(IN) :: COUNT
INTEGER, INTENT(OUT) :: IERROR
IERROR = PAPYRUSKV_SIGNAL_NOTIFY_CBIND(SIGNUM, RANKS, COUNT)
END SUBROUTINE PAPYRUSKV_SIGNAL_NOTIFY
SUBROUTINE PAPYRUSKV_SIGNAL_WAIT(SIGNUM, RANKS, COUNT, IERROR)
INTEGER, INTENT(IN) :: SIGNUM
INTEGER, DIMENSION(*), INTENT(IN) :: RANKS
INTEGER, INTENT(IN) :: COUNT
INTEGER, INTENT(OUT) :: IERROR
IERROR = PAPYRUSKV_SIGNAL_WAIT_CBIND(SIGNUM, RANKS, COUNT)
END SUBROUTINE PAPYRUSKV_SIGNAL_WAIT
SUBROUTINE PAPYRUSKV_CONSISTENCY(DB, CONSISTENCY, IERROR)
INTEGER, INTENT(IN) :: DB
INTEGER, INTENT(IN) :: CONSISTENCY
INTEGER, INTENT(OUT) :: IERROR
IERROR = PAPYRUSKV_CONSISTENCY_CBIND(DB, CONSISTENCY)
END SUBROUTINE PAPYRUSKV_CONSISTENCY
SUBROUTINE PAPYRUSKV_PROTECT(DB, PROTECT, IERROR)
INTEGER, INTENT(IN) :: DB
INTEGER, INTENT(IN) :: PROTECT
INTEGER, INTENT(OUT) :: IERROR
IERROR = PAPYRUSKV_PROTECT_CBIND(DB, PROTECT)
END SUBROUTINE PAPYRUSKV_PROTECT
SUBROUTINE PAPYRUSKV_DESTROY(DB, EVENT, IERROR)
INTEGER, INTENT(IN) :: DB
INTEGER, INTENT(OUT) :: EVENT
INTEGER, INTENT(OUT) :: IERROR
IERROR = PAPYRUSKV_DESTROY_CBIND(DB, EVENT)
END SUBROUTINE PAPYRUSKV_DESTROY
SUBROUTINE PAPYRUSKV_CHECKPOINT(DB, PATH, EVENT, IERROR)
INTEGER, INTENT(IN) :: DB
CHARACTER, DIMENSION(*), INTENT(IN) :: PATH
INTEGER, INTENT(OUT) :: EVENT
INTEGER, INTENT(OUT) :: IERROR
IERROR = PAPYRUSKV_CHECKPOINT_CBIND(DB, PATH, EVENT)
END SUBROUTINE PAPYRUSKV_CHECKPOINT
SUBROUTINE PAPYRUSKV_RESTART(PATH, NAME, FLAGS, DB, EVENT, IERROR)
CHARACTER, DIMENSION(*), INTENT(IN) :: PATH
CHARACTER, DIMENSION(*), INTENT(IN) :: NAME
INTEGER, INTENT(IN) :: FLAGS
INTEGER, INTENT(OUT) :: DB
INTEGER, INTENT(OUT) :: EVENT
INTEGER, INTENT(OUT) :: IERROR
TYPE(C_PTR) :: OPT
OPT = C_NULL_PTR
IERROR = PAPYRUSKV_RESTART_CBIND(PATH, NAME, FLAGS, OPT, DB, EVENT)
END SUBROUTINE PAPYRUSKV_RESTART
SUBROUTINE PAPYRUSKV_WAIT(DB, EVENT, IERROR)
INTEGER, INTENT(IN) :: DB
INTEGER, INTENT(IN) :: EVENT
INTEGER, INTENT(OUT) :: IERROR
IERROR = PAPYRUSKV_WAIT_CBIND(DB, EVENT)
END SUBROUTINE PAPYRUSKV_WAIT
END MODULE PAPYRUS
......@@ -156,7 +156,7 @@ int Platform::Delete(int dbid, const char* key, size_t keylen) {
return GetDB(dbid)->Delete(key, keylen);
}
int Platform::Free(void* val) {
int Platform::Free(char** val) {
pool_->FreeVal(val);
return PAPYRUSKV_OK;
}
......
......@@ -26,7 +26,7 @@ public:
int Put(int dbid, const char* key, size_t keylen, const char* val, size_t vallen);
int Get(int dbid, const char* key, size_t keylen, char** val, size_t* vallen, papyruskv_pos_t* pos);
int Delete(int dbid, const char* key, size_t keylen);
int Free(void* val);
int Free(char** val);
int Fence(int dbid, int level);
int Barrier(int dbid, int level);
int SignalNotify(int signum, int* ranks, int count);
......
......@@ -14,8 +14,9 @@ char* Pool::AllocVal(size_t vallen) {
return new char[vallen];
}
void Pool::FreeVal(void* val) {
delete[] reinterpret_cast<char *>(val);
void Pool::FreeVal(char** val) {
delete[] *val;
*val = NULL;
}
} /* namespace papyruskv */
......@@ -13,7 +13,7 @@ public:
~Pool();
char* AllocVal(size_t vallen);
void FreeVal(void* val);
void FreeVal(char** val);
private:
Platform* platform_;
......
......@@ -49,7 +49,7 @@ int main(int argc, char** argv) {
else printf("[%s:%d] GET:rank[%d] peer[%d] key[%s] value[%s] vallen[%lu]\n", __FILE__, __LINE__, rank, peer, k[peer], val, vallen);
}
if (val) ret = papyruskv_free(val);
if (val) ret = papyruskv_free(&val);
if (ret != PAPYRUSKV_OK) printf("[%s:%d] ERROR:ret[%d] val[%p]\n", __FILE__, __LINE__, ret, val);
ret = papyruskv_close(db);
......
papyruskv_test_fortran(test14_fortran)
PROGRAM TEST14_FORTRAN
USE MPI
USE PAPYRUS
IMPLICIT NONE
INTEGER :: RANK, NRANKS, IERROR, PROVIDED, PEER, DB
CHARACTER, DIMENSION(4) :: KEY * 32
CHARACTER, DIMENSION(4) :: VAL * 256
CHARACTER, POINTER :: VAL1(:)
CHARACTER, POINTER :: VAL2(:)
INTEGER(KIND=8) :: KEYLEN, VALLEN
CALL MPI_INIT_THREAD(MPI_THREAD_MULTIPLE, PROVIDED, IERROR)
CALL PAPYRUSKV_INIT('./pkv_repo', IERROR)
IF (IERROR /= PAPYRUSKV_OK) THEN
PRINT*, 'FAILED'
ENDIF
CALL MPI_COMM_RANK(MPI_COMM_WORLD, RANK, IERROR)
CALL MPI_COMM_SIZE(MPI_COMM_WORLD, NRANKS, IERROR)
KEY(1) = 'GOOGLE'
KEY(2) = 'FACEBOOK'
KEY(3) = 'TWITTER'
KEY(4) = 'PAPYRUS'
VAL(1) = 'https://google.com'
VAL(2) = 'https://facebook.com'
VAL(3) = 'https://twitter.com'
VAL(4) = 'https://code.ornl.gov/eck/papyrus'
ALLOCATE(VAL1(256))
NULLIFY(VAL2)
IF (RANK == NRANKS - 1) THEN
PEER = 0
ELSE
PEER = RANK + 1
ENDIF
CALL PAPYRUSKV_OPEN('TEST_DB', PAPYRUSKV_CREATE .OR. PAPYRUSKV_RDWR, DB, IERROR)
IF (IERROR /= PAPYRUSKV_OK) THEN
PRINT*, 'FAILED'
ENDIF
IF (RANK < SIZE(KEY)) THEN
PRINT*, 'PUT --> RANK', RANK, 'KEY:', TRIM(KEY(RANK + 1)), ' VAL:', TRIM(VAL(RANK + 1))
KEYLEN = LEN(TRIM(KEY(RANK + 1)), KIND = 8)
VALLEN = LEN(TRIM(VAL(RANK + 1)), KIND = 8)
CALL PAPYRUSKV_PUT(DB, TRIM(KEY(RANK + 1)), KEYLEN, TRIM(VAL(RANK + 1)), VALLEN, IERROR)
IF (IERROR /= PAPYRUSKV_OK) THEN
PRINT*, 'FAILED'
ENDIF
END IF
CALL PAPYRUSKV_BARRIER(DB, PAPYRUSKV_MEMTABLE, IERROR)
IF (IERROR /= PAPYRUSKV_OK) THEN
PRINT*, 'FAILED'
ENDIF
IF (RANK < SIZE(KEY)) THEN
CALL PAPYRUSKV_GET(DB, TRIM(KEY(RANK + 1)), KEYLEN, VAL1, VALLEN, IERROR)
IF (IERROR /= PAPYRUSKV_OK) THEN
PRINT*, 'FAILED'
ENDIF
PRINT*, 'GET--> RANK', RANK, 'KEY:', TRIM(KEY(RANK + 1)), ' VAL:', VAL1(1: VALLEN)
CALL PAPYRUSKV_GET(DB, TRIM(KEY(RANK + 1)), KEYLEN, VAL2, VALLEN, IERROR)
IF (IERROR /= PAPYRUSKV_OK) THEN
PRINT*, 'FAILED'
ENDIF
PRINT*, 'GET--> RANK', RANK, 'KEY:', TRIM(KEY(RANK + 1)), ' VAL:', VAL2(1: VALLEN)
CALL PAPYRUSKV_FREE(VAL2, IERROR)
IF (IERROR /= PAPYRUSKV_OK) THEN
PRINT*, 'FAILED'
ENDIF
KEYLEN = LEN(TRIM(KEY(PEER + 1)), KIND = 8)
CALL PAPYRUSKV_GET(DB, TRIM(KEY(PEER + 1)), KEYLEN, VAL1, VALLEN, IERROR)
IF (IERROR /= PAPYRUSKV_OK) THEN
PRINT*, 'FAILED'
ENDIF
PRINT*, 'GET--> RANK', RANK, 'KEY:', TRIM(KEY(PEER + 1)), ' VAL:', VAL1(1: VALLEN)
KEYLEN = LEN(TRIM(KEY(PEER + 1)), KIND = 8)
CALL PAPYRUSKV_GET(DB, TRIM(KEY(PEER + 1)), KEYLEN, VAL2, VALLEN, IERROR)
IF (IERROR /= PAPYRUSKV_OK) THEN
PRINT*, 'FAILED'
ENDIF
PRINT*, 'GET--> RANK', RANK, 'KEY:', TRIM(KEY(PEER + 1)), ' VAL:', VAL2(1: VALLEN)
CALL PAPYRUSKV_FREE(VAL2, IERROR)
IF (IERROR /= PAPYRUSKV_OK) THEN
PRINT*, 'FAILED'
ENDIF
END IF
CALL PAPYRUSKV_CLOSE(DB, IERROR)
IF (IERROR /= PAPYRUSKV_OK) THEN
PRINT*, 'FAILED'