//// private functions int ExpLed::_FunctionSet (void) { int status = EXIT_SUCCESS; int colorVals[EXP_LED_COLOR_ID_NUM]; // Check that json has been parsed if ( !jsonDoc.IsObject() ) { return 1; } // JSON - find input values for the colors status |= JsonGetInt(EXP_LED_COLOR_R_STRING, &(colorVals[EXP_LED_COLOR_ID_R]) ); status |= JsonGetInt(EXP_LED_COLOR_G_STRING, &(colorVals[EXP_LED_COLOR_ID_G]) ); status |= JsonGetInt(EXP_LED_COLOR_B_STRING, &(colorVals[EXP_LED_COLOR_ID_B]) ); if (verbosityLevel > 0) printf("Setting RGB to %d%d%d\n", colorVals[EXP_LED_COLOR_ID_R], colorVals[EXP_LED_COLOR_ID_G], colorVals[EXP_LED_COLOR_ID_B] ); // write to the gpios if (status == EXIT_SUCCESS) { status |= gpioObj.Write(pins[EXP_LED_COLOR_ID_R], !colorVals[EXP_LED_COLOR_ID_R]); status |= gpioObj.Write(pins[EXP_LED_COLOR_ID_G], !colorVals[EXP_LED_COLOR_ID_G]); status |= gpioObj.Write(pins[EXP_LED_COLOR_ID_B], !colorVals[EXP_LED_COLOR_ID_B]); } // generate the json return _GenerateOutJson(status); return (status); }
int ExpLed::_FunctionSetColor (void) { int status = EXIT_SUCCESS; int pinNum; int colorValue; char* colorName = new char[1024]; // Check that json has been parsed if ( !jsonDoc.IsObject() ) { return 1; } // JSON - find the color being used /* TO DO: change this to detect JSON{"color":"red","value":1} */ if ( jsonDoc.HasMember(EXP_LED_COLOR_R_STRING) ) { strcpy(colorName, EXP_LED_COLOR_R_STRING); pinNum = EXP_LED_COLOR_R_PIN_ID; } else if ( jsonDoc.HasMember(EXP_LED_COLOR_G_STRING) ) { strcpy(colorName, EXP_LED_COLOR_G_STRING); pinNum = EXP_LED_COLOR_G_PIN_ID; } else if ( jsonDoc.HasMember(EXP_LED_COLOR_B_STRING) ) { strcpy(colorName, EXP_LED_COLOR_B_STRING); pinNum = EXP_LED_COLOR_B_PIN_ID; } else { status = EXIT_FAILURE; } // JSON - find the value of the color status |= JsonGetInt(colorName, &colorValue ); // write to the gpio if (status == EXIT_SUCCESS) { status |= gpioObj.Write(pinNum, !colorValue ); } // generate the json return _GenerateOutJson(status); return (status); }
int main(int argc, char *argv[]) { json_object *main_obj = json_object_new_object(); json_object *parallel_obj = json_object_new_object(); json_object *problem_obj = 0; json_object *clargs_obj = 0; MACSIO_TIMING_GroupMask_t main_grp; MACSIO_TIMING_TimerId_t main_tid; int i, argi, exercise_scr = 0; int size = 1, rank = 0; /* quick pre-scan for scr cl flag */ for (i = 0; i < argc && !exercise_scr; i++) exercise_scr = !strcmp("exercise_scr", argv[i]); #warning SHOULD WE BE USING MPI-3 API #ifdef HAVE_MPI MPI_Init(&argc, &argv); #ifdef HAVE_SCR #warning SANITY CHECK WITH MIFFPP if (exercise_scr) SCR_Init(); #endif MPI_Comm_dup(MPI_COMM_WORLD, &MACSIO_MAIN_Comm); MPI_Errhandler_set(MACSIO_MAIN_Comm, MPI_ERRORS_RETURN); MPI_Comm_size(MACSIO_MAIN_Comm, &MACSIO_MAIN_Size); MPI_Comm_rank(MACSIO_MAIN_Comm, &MACSIO_MAIN_Rank); mpi_errno = MPI_SUCCESS; #endif errno = 0; main_grp = MACSIO_TIMING_GroupMask("MACSIO main()"); main_tid = MT_StartTimer("main", main_grp, MACSIO_TIMING_ITER_AUTO); MACSIO_LOG_StdErr = MACSIO_LOG_LogInit(MACSIO_MAIN_Comm, 0, 0, 0, 0); /* Process the command line and put the results in the problem */ clargs_obj = ProcessCommandLine(argc, argv, &argi); json_object_object_add(main_obj, "clargs", clargs_obj); strncpy(MACSIO_UTILS_UnitsPrefixSystem, JsonGetStr(clargs_obj, "units_prefix_system"), sizeof(MACSIO_UTILS_UnitsPrefixSystem)); MACSIO_LOG_MainLog = MACSIO_LOG_LogInit(MACSIO_MAIN_Comm, JsonGetStr(clargs_obj, "log_file_name"), JsonGetInt(clargs_obj, "log_line_length"), JsonGetInt(clargs_obj, "log_line_cnt/0"), JsonGetInt(clargs_obj, "log_line_cnt/1")); #warning THESE INITIALIZATIONS SHOULD BE IN MACSIO_LOG MACSIO_LOG_DebugLevel = JsonGetInt(clargs_obj, "debug_level"); /* Setup parallel information */ json_object_object_add(parallel_obj, "mpi_size", json_object_new_int(MACSIO_MAIN_Size)); json_object_object_add(parallel_obj, "mpi_rank", json_object_new_int(MACSIO_MAIN_Rank)); json_object_object_add(main_obj, "parallel", parallel_obj); #warning SHOULD WE INCLUDE TOP-LEVEL INFO ON VAR NAMES AND WHETHER THEYRE RESTRICTED #warning CREATE AN IO CONTEXT OBJECT /* Acquire an I/O context handle from the plugin */ /* Do a read or write test */ if (strcmp(JsonGetStr(clargs_obj, "read_path"),"null")) main_read(argi, argc, argv, main_obj); else main_write(argi, argc, argv, main_obj); /* stop total timer */ MT_StopTimer(main_tid); /* Write timings data file if requested */ if (strlen(JsonGetStr(clargs_obj, "timings_file_name"))) write_timings_file(JsonGetStr(clargs_obj, "timings_file_name")); MACSIO_TIMING_ClearTimers(MACSIO_TIMING_ALL_GROUPS); #warning ATEXIT THESE if (json_object_put(main_obj) != 1) { MACSIO_LOG_MSG(Info, ("Unable to free main JSON object")); } MACSIO_TIMING_GroupMask(0); MACSIO_TIMING_ReduceTimers(MACSIO_MAIN_Comm, -1); json_object_apath_get_string(0,0); /* free circ cache */ MACSIO_LOG_LogFinalize(MACSIO_LOG_MainLog); MACSIO_LOG_LogFinalize(MACSIO_LOG_StdErr); #ifdef HAVE_SCR if (exercise_scr) SCR_Finalize(); #endif #ifdef HAVE_MPI { int result; if ((MPI_Initialized(&result) == MPI_SUCCESS) && result) MPI_Finalize(); } #endif #warning FIX RETVAL OF MAIN TO BE NON-ZERO WHEN ERRORS OCCUR return (0); }
static int main_write(int argi, int argc, char **argv, json_object *main_obj) { int rank = 0, dumpNum = 0, dumpCount = 0; unsigned long long problem_nbytes, dumpBytes = 0, summedBytes = 0; char nbytes_str[32], seconds_str[32], bandwidth_str[32], seconds_str2[32]; double dumpTime = 0; double bandwidth, summedBandwidth; MACSIO_TIMING_GroupMask_t main_wr_grp = MACSIO_TIMING_GroupMask("main_write"); double dump_loop_start, dump_loop_end; double min_dump_loop_start, max_dump_loop_end; int exercise_scr = JsonGetInt(main_obj, "clargs/exercise_scr"); /* Sanity check args */ /* Generate a static problem object to dump on each dump */ json_object *problem_obj = MACSIO_DATA_GenerateTimeZeroDumpObject(main_obj,0); problem_nbytes = (unsigned long long) json_object_object_nbytes(problem_obj, JSON_C_FALSE); #warning MAKE JSON OBJECT KEY CASE CONSISTENT json_object_object_add(main_obj, "problem", problem_obj); /* Just here for debugging for the moment */ if (MACSIO_LOG_DebugLevel >= 2) { char outfName[256]; FILE *outf; int json_c_print_flags = JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED; if (MACSIO_LOG_DebugLevel < 3) json_c_print_flags |= JSON_C_TO_STRING_NO_EXTARR_VALS; snprintf(outfName, sizeof(outfName), "main_obj_write_%03d.json", MACSIO_MAIN_Rank); outf = fopen(outfName, "w"); fprintf(outf, "\"%s\"\n", json_object_to_json_string_ext(main_obj, json_c_print_flags)); fclose(outf); } #warning WERE NOT GENERATING OR WRITING ANY METADATA STUFF #warning MAKE THIS LOOP MORE LIKE A MAIN SIM LOOP WITH SIMPLE COMPUTE AND COMM STEP dump_loop_start = MT_Time(); dumpTime = 0.0; for (dumpNum = 0; dumpNum < json_object_path_get_int(main_obj, "clargs/num_dumps"); dumpNum++) { double dt; int scr_need_checkpoint_flag = 1; MACSIO_TIMING_TimerId_t heavy_dump_tid; #warning ADD OPTION TO UNLINK OLD FILE SETS #ifdef HAVE_SCR if (exercise_scr) SCR_Need_checkpoint(&scr_need_checkpoint_flag); #endif const MACSIO_IFACE_Handle_t *iface = MACSIO_IFACE_GetByName( json_object_path_get_string(main_obj, "clargs/interface")); /* log dump start */ if (!exercise_scr || scr_need_checkpoint_flag) { int scr_valid = 0; #ifdef HAVE_SCR if (exercise_scr) SCR_Start_checkpoint(); #endif /* Start dump timer */ heavy_dump_tid = MT_StartTimer("heavy dump", main_wr_grp, dumpNum); #warning REPLACE DUMPN AND DUMPT WITH A STATE TUPLE #warning SHOULD HAVE PLUGIN RETURN FILENAMES SO MACSIO CAN STAT FOR TOTAL BYTES ON DISK /* do the dump */ (*(iface->dumpFunc))(argi, argc, argv, main_obj, dumpNum, dumpTime); #ifdef HAVE_MPI mpi_errno = 0; #endif errno = 0; dt = MT_StopTimer(heavy_dump_tid); #ifdef HAVE_SCR if (exercise_scr) SCR_Complete_checkpoint(scr_valid); #endif } /* stop timer */ dumpTime += dt; dumpBytes += problem_nbytes; dumpCount += 1; /* log dump timing */ MACSIO_LOG_MSG(Info, ("Dump %02d BW: %s/%s = %s", dumpNum, MU_PrByts(problem_nbytes, 0, nbytes_str, sizeof(nbytes_str)), MU_PrSecs(dt, 0, seconds_str, sizeof(seconds_str)), MU_PrBW(problem_nbytes, dt, 0, bandwidth_str, sizeof(bandwidth_str)))); } dump_loop_end = MT_Time(); MACSIO_LOG_MSG(Info, ("Overall BW: %s/%s = %s", MU_PrByts(dumpBytes, 0, nbytes_str, sizeof(nbytes_str)), MU_PrSecs(dumpTime, 0, seconds_str, sizeof(seconds_str)), MU_PrBW(dumpBytes, dumpTime, 0, bandwidth_str, sizeof(bandwidth_str)))); bandwidth = dumpBytes / dumpTime; summedBandwidth = bandwidth; min_dump_loop_start = dump_loop_start; max_dump_loop_end = dump_loop_end; #ifdef HAVE_MPI MPI_Comm_rank(MACSIO_MAIN_Comm, &rank); MPI_Reduce(&bandwidth, &summedBandwidth, 1, MPI_DOUBLE, MPI_SUM, 0, MACSIO_MAIN_Comm); MPI_Reduce(&dumpBytes, &summedBytes, 1, MPI_UNSIGNED_LONG_LONG, MPI_SUM, 0, MACSIO_MAIN_Comm); MPI_Reduce(&dump_loop_start, &min_dump_loop_start, 1, MPI_DOUBLE, MPI_MIN, 0, MACSIO_MAIN_Comm); MPI_Reduce(&dump_loop_end, &max_dump_loop_end, 1, MPI_DOUBLE, MPI_MAX, 0, MACSIO_MAIN_Comm); #endif if (rank == 0) { MACSIO_LOG_MSG(Info, ("Summed BW: %s", MU_PrBW(summedBandwidth, 1.0, 0, bandwidth_str, sizeof(bandwidth_str)))); MACSIO_LOG_MSG(Info, ("Total Bytes: %s; Last finisher - First starter = %s; BW = %s", MU_PrByts(summedBytes, 0, nbytes_str, sizeof(nbytes_str)), MU_PrSecs(max_dump_loop_end - min_dump_loop_start, 0, seconds_str, sizeof(seconds_str)), MU_PrBW(summedBytes, max_dump_loop_end - min_dump_loop_start, 0, bandwidth_str, sizeof(bandwidth_str)))); } }