Skip to content

Commit

Permalink
Merge pull request ornladios#2816 from eisenhauer/FFSUpstream
Browse files Browse the repository at this point in the history
  • Loading branch information
eisenhauer authored Aug 8, 2021
2 parents 47b7df5 + 697b907 commit 5e76697
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 47 deletions.
5 changes: 4 additions & 1 deletion thirdparty/ffs/ffs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,13 @@ else()
${CMAKE_CURRENT_BINARY_DIR}/lex.yy.c)
ADD_FLEX_BISON_DEPENDENCY(CODScanner CODParser)
endif()

find_package(Perl REQUIRED)

add_custom_command(
OUTPUT "cod_node.c"
COMMAND
perl
${PERL_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/cod/struct.pl
${CMAKE_CURRENT_SOURCE_DIR}/cod/cod.structs
DEPENDS
Expand Down
105 changes: 60 additions & 45 deletions thirdparty/ffs/ffs/fm/fm_formats.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static char *stringify_field_type(const char *type,
static int is_self_server(FMContext fmc);
static void expand_FMContext(FMContext fmc);
static int IOget_array_size_dimen(const char *str, FMFieldList fields,
int dimen, int *control_field);
int dimen, int *control_field, int cur_field);
static int field_type_eq(const char *str1, const char *str2);

/*
Expand Down Expand Up @@ -700,31 +700,25 @@ FMContext fmc;
}

static int
is_var_array_field(FMFieldList field_list, int field)
is_all_static_array_dimens(const char *str)
{
int done = 0;
int ret = 0;
int dimen_count = 0;
int control_val;
while (!done) {
int static_size = IOget_array_size_dimen(field_list[field].field_type,
field_list, dimen_count,
&control_val);
dimen_count++;
if (static_size == 0) {
done++;
continue;
}
if ((static_size == -1) && (control_val == -1)) {
/* failed validation, errors already delivered */
return -1;
}
if (control_val != -1) {
/* dynamic array */
ret = 1;
}
char *left_paren, *end;

if ((left_paren = strchr(str, '[')) == NULL) {
return 1;
}
(void) strtol(left_paren + 1, &end, 0);
if (*end != ']') {
return 0;
} else {
return is_all_static_array_dimens(end+1);
}
return ret;
}

static int
is_var_array_field(FMFieldList field_list, int field)
{
return !is_all_static_array_dimens(field_list[field].field_type);
}

static FMTypeDesc *
Expand Down Expand Up @@ -831,7 +825,7 @@ gen_FMTypeDesc(FMFieldList fl, int field, const char *typ)
int control_val;
FMTypeDesc *tmp;
int static_size = IOget_array_size_dimen(typ, fl, dimen_count,
&control_val);
&control_val, field);
tmp = new_FMTypeDesc();
tmp->type = FMType_array;
tmp->field_index = field;
Expand Down Expand Up @@ -1164,7 +1158,7 @@ gen_var_dimens(FMFormat fmformat, int field)
int control_val;
int static_size = IOget_array_size_dimen(field_list[field].field_type,
field_list, dimen_count,
&control_val);
&control_val, field);
if (static_size == 0) {
done++;
continue;
Expand Down Expand Up @@ -2764,12 +2758,35 @@ const char *str;
return unknown_type;
}

long
find_field(char *field_name, FMFieldList fields, int cur_field, void *search_help)
{
int i;
if (cur_field > 10) {
/* search close first */
for (i = cur_field -1; i > cur_field - 10; i--) {
if (strcmp(field_name, fields[i].field_name) == 0) {
return i;
}
}
for (i = cur_field + 1; i < cur_field + 10; i++) {
if (strcmp(field_name, fields[i].field_name) == 0) {
return i;
}
}
}
i = 0;
while (fields[i].field_name != NULL) {
if (strcmp(field_name, fields[i].field_name) == 0) {
return i;
}
i++;
}
return -1;
}

extern int
IOget_array_size_dimen(str, fields, dimen, control_field)
const char *str;
FMFieldList fields;
int dimen;
int *control_field;
IOget_array_size_dimen(const char *str, FMFieldList fields, int dimen, int *control_field, int cur_field)
{
char *left_paren, *end;
long static_size;
Expand All @@ -2788,27 +2805,25 @@ int *control_field;
/* dynamic element */
char field_name[1024];
int count = 0;
int i = 0;
while (((left_paren+1)[count] != ']') &&
((left_paren+1)[count] != 0)) {
field_name[count] = (left_paren+1)[count];
count++;
}
field_name[count] = 0;
while (fields[i].field_name != NULL) {
if (strcmp(field_name, fields[i].field_name) == 0) {
if ((FMstr_to_data_type(fields[i].field_type) ==
integer_type) ||
(FMstr_to_data_type(fields[i].field_type) ==
unsigned_type)) {
*control_field = i;
return -1;
} else {
fprintf(stderr, "Variable length control field \"%s\" not of integer type.\n", field_name);
return 0;
}
void * search_help = NULL;
long search_field = find_field(field_name, fields, cur_field, search_help);
if (search_field != -1) {
if ((FMstr_to_data_type(fields[search_field].field_type) ==
integer_type) ||
(FMstr_to_data_type(fields[search_field].field_type) ==
unsigned_type)) {
*control_field = search_field;
return -1;
} else {
fprintf(stderr, "Variable length control field \"%s\" not of integer type.\n", field_name);
return 0;
}
i++;
}
fprintf(stderr, "Array dimension \"%s\" in type spec\"%s\" not recognized.\n",
field_name, str);
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/ffs/ffs/fm/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set (TESTS align_test compat_test)
set (PROGS format_test self_format_test)
set (PROGS format_test self_format_test scale_test)

foreach (TEST ${TESTS} )
ADD_EXECUTABLE(${TEST} ${TEST}.c test_funcs.c)
Expand Down
84 changes: 84 additions & 0 deletions thirdparty/ffs/ffs/fm/tests/scale_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@

#include <stdio.h>
#include <stdlib.h>

#include "config.h"
#include <string.h>
#include <time.h>
#include "fm.h"
#include "fm_internal.h"
#ifdef HAVE_WINDOWS_H
#include <windows.h>
#define sleep(x) Sleep(1000*x)
#else
extern int sleep();
#endif

#include "test_funcs.h"

char *gen_name(int i)
{
char tmp_name[128];
sprintf(tmp_name, "SST_Variable_FieldName that's really really long because I can't imagine why %d", i);
return strdup(tmp_name);
}

int
main(argc, argv)
int argc;
char **argv;
{

FMStructDescRec str_list[5];
struct timespec start, stop;

if (argc > 1) {
}

FMContext context = create_FMcontext(NULL);
int field_count = 2000000;
field_count = ((field_count >> 2 ) << 2); // ensure field count is divisible by 4;
FMFieldList list = malloc(sizeof(struct _FMField) * (field_count + 1));
int cur_count = 0;
while (cur_count < field_count) {
/* do 4 at a time */
char tmp[128];
char *n1 = gen_name(cur_count);
char *n2 = gen_name(cur_count + 1);
char *n3 = gen_name(cur_count + 2);
char *n4 = gen_name(cur_count + 3);
list[cur_count].field_name = n1;
list[cur_count].field_type = strdup("integer");
list[cur_count].field_size = 8;
list[cur_count].field_offset = cur_count * 8;
list[cur_count+1].field_name = n2;
list[cur_count+1].field_type = strdup("integer");
list[cur_count+1].field_size = 8;
list[cur_count+1].field_offset = (cur_count+1) * 8;
list[cur_count+2].field_name = n3;
sprintf(tmp, "integer[%s]", n1);
list[cur_count+2].field_type = strdup(tmp);
list[cur_count+2].field_size = 8;
list[cur_count+2].field_offset = (cur_count+2) * 8;
list[cur_count+3].field_name = n4;
sprintf(tmp, "integer[%s]", n2);
list[cur_count+3].field_type = strdup(tmp);
list[cur_count+3].field_size = 8;
list[cur_count+3].field_offset = (cur_count+3) * 8;
cur_count +=4;
}
list[cur_count].field_name = list[cur_count].field_type = NULL;

clock_gettime(CLOCK_MONOTONIC, &start);

str_list[0].format_name = "first format";
str_list[0].field_list = list;
str_list[0].struct_size = sizeof(first_rec);
str_list[0].opt_info = NULL;
str_list[1].format_name = NULL;
FMFormat format = register_data_format(context, str_list);

clock_gettime(CLOCK_MONOTONIC, &stop);
double duration = (stop.tv_sec + 1.0e-9*stop.tv_nsec) - (start.tv_sec + 1.0e-9*start.tv_nsec);
printf("Registration took %g seconds\n", duration);
}

0 comments on commit 5e76697

Please sign in to comment.