From 71ed298451fd0db10be632eef4ccf4fb624b52dd Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Mon, 16 Dec 2024 16:57:35 -0800 Subject: [PATCH] Apply the new formatting Signed-off-by: Chen Wang --- docs/demos/ecp_feb_2023/cons.c | 16 ++++++++------ docs/demos/ecp_feb_2023/prod.c | 19 +++++++++-------- src/dyad/modules/dyad.c | 39 ++++++++++++++++------------------ 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/docs/demos/ecp_feb_2023/cons.c b/docs/demos/ecp_feb_2023/cons.c index 9cdb7d4c..de6e058c 100644 --- a/docs/demos/ecp_feb_2023/cons.c +++ b/docs/demos/ecp_feb_2023/cons.c @@ -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); @@ -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); @@ -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; } diff --git a/docs/demos/ecp_feb_2023/prod.c b/docs/demos/ecp_feb_2023/prod.c index db326b6a..70f676d5 100644 --- a/docs/demos/ecp_feb_2023/prod.c +++ b/docs/demos/ecp_feb_2023/prod.c @@ -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; @@ -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); @@ -86,4 +85,6 @@ int main (int argc, char** argv) } } free (full_path); + + return 0; } diff --git a/src/dyad/modules/dyad.c b/src/dyad/modules/dyad.c index 23a400d9..803828b1 100644 --- a/src/dyad/modules/dyad.c +++ b/src/dyad/modules/dyad.c @@ -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”. @@ -69,7 +68,6 @@ * using "flux module load". */ - typedef struct dyad_mod_ctx { flux_msg_handler_t **handlers; dyad_ctx_t *ctx; @@ -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'}; @@ -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'}, @@ -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 (); @@ -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; } } @@ -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 @@ -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