Skip to content

Commit

Permalink
Merge pull request #262 from lanl/tam-debug
Browse files Browse the repository at this point in the history
Tam debug
  • Loading branch information
ehinrichs authored Apr 22, 2024
2 parents 0dae9c6 + 5e7769f commit 10e14b0
Show file tree
Hide file tree
Showing 10 changed files with 313 additions and 20 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ FortranCInterface_HEADER(
SYMBOLS
INITLAGRIT # syntax: <subroutine>
DOTASK
DOTASK_TEST
CMO_GET_NAME
CMO_GET_INFO
CMO_GET_INTINFO
Expand Down
35 changes: 30 additions & 5 deletions src/dotask.f
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ subroutine dotask(task_buff,ierror)
C#######################################################################
C
C PURPOSE -
C
C execute commands
C
C include file defines globals for command parsing and buffer
C commands_lg.h:C cmd_buffer is a the command buffer
C commands_lg.h: common /ccommands_lg/ clevels, cmd_buff, cmd_temp,
C commands_lg.h: character*16384 cmd_buff, cmd_temp, command
C
C INPUT
c task_buff character string of commands to be added
c to command_stack
Expand All @@ -25,8 +30,13 @@ subroutine dotask(task_buff,ierror)
C
implicit none
include 'commands_lg.h'

C parameters
character*(*) task_buff
integer ierror
integer ierror

C local variables
integer ierr
c
ierror=0
nlevels=nlevels+1
Expand All @@ -35,9 +45,24 @@ subroutine dotask(task_buff,ierror)
clevels(nlevels)='internal_lg'
cmd_buff=' '
cmd_buff=task_buff
call pack_command_lg(ierror)
call push_command_lg(ierror)
call control_command_lg(ierror)

call pack_command_lg(ierr)
if (ierr .ne. 0) then
call x3d_error('dotask:','pack_command_lg')
ierror = ierror + 1
endif
call push_command_lg(ierr)
if (ierr .ne. 0) then
call x3d_error('dotask:','push_command_lg')
ierror = ierror + 1
endif
call control_command_lg(ierr)
if (ierr .ne. 0) then
call x3d_error('dotask:','control_command_lg')
ierror = ierror + 1
endif


return
end

73 changes: 73 additions & 0 deletions src/dotask_test.f
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
subroutine dotask_test(task_buff,ierror)
C#######################################################################
C
C PURPOSE -
C
C Test string passing from cpp
C Do not execute commands, print info
C
c task_buff character string of commands to be added
c to command_stack
c
C#######################################################################
C
implicit none
include 'commands_lg.h'

C global defines for command parsing and buffer
C check but do not set in this test routine
C commands_lg.h:C cmd_buffer is a the command buffer
C commands_lg.h: common /ccommands_lg/ clevels, cmd_buff, cmd_temp,
C commands_lg.h: character*16384 cmd_buff, cmd_temp, command
C last_char is the location of the last character in cmd_stack
c len_buff is the length of cmd_buffer
c len_cmd is the length of a single command

C parameters
character*(*) task_buff
integer ierror

C local variables
integer ierr, icharlnf, ilen
character*132 cbuf
c
ierror=0

print*,""
print*,"Begin FORTRAN dotask_test"
print*,"parameter integer size: ", sizeof(ierr)

ilen = icharlnf(task_buff)
print*," received string: ",task_buff(1:ilen)
print*," length: ",ilen
print*,""
print*," check GLOBAL cmd_buff set in dotask calls."
print*," cmd_buff: ",cmd_buff(1:len_buff)
print*," length:",len_buff

print*,"End FORTRAN dotask_test"
print*,""

C -------------------------------------------------------
C do not process the buffer into command options
C
C call pack_command_lg(ierr)
C if (ierr .ne. 0) then
C call x3d_error('dotask:','pack_command_lg')
C ierror = ierror + 1
C endif
C call push_command_lg(ierr)
C if (ierr .ne. 0) then
C call x3d_error('dotask:','push_command_lg')
C ierror = ierror + 1
C endif
C call control_command_lg(ierr)
C if (ierr .ne. 0) then
C call x3d_error('dotask:','control_command_lg')
C ierror = ierror + 1
C endif
C -------------------------------------------------------

return
end

1 change: 1 addition & 0 deletions src/fc_mangle.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/* Mangle some symbols automatically. */
#define INITLAGRIT FortranCInterface_GLOBAL(initlagrit, INITLAGRIT)
#define DOTASK FortranCInterface_GLOBAL(dotask, DOTASK)
#define DOTASK_TEST FortranCInterface_GLOBAL_(dotask_test, DOTASK_TEST)
#define CMO_GET_NAME FortranCInterface_GLOBAL_(cmo_get_name, CMO_GET_NAME)
#define CMO_GET_INFO FortranCInterface_GLOBAL_(cmo_get_info, CMO_GET_INFO)
#define CMO_GET_INTINFO FortranCInterface_GLOBAL_(cmo_get_intinfo, CMO_GET_INTINFO)
Expand Down
1 change: 1 addition & 0 deletions src/lg_c_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ void lg_initlagrit();

/// Send a LaGriT command for processing
LG_ERR lg_dotask(const char* cmd);
LG_ERR lg_dotask_test(const char* cmd);

LG_ERR lg_cmo_get_name(char* name_buffer, int name_buffer_size);

Expand Down
52 changes: 51 additions & 1 deletion src/lg_c_wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ NOTE: these only work for integer scalars

#include "lg_c_interface.h"
#include "lg_f_interface.h"

#include "type_sizes.h"
#include <stdio.h>
#include <cstring>

Expand Down Expand Up @@ -75,6 +75,56 @@ LG_ERR lg_dotask(const char* cmd) {
}
}

