Conversation
src/code.c - Update author list src/code_c.c - Update bprintf call to print out //-style commments Signed-off-by: Bob Yantosca <[email protected]>
drv/general.c - C-language driver program drv/general_adj.c - C-language adjoint driver program Signed-off-by: Bob Yantosca <[email protected]>
src/code.c - In WriteDelim, extend the number of ~ characters printed src/code_c.c - Fix error in previous commit in call to bprintf, remove the 2nd parameter (LINE_LENGTH) and add a \n to the format. Signed-off-by: Bob Yantosca <[email protected]>
src/gen.c - When generating the _Function file, wrap Fortran90 optional arguments in an "if ( useLang == F90_LANG )". This prevents a compiler error when the target language is C - In the equation for Vdot, we need to loop over elements of the Vdot array if the target language is C. We can only use array notation for Fortran90. - Trim trailing whitespace src/code_c.c - In routine C_FunctionStart, set fncPrototipe=0. This will declare each C-language function so that arrays will have dimensions included in the function interface. This will avoid a compilation error. - Trim trailing whitespace Signed-off-by: Bob Yantosca <[email protected]>
drv/general.c drv/general_adj.c - Add more comments for clarity - Trimmed trailing whitespace Signed-off-by: Bob Yantosca <[email protected]>
We have renamed the continuous integration test folders in ci_tests so that each test begins with either a C_ or F90_, to denote the target language of KPP-generated code. The minimum version test has been renamed to X_minver. ./ci-pipelines/ci-testing-list.sh - Added the names of all the CI test folders in this file, which is source-d by the other scripts. The list of folders is stored in the ALL_TESTS bash variable. ./ci-pipelines/ci-manual-cleanup-script.sh ./ci-pipelines/ci-manual-testing-script.sh ./ci-pipelines/ci-testing-script.sh - These scripts now issue a "source ./ci-testing-list.sh" command in order to get the ALL_TESTS variable (which contains the list of CI test folders). Signed-off-by: Bob Yantosca <[email protected]>
This commit brings the updates from the "cleanup_util" and "dev" branches branch (plus some documentation updates) into the C-language development steream. Resolved conflicts in: (1) .ci-pipelines/ci-manual-cleanup-script.sh (2) .ci-pipelines/ci-manual-testing-script.sh (3) .ci-pipelines/ci-testing-script.sh Signed-off-by: Bob Yantosca <[email protected]>
…gets util/Makefile_f90 util/Makefile_upper_f90 - Remove *.o and *.mod files instead of KPP_ROOT*.o and KPP_ROOT*.mod in the clean and distclean targets. This will prevent issues where files are not removed due to case-insensitivity. Signed-off-by: Bob Yantosca <[email protected]>
./ci-tests/F90_ros_autoreduce - Renamed (was originally ros_autoreduce) ./ci-pipelines/ci-testing/list.sh - Add F90_ros_autoreduce to list of tests drv/general_autoreduce - Set ICNTRL(15) = -1 to prevent rate constants from being updated within the integration step. This slows the autoreduce code down. Signed-off-by: Bob Yantosca <[email protected]>
util/Makefile_c - Typo: Remove KPP_ROOT*.map (was KPP_ROOT_*.map) util/Makefile.f90 util/Makefile_upper_F90 - Now remove *.o and *.mod in clean and distclean targets, in order to avoid uppercase/lowercase ambiguity Signed-off-by: Bob Yantosca <[email protected]>
|
Looks good. Thanks for given the CI tests a nice structure! |
|
Still debugging a seg fault when I try to build a larger mechanism than small_strato. It seems to be in C_InitDeclare when we pass it the EQN_NAMES. Will dig into this a bit. |
|
gdb output says: Program received signal SIGSEGV, Segmentation fault.
0x00002aaaaaf60f76 in __mempcpy_sse2 () from /lib64/libc.so.6
(gdb) where
#0 0x00002aaaaaf60f76 in __mempcpy_sse2 () from /lib64/libc.so.6
#1 0x00002aaaaaf4e06c in _IO_default_xsputn () from /lib64/libc.so.6
#2 0x00002aaaaaf1e033 in vfprintf () from /lib64/libc.so.6
#3 0x00002aaaaaf424cb in vsprintf () from /lib64/libc.so.6
#4 0x0000000000401b55 in bprintf (fmt=0x425ce4 "\"%s\"") at code.c:202
#5 0x0000000000404878 in C_InitDeclare (v=90, n=235, values=0x7ffffffda350)
at code_c.c:333
#6 0x000000000040dd4d in GenerateMonitorData () at gen.c:525
#7 0x000000000041998c in Generate () at gen.c:3629
#8 0x000000000041c66e in main (argc=2, argv=0x7fffffffb938) at kpp.c:640 |
|
@RolfSander, I think I see what is going on. In routine // debug
if ( v==90 ) {
printf("\n");
for (i=0; i<n; i++) printf( "\n%d, %s\n", i, cval[i] );
exit(1);
}which gives this output: 0, NO2 --> O3P + NO O3P + AIR + O2 --> O3 O3P + O3 --> 2 O2 O3P + NO + AIR --> NO2 O3P + NO2 --> NO O3P + NO2 --> NO3 O3 + NO --> NO2so for each index This is called from p = bufeqn;
for (i = 0; i < EqnNr; i++) {
EqnString(i, p);
seqn[i] = p;
p += MAX_EQNLEN;
}
InitDeclare( EQN_NAMES, EqnNr, (void*)seqn );If you have any ideas then let me know. Thanks! |
|
I'm sorry but I don't know how to solve this problem. Maybe the easiest quick&dirty fix is to deactive EQN_NAMES for the C |
|
Found a solution! switch( var->type ) {
case VELM: bprintf( " %s %s[] = {\n%5s", C_types[var->baseType], var->name, " " );
for( i = 0; i < n; i++ ) {
switch( var->baseType ) {
case INT:
bprintf( "%3d", ival[i] );
maxCols=12;
break;
case DOUBLE:
case REAL:
bprintf( "%5lg", dval[i] );
maxCols=8;
break;
case STRING:
bprintf( "\"%s\"", cval[i] );
maxCols=8;
break;
case DOUBLESTRING:
// Bug fix: To avoid a segmentation fault, copy the
// string from cval[i] to string variable thisEqn
// before passing it to bprintf.
// -- Bob Yantosca (28 Jun 2022)
strncpy( thisEqn, cval[i], MAX_EQNLEN+1 );
bprintf( "\"%s\"", thisEqn );
maxCols=1;
break;
} |
In routine C_InitDeclare, in the switch statement for VELM and DOUBLESTRING, we first copy the cval[i] to a temporary string variable before passing that to bprintf. This avoids a segmentation fault. Also removed some leftover debug printout. Signed-off-by: Bob Yantosca <[email protected]>
This is needed in order to generate C-language code for the models/saprc99.eqn or models/saprcnov.eqn mechanisms. Signed-off-by: Bob Yantosca <[email protected]>
drv/general.c
- Use floating point variables for TSTART and TEND
- Fixed a typo ("3600/0" should be "3600.0")
drv/general_adj.c
- Use floating point constants 100.0 and 3600.0
models/saprcnov.def
- Remove tabs
- Trim trailing whitespace
- Align entries in INLINE blocks
Signed-off-by: Bob Yantosca <[email protected]>
./ci-pipelines/ci-testing-list.sh - Added C_rosadj to the ALL_TESTS variable ./ci_tests/C_rk/C_rk.kpp - Bug fix: #LANGUAGE should be C, not Fortran90 ./ci-tests/C_rosadj/C_rosadj.kpp - Added KPP definition file for the rosenbrock_adj test in C Signed-off-by: Bob Yantosca <[email protected]>
|
I've since fixed the issue above. For now I only use the |
RolfSander
left a comment
There was a problem hiding this comment.
Great that you found a solution. Yes, go ahead and merge!
This PR fixes several issues that were preventing KPP from generating C-language output code. Namely:
Change
/* */comment headers to//, which reads much more clearlyRestored and updated the
drv/general.canddrv/general_adj.cdriver programsAdded updates to
gen.c:_Functionfile is generated, we now wrap Fortran90 optional arguments with anif ( useLang == F90_LANG ). This prevents a compiler error when the target language is C.Vdotis added to_Function, we need to loop over elements of the Vdot array if the target language is C. We can only use array notation for Fortran90.Added updates to
code_c.c:fncPrototipe=0. This will declare each C-language function so that arrays will have dimensions included in the function interface. This will avoid a compilation error.I have also reorganized the
./ci_testssubfolders.C_orF90_, to denote the target language. (The minimum version test folder has been renamed toX_minverso that it will come last.NOTE: At present, the C-language code fails when trying to use a mechanism other than
small_strato. I think this is due to a Makefile issue that happens when e.g. Hessian is turned off but the Makefile looks for the Hessian files. I can implement a similar fix as was done for Fortran90.