Skip to content

Commit

Permalink
Apply the new formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Chen Wang <[email protected]>
  • Loading branch information
wangvsa committed Dec 17, 2024
1 parent 09363c1 commit 71ed298
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 37 deletions.
16 changes: 9 additions & 7 deletions docs/demos/ecp_feb_2023/cons.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ int consume_file (char* full_path, int32_t seed, int32_t* val_buf)
printf ("File %ld: Cannot open\n", (long)seed);
return -1;
}
// Read the file or abort if not possible
// Read then close the file
size_t items_read = fread (val_buf, sizeof (int32_t), NUM_VALS, fp);
fclose (fp);

// Print an error if the number of items read is not what was expected
if (items_read != NUM_VALS) {
fprintf (stderr, "Could not read the full file (%s)\n", full_path);
Expand All @@ -45,15 +46,14 @@ int main (int argc, char** argv)
int32_t num_transfers;
char* fpath;
int rc = parse_cmd_line (argc, argv, &num_transfers, &fpath);
// If an error occured during command-line parsing,
// abort the consumer
// abort if an error occured during command-line parsing,
if (rc != 0) {
return rc;
}

// Largest number of digits for a int32_t when converted to string
const size_t max_digits = 10;
// First 4 is for "data"
// Second 4 is for ".txt"
// First 4 is for "data" and second 4 is for ".txt"
size_t path_len = strlen (fpath) + 4 + max_digits + 4;
// Allocate a buffer for the file path
char* full_path = malloc (path_len + 1);
Expand Down Expand Up @@ -85,11 +85,13 @@ int main (int argc, char** argv)
}
// Validate the content of the file
if (vals_are_valid (seed, val_buf)) {
printf ("File %ld: OK\n", (long)seed);
printf ("File %ld validation: OK\n", (long)seed);
} else {
printf ("File %ld: BAD\n", (long)seed);
printf ("File %ld validation: BAD\n", (long)seed);
}
}
free (val_buf);
free (full_path);

return 0;
}
19 changes: 10 additions & 9 deletions docs/demos/ecp_feb_2023/prod.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ int produce_file (char* full_path, int32_t seed, int32_t* val_buf)
printf ("File %ld: Cannot open\n", (long)seed);
return -1;
}
// Write the file or abort if not possible
size_t items_read = fwrite (val_buf, sizeof (int32_t), NUM_VALS, fp);
// Close the file
fclose (fp);

// Write then close the file
size_t items_write = fwrite (val_buf, sizeof(int32_t), NUM_VALS, fp);
fclose(fp);

// If an error occured during writing, abort
if (items_read != NUM_VALS) {
if (items_write != NUM_VALS) {
fprintf (stderr, "Could not write the full file (%s)\n", full_path);
printf ("File %ld: Cannot write\n", (long)seed);
return -1;
Expand All @@ -43,15 +44,13 @@ int main (int argc, char** argv)
int32_t num_transfers;
char* fpath;
int rc = parse_cmd_line (argc, argv, &num_transfers, &fpath);
// If an error occured during command-line parsing,
// abort the consumer
// abort if an error occured during command-line parsing
if (rc != 0) {
return rc;
}
// Largest number of digits for a int32_t when converted to string
const size_t max_digits = 10;
// First 4 is for "data"
// Second 4 is for ".txt"
// First 4 is for "data", second 4 is for ".txt"
size_t path_len = strlen (fpath) + 4 + max_digits + 4;
// Allocate a buffer for the file path
char* full_path = malloc (path_len + 1);
Expand Down Expand Up @@ -86,4 +85,6 @@ int main (int argc, char** argv)
}
}
free (full_path);

return 0;
}
39 changes: 18 additions & 21 deletions src/dyad/modules/dyad.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
((double)(1000000000L * ((Tend).tv_sec - (Tstart).tv_sec) + (Tend).tv_nsec - (Tstart).tv_nsec) \
/ 1000000000L)


/**
* Flux services are implemented as dynamically loaded broker
* plugins called “broker modules”.
Expand All @@ -69,7 +68,6 @@
* using "flux module load".
*/


typedef struct dyad_mod_ctx {
flux_msg_handler_t **handlers;
dyad_ctx_t *ctx;
Expand Down Expand Up @@ -309,11 +307,11 @@ struct opt_parse_out {

typedef struct opt_parse_out opt_parse_out_t;

int opt_parse(opt_parse_out_t *restrict opt,
const unsigned broker_rank,
dyad_dtl_mode_t *restrict dtl_mode,
int argc,
char **restrict argv)
int opt_parse (opt_parse_out_t *restrict opt,
const unsigned broker_rank,
dyad_dtl_mode_t *restrict dtl_mode,
int argc,
char **restrict argv)
{
#ifndef DYAD_LOGGER_NO_LOG
char log_file_name[PATH_MAX + 1] = {'\0'};
Expand Down Expand Up @@ -342,11 +340,11 @@ int opt_parse(opt_parse_out_t *restrict opt,
extern int optind;
optind = 1;
int _argc = argc + 1;
char** _argv = malloc(sizeof(char*) * _argc);
char **_argv = malloc (sizeof (char *) * _argc);
_argv[0] = NULL;
for (int i = 1; i < _argc; i++) {
// we will reuse the same same string in argv[].
_argv[i] = argv[i-1];
_argv[i] = argv[i - 1];
}

static struct option long_options[] = {{"help", no_argument, 0, 'h'},
Expand All @@ -357,7 +355,7 @@ int opt_parse(opt_parse_out_t *restrict opt,
{0, 0, 0, 0}};

int c;
while ((c = getopt_long(_argc, _argv, "hdm:i:e:", long_options, NULL)) != -1) {
while ((c = getopt_long (_argc, _argv, "hdm:i:e:", long_options, NULL)) != -1) {
switch (c) {
case 'h':
show_help ();
Expand Down Expand Up @@ -396,7 +394,7 @@ int opt_parse(opt_parse_out_t *restrict opt,
break;
default:
DYAD_LOG_STDERR ("DYAD_MOD: option parsing failed %d\n", c);
free(_argv);
free (_argv);
return DYAD_RC_SYSFAIL;
}
}
Expand All @@ -418,11 +416,10 @@ int opt_parse(opt_parse_out_t *restrict opt,
}
opt->prod_managed_path = prod_managed_path;

free(_argv);
free (_argv);
return DYAD_RC_OK;
}


dyad_rc_t dyad_module_ctx_init (const opt_parse_out_t *opt, flux_t *h)
{
// get DYAD Flux module
Expand All @@ -441,18 +438,18 @@ dyad_rc_t dyad_module_ctx_init (const opt_parse_out_t *opt, flux_t *h)

if (opt->dtl_mode) {
setenv (DYAD_DTL_MODE_ENV, opt->dtl_mode, 1);
DYAD_LOG_STDERR (
"DYAD_MOD: DTL 'mode' option set. Setting env %s=%s\n",
DYAD_DTL_MODE_ENV, opt->dtl_mode);
DYAD_LOG_STDERR ("DYAD_MOD: DTL 'mode' option set. Setting env %s=%s\n",
DYAD_DTL_MODE_ENV,
opt->dtl_mode);
} else {
DYAD_LOG_STDERR (
"DYAD_MOD: Did not find DTL 'mode' option. Using env %s=%s\n",
DYAD_DTL_MODE_ENV, getenv (DYAD_DTL_MODE_ENV));
DYAD_LOG_STDERR ("DYAD_MOD: Did not find DTL 'mode' option. Using env %s=%s\n",
DYAD_DTL_MODE_ENV,
getenv (DYAD_DTL_MODE_ENV));
}

char* kvs_namespace = getenv("DYAD_KVS_NAMESPACE");
char *kvs_namespace = getenv ("DYAD_KVS_NAMESPACE");
if (kvs_namespace != NULL) {
DYAD_LOG_STDERR ("DYAD_MOD: DYAD_KVS_NAMESPACE is set to `%s'\n", kvs_namespace);
DYAD_LOG_STDERR ("DYAD_MOD: DYAD_KVS_NAMESPACE is set to `%s'\n", kvs_namespace);
} else {
DYAD_LOG_STDERR ("DYAD_MOD: DYAD_KVS_NAMESPACE is not set\n");
// Required so that dyad_ctx_init can pass
Expand Down

0 comments on commit 71ed298

Please sign in to comment.