// test strings passed from cpp to fortran
// similar to dotask but do not process strings as commands
extern "C"
LG_ERR lg_dotask_test(const char* cmd) {
const char* cmd_finish = "; finish";

// arg values passed to fortran should be size 8
// int_ptrsize is usually integer 8 same as long
// The hidden string length is passed as size_t as 8 bytes on x64

int_ptrsize err = 0;
size_t ival = 0;

printf("Inside C wrapper lg_dotask_test \n");
printf("received string: %s\n", cmd);
printf("string length: %ld\n", strlen(cmd));

if (strlen(cmd) >= (MAX_BUFFER_SIZE - strlen(cmd_finish))) {
return LG_ERR_C_INVALID_ARGS;
}

char cmd_buffer[MAX_BUFFER_SIZE];

int result = snprintf(
cmd_buffer,
MAX_BUFFER_SIZE,
"%s%s",
cmd,
cmd_finish);

if ((result >= 0) && (result < MAX_BUFFER_SIZE)) {

printf(" sizeof strlen: %ld\n",sizeof(strlen(cmd_buffer)));
printf(" sizeof err: %ld\n",sizeof(err));
printf(" sizeof hidden length: %ld\n",sizeof(ival));


printf("sending parameters to FORTRAN dotask_test\n");
printf("send string: %s\n", cmd_buffer);
printf("string length: %ld\n", strlen(cmd_buffer));

DOTASK_TEST(cmd_buffer, &err, strlen(cmd_buffer));

return (LG_ERR)err;

} else {
return LG_ERR_C_INVALID_ARGS;
}
}

extern "C"
LG_ERR lg_cmo_get_name(char* name_buffer, int name_buffer_size) {
int_ptrsize err = 0;
Expand Down
41 changes: 41 additions & 0 deletions src/lg_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ where integer=8bytes, real*8=8bytes, pointer=8bytes

#include "lg_c_interface.h"
#include "lg_f_interface.h"
#include "type_sizes.h"
#include <stdio.h>
#include <cstring>

Expand Down Expand Up @@ -209,6 +210,46 @@ C ----------------------------------------------------------*/
return;

}

// for testing dotask without processing commands
void dotask_cpp_ () {

LG_ERR err = 0;
double minmax[6];
double xreal = 0.0;
long ival= 0;
long itype = 0;
long ierr= 0;

printf("------------------------------------------\n");
printf("Inside C++ dotask_cpp \n");

char* cmd1[512];

printf("send string to wrapper: %s\n\n", "123456789");
err = lg_dotask_test("123456789");

// if needed, test list of commands
/******
const char* cmds[] = {
"command/one",
"command/two"};
for (int i = 0; i < sizeof(cmds)/sizeof(cmds[0]); ++i) {
printf("send string to wrapper lg_dotask_test: %s\n", cmds[i]);
err = lg_dotask_test(cmds[i]);
if (err != LG_ERR_SUCCESS) {
printf("dotask_test error: %s\n", cmds[i]);
return;
}
}
******/

printf("End C++ dotask_cpp \n");
printf("------------------------------------------\n");
}
#ifdef __cplusplus
}
#endif
Expand Down
26 changes: 25 additions & 1 deletion src/lg_example_fortran.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
subroutine lg_example_fortran(ierror)
! #####################################################################
! This file has examples of dotask and get info routines
! Added routines for testing strings

subroutine test_string(cbuf)
! #####################################################################
! PURPOSE -
! test string passing between C and fortran calls
! using print to avoid formatting
! #####################################################################

implicit none
character*132 cbuf
integer icharlnf, ilen

ilen = icharlnf(cbuf)
print*
print*,"test_string() received string:"
print*,"length: ",icharlnf(cbuf)
print*,"string: ",cbuf(1:ilen)

return
end

!
!
subroutine lg_example_fortran(ierror)
! #####################################################################
!
! PURPOSE -
Expand Down
8 changes: 7 additions & 1 deletion src/lg_f_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ ie define DOTASK FortranCInterface_GLOBAL(dotask, DOTASK)
*/

#include "fc_mangle.h"
#include "type_sizes.h"
#include <stddef.h>

typedef int int_ptrsize;
// typedef int int_ptrsize;
typedef double real8;

#ifdef __cplusplus
Expand All @@ -68,6 +69,11 @@ extern void DOTASK(
int_ptrsize* ierr,
size_t cmd_len);

extern void DOTASK_TEST(
const char* cmd,
int_ptrsize* ierr,
size_t cmd_len);

extern void CMO_GET_NAME(
const char* name,
int_ptrsize* ierr,
Expand Down
Loading

0 comments on commit 10e14b0

Please sign in to comment.