int init_conf() { char *val = NULL; struct sockaddr_in s_addr; query_conf *general = NULL; query_conf *conf = NULL; if ((conf = load_configuration(sconf_file)) == NULL) { return -1; } if ((general = find_label(conf, (char*)"socket")) == NULL) { free_configuration(&conf); return -1; } if ((val = get_value_from_label(general, (char*)"synconf_ip")) != NULL) sc.s_ip = inet_atoul(val); printf("ip:%s\n", val); if ((val = get_value_from_label(general, (char*)"synconf_port")) != NULL) sc.s_port = (unsigned short)atoi(val); printf("port:%d\n", sc.s_port); free_configuration(&conf); return 0; }
API_EXPORTED struct eegdev* egd_open(const char* confstring) { struct conf cf; struct eegdev* dev = NULL; const char* device; // Load global configuration if (init_configuration(&cf, confstring) || load_configuration_file(&cf, "eegdev.conf", 1)) { free_configuration(&cf); return NULL; } // Get device type device = get_conf_setting(&cf, "device", "any"); if (!strcmp(device, "any")) dev = open_any(&cf); else dev = open_plugin_device(device, &cf); free_configuration(&cf); return dev; }
void deal_all_label_value(query_conf *que, char *item_name) { conf_item *item = NULL; char *res = NULL; if ((que == NULL) || (item_name == NULL)) return; query_conf *mod_option_conf = NULL; query_conf *mod_items_conf = NULL; query_conf *mod_item_label_name = NULL; char *mod_items_path = "mod_items.conf"; if ((mod_items_conf = load_configuration(mod_items_path)) == NULL) { return; } item = que->label_item; while (item != NULL) { if (strcmp(item->item_value, "yes") == 0) { if ((mod_item_label_name = find_label(mod_items_conf, item->item_name)) == NULL) { free_configuration(&mod_items_conf); return; } deal_all_item_value(mod_item_label_name, "null"); } //printf("%s\n", item->item_value); item = item->item_next; } }
int load_proxy_config(const char *config_name, int pmid, int proxy_sign, char value[C_TOTAL][32]) { const static char FLG_PLATFORM_CONF[] = "platform="; int i = 0; int ret = 1; query_conf *pconf = NULL; query_conf *pplatform = NULL; char cfg_path[256] = {0}; char plat_flg[32] = {0}; char *val = NULL; sprintf(cfg_path, "%s/%s", PLATFORM_CONFIG_DIR, config_name); sprintf(plat_flg, "%s%d", FLG_PLATFORM_CONF, pmid); if ((pconf = load_configuration(cfg_path)) == NULL) { //printf("open conf file:%s\n", cfg_path); loginf_out("读取平台配置失败!"); return -1; } if ((pplatform = find_label(pconf, plat_flg)) == NULL) { free_configuration(&pconf); loginf_fmt("没有平台ID为[%d]的配置项", pmid); return -1; } for (i = 0; i < C_TOTAL; ++i) { memset(value[i], 0, sizeof(value[i])); if (proxy_sign == PROXY_AUTH_SERVER && i == L_VIDEOIP) break; if ((val = get_value_from_label(pplatform, m_conf_key[i])) == NULL) { loginf_fmt("缺少配置项\"%s\"", m_conf_key[i]); ret = -1; break; } strcpy(value[i], val); } free_configuration(&pconf); return ret; }
int main() { char *val = NULL; char *mod_option_path = "mod_option.conf"; struct sockaddr_in s_addr; query_conf *general = NULL; query_conf *mod_option_conf = NULL; if ((mod_option_conf = load_configuration(mod_option_path)) == NULL) { return -1; } if ((general = find_label(mod_option_conf, (char*)"mod_option")) == NULL) { free_configuration(&mod_option_conf); return -1; } deal_all_label_value(general, "null"); /* if ((val = get_value_from_label(general, (char*)"synconf_ip")) != NULL) __sc.s_ip = inet_atoul(val); printf("ip:%s\n", val); if ((val = get_value_from_label(general, (char*)"synconf_port")) != NULL) __sc.s_port = inet_atoul(val); printf("port:%s\n", val); s_addr.sin_family = AF_INET; s_addr.sin_port = htons(__sc.s_port); s_addr.sin_addr.s_addr = htonl(__sc.s_ip); */ free_configuration(&mod_option_conf); return 0; }
int main( int argc, char *argv[] ) { char sectype_code = '_'; MarFS_SecType marfs_sectype; char compType_code = '_'; MarFS_CompType marfs_comptype; char comptype_code = '_'; MarFS_CorrectType marfs_correcttype; char code; int ret_val; MarFS_Namespace_Ptr namespacePtr; MarFS_Repo_Ptr repoPtr; INIT_LOG(); fprintf( stdout, "\n" ); if (read_configuration()) { fprintf( stderr, "ERROR: Reading MarFS configuration failed.\n" ); return 1; } fprintf( stdout, "CORRECT: The members of the MarFS config structure are:\n" ); fprintf( stdout, "\tconfig name : %s\n", marfs_config->name ); fprintf( stdout, "\tconfig version : %d.%d\n", marfs_config->version_major, marfs_config->version_minor ); fprintf( stdout, "\tconfig mnt-top : %s\n", marfs_config->mnt_top ); // fprintf( stdout, "\tconfig namespace count : %lu\n", marfs_config->namespace_count ); fprintf( stdout, "\n" ); ret_val = free_configuration(); if ( ! ret_val ) { fprintf( stdout, "CORRECT: free_configuration returned %d\n", ret_val ); if ( marfs_config == NULL ) { fprintf( stdout, "CORRECT: We freed the MarFS configuration and it is now NULL.\n" ); } else { fprintf( stderr, "ERROR: free_configuration did not set the MarFS configuration to NULL.\n" ); } } else { fprintf( stderr, "ERROR: free_configuration returned %d\n", ret_val ); } fprintf( stdout, "\n" ); fprintf( stdout, "Re-reading the configuration to continue testing...\n" ); read_configuration(); if ( marfs_config == NULL ) { fprintf( stderr, "ERROR: Reading MarFS configuration failed.\n" ); return 1; } fprintf( stdout, "\n" ); if ( lookup_sectype( "none", &marfs_sectype )) { fprintf( stderr, "ERROR: Invalid sectype value of \"%s\".\n", "none" ); } else { fprintf( stdout, "CORRECT: SecType value of \"%s\" translates to %d.\n", "none", marfs_sectype ); } if ( encode_sectype( SECTYPE_NONE, &code )) { fprintf( stderr, "ERROR: Invalid enumeration value of %d.\n", SECTYPE_NONE ); } else { fprintf( stdout, "CORRECT: Encode value of %d is \"%c\".\n", SECTYPE_NONE, code ); } if ( decode_sectype( '_', &marfs_sectype )) { fprintf( stderr, "ERROR: Invalid code of \"%c\".\n", '_' ); } else { fprintf( stdout, "CORRECT: Decode code of \"%c\" is %d.\n", '_',marfs_sectype ); } fprintf( stdout, "\n" ); if ( lookup_comptype( "none", &marfs_comptype )) { fprintf( stderr, "ERROR: Invalid comptype value of \"%s\".\n", "none" ); } else { fprintf( stdout, "CORRECT: CompType value of \"%s\" translates to %d.\n", "none", marfs_comptype ); } if ( encode_comptype( COMPTYPE_NONE, &code )) { fprintf( stderr, "ERROR: Invalid enumeration value of %d.\n", COMPTYPE_NONE ); } else { fprintf( stdout, "CORRECT: Encode value of %d is \"%c\".\n", COMPTYPE_NONE, code ); } if ( decode_comptype( '_', &marfs_comptype )) { fprintf( stderr, "ERROR: Invalid code of \"%c\".\n", '_' ); } else { fprintf( stdout, "CORRECT: Decode code of \"%c\" is %d.\n", '_',marfs_comptype ); } fprintf( stdout, "\n" ); if ( lookup_correcttype( "none", &marfs_correcttype )) { fprintf( stderr, "ERROR: Invalid correcttype value of \"%s\".\n", "none" ); } else { fprintf( stdout, "CORRECT: CorrectType value of \"%s\" translates to %d.\n", "none", marfs_correcttype ); } if ( encode_correcttype( CORRECTTYPE_NONE, &code )) { fprintf( stderr, "ERROR: Invalid enumeration value of %d.\n", CORRECTTYPE_NONE ); } else { fprintf( stdout, "CORRECT: Encode value of %d is \"%c\".\n", CORRECTTYPE_NONE, code ); } if ( decode_correcttype( '_', &marfs_correcttype )) { fprintf( stderr, "ERROR: Invalid code of \"%c\".\n", '_' ); } else { fprintf( stdout, "CORRECT: Decode code of \"%c\" is %d.\n", '_',marfs_correcttype ); } fprintf( stdout, "\n" ); namespacePtr = find_namespace_by_name( "BoGuS" ); if ( namespacePtr == NULL ) { fprintf( stdout, "CORRECT: Namespace \"BoGuS\" does not exist.\n" ); } else { fprintf( stderr, "ERROR: Namespace \"BoGuS\" does not exist and was found.\n" ); } fprintf( stdout, "\n" ); namespacePtr = find_namespace_by_name( "s3" ); if ( namespacePtr != NULL ) { fprintf( stdout, "CORRECT: Namespace \"s3\" does exist and has mnt_path \"%s\".\n", namespacePtr->mnt_path ); } else { fprintf( stderr, "ERROR: Namespace \"s3\" does exist and was not found.\n" ); } fprintf( stdout, "\n" ); namespacePtr = find_namespace_by_mnt_path( "/BoGuS" ); if ( namespacePtr == NULL ) { fprintf( stdout, "CORRECT: Mntpath \"/BoGuS\" does not exist.\n" ); } else { fprintf( stderr, "ERROR: Mntpath \"/BoGuS\" does not exist and was found.\n" ); } fprintf( stdout, "\n" ); namespacePtr = find_namespace_by_mnt_path( "/s3" ); if ( namespacePtr != NULL ) { fprintf( stdout, "CORRECT: Mntpath \"/s3\" does exist and has name \"%s\".\n", namespacePtr->name ); } else { fprintf( stderr, "ERROR: Mntpath \"/s3\" does exist and was not found.\n" ); } repoPtr = find_repo_by_range( namespacePtr, 38 ); if ( repoPtr != NULL ) { fprintf( stdout, "CORRECT: Namespace \"%s\" has a repo \"%s\" for files of size 38.\n", namespacePtr->name, repoPtr->name ); } else { fprintf( stderr, "ERROR: Namespace \"%s\" should have a repo for files of size 38.\n", namespacePtr->name ); } fprintf( stdout, "\n" ); namespacePtr = find_namespace_by_mnt_path( "/" ); if ( namespacePtr != NULL ) { fprintf( stdout, "CORRECT: Mntpath \"/\" does exist and has name \"%s\".\n", namespacePtr->name ); } else { fprintf( stderr, "ERROR: Mntpath \"/\" does exist and was not found.\n" ); } fprintf( stdout, "\n" ); /* * Since the file_size argument is size_t, that is unsigned and negative numbers * are not allowed. * fprintf( stdout, "\n" ); repoPtr = find_repo_by_range( namespacePtr, -2 ); if ( repoPtr == NULL ) { fprintf( stdout, "CORRECT: Namespace \"%s\" should not have a repo for files of size -2.\n", namespacePtr->name ); } else { fprintf( stderr, "ERROR: Namespace \"%s\" incorrectly has a repo \"%s\" for files of size -2.\n", namespacePtr->name, repoPtr->repo_name ); } */ fprintf( stdout, "\n" ); repoPtr = find_repo_by_range( NULL, 38 ); if ( repoPtr == NULL ) { fprintf( stdout, "CORRECT: A NULL namespace should not have a repo for files of size 38.\n" ); } else { fprintf( stderr, "ERROR: A NULL namespace incorrectly has a repo \"%s\" for files of size 38.\n", repoPtr->name ); } fprintf( stdout, "\n" ); repoPtr = find_repo_by_name( "BoGuS" ); if ( repoPtr == NULL ) { fprintf( stdout, "CORRECT: Repo name \"BoGuS\" does not exist.\n" ); } else { fprintf( stderr, "ERROR: Repo name \"BoGuS\" does not exist and was found.\n" ); } fprintf( stdout, "\n" ); repoPtr = find_repo_by_name( "emcS3_00" ); if ( repoPtr != NULL ) { fprintf( stdout, "CORRECT: Repo name \"emcS3_00\" does exist and has host \"%s\".\n", repoPtr->host ); } else { fprintf( stderr, "ERROR: Repo name \"emcS3_00\" does exist and was not found.\n" ); } fprintf( stdout, "\n" ); // --- show contents of all repos RepoIterator rit = repo_iterator(); while (( repoPtr = repo_next( &rit )) != NULL ) { debug_repo(repoPtr); fprintf(stdout, "\n"); } fprintf(stdout, "\n"); // --- show contents of all namespaces NSIterator nit = namespace_iterator(); while (( namespacePtr = namespace_next( &nit )) != NULL ) { debug_namespace(namespacePtr); fprintf(stdout, "\n"); } fprintf( stdout, "\n" ); return 0; }
int main ( int argc, char* argv[] ) { char *distroname = NULL; int valid_args , c; while (1) { int option_index = 0; c = getopt_long_only( argc , argv , "d:" , long_options , &option_index ); if (c == -1) break; switch (c) { case 'd': distroname = malloc( strlen(optarg) * sizeof(char) ); strcpy( distroname , optarg ); break; } } valid_args = argc - ( optind - 1 ); if ( valid_args < 2 ) { print_usage( argv[0] ); exit(1); } if ( strcmp( argv[optind] , "register" ) == 0 ) { if ( valid_args != 4 ) { printf( "Usage register\n" ); exit(1); } } if ( strcmp( argv[optind] , "login" ) == 0 ) { if ( valid_args != 2 ) { printf( "Usage login\n" ); exit(1); } } if ( strcmp( argv[optind] , "loginout" ) == 0 ) { if ( valid_args != 3 ) { printf( "Usage logout\n" ); exit(1); } } // TODO : Use a define instead of 256 AMEBA_SESSID_MAX_LENGTH char *sessid = malloc( 256 * sizeof(char) ); memset( sessid , '\0' , 256 ); if ( strncmp( argv[optind] , "login" , 5 ) == 0 ) { GKeyFile *config = get_configuration(); if ( ! check_configuration( config , 1 ) ) { printf("No valid configuration exists\n"); free_configuration( config ); exit(2); } login_node( get_configuration_value( config , "url" ) , get_configuration_value( config , "uuid" ) , sessid ); free_configuration( config ); } if ( strcmp( argv[optind] , "loginout" ) == 0 ) { GKeyFile *config = get_configuration(); if ( ! check_configuration( config , 1 ) ) { printf("No valid configuration exists\n"); free_configuration( config ); exit(2); } logout_node( get_configuration_value( config , "url" ) , sessid , argv[optind+1] ); free_configuration( config ); } if ( strcmp( argv[optind] , "register" ) == 0 ) { nodeinfo *nodedata = get_nodeinfo( argv[optind+2] , distroname ); if ( ! nodedata ) { exit(-255); } register_node( argv[optind+1] , nodedata ); free_nodeinfo( nodedata ); } free(sessid); exit(0); }
/****************************************************************************** * Main of the parallel sampling sort ******************************************************************************/ int main(int argc, char **argv){ int mpi_size, mpi_rank; double t0, t1; int is_help; char *final_buff; unsigned long long rsize; MPI_Comm comm = MPI_COMM_WORLD; MPI_Init(&argc, &argv); MPI_Comm_size(comm, &mpi_size); MPI_Comm_rank(comm, &mpi_rank); t0 = MPI_Wtime(); config_t *config = (config_t *)malloc(sizeof(config_t)); config_t *config_init = (config_t *)malloc(sizeof(config_t)); init_configuration(config); init_configuration(config_init); is_help = get_configuration(argc, argv, mpi_rank, config_init); // when -h flag is set to seek help of how to use this program if (is_help) { free_configuration(config); free_configuration(config_init); MPI_Finalize(); return 1; } copy_configuration(config, config_init); int ntf, mtf, tstep, nsteps_tot; mtf = config->tmin / config->tinterval; ntf = config->tmax / config->tinterval + 1; if (config->nsteps == 1) { nsteps_tot = ntf; } else { nsteps_tot = config->tmax; } // Get the particle tags from sorted-by-energy data of the last time frame, // and then sort the tags int *tags, qindex; int row_size, dataset_num, max_type_size, key_value_type; char *tracked_particles, *tracked_particles_sum, *package_data; dset_name_item *dname_array; hsize_t my_data_size, rest_size; if (config->tracking_traj) { tags = (int *)malloc(config->nptl_traj * sizeof(int)); char filename_ene[MAX_FILENAME_LEN]; tstep = (ntf - 1) * config->tinterval; snprintf(filename_ene, MAX_FILENAME_LEN, "%s%s%d%s%s%s", config->filepath, "/T.", tstep, "/", config->species, "_tracer_energy_sorted.h5p"); if (config->nsteps != 1) tstep--; // get particle tags w.r.t some energy get_particle_tags(filename_ene, tstep, config->ratio_emax, config->nptl_traj, tags); // sort the tags qsort(tags, config->nptl_traj, sizeof(int), CompareInt32Value); // get the indices for Ux and q in the HDF5 file snprintf(config->group_name, MAX_FILENAME_LEN, "%s%d", "/Step#", tstep); dname_array = (dset_name_item *)malloc(MAX_DATASET_NUM * sizeof(dset_name_item)); package_data = get_vpic_pure_data_h5(mpi_rank, mpi_size, filename_ene, config->group_name, &row_size, &my_data_size, &rest_size, &dataset_num, &max_type_size, &key_value_type, dname_array); free(package_data); qindex = get_dataset_index("q", dname_array, dataset_num); config->ux_kindex = get_dataset_index("Ux", dname_array, dataset_num); tracked_particles = (char *)malloc(nsteps_tot * config->nptl_traj * row_size); for (int j = 0; j < nsteps_tot*config->nptl_traj*row_size; j++) { tracked_particles[j] = 0; } if (mpi_rank == 0) { tracked_particles_sum = (char *)malloc(nsteps_tot * config->nptl_traj * row_size); for (int j = 0; j < nsteps_tot*config->nptl_traj*row_size; j++) { tracked_particles_sum[j] = 0; } } } // if (config->tracking_traj) if (config->multi_tsteps) { for (int i = mtf; i < ntf; i++) { tstep = i * config->tinterval; if (mpi_rank == 0) printf("Time Step: %d\n", tstep); if (config->reduced_tracer) { set_filenames_reduced(tstep, config->filepath, config->species, config->filename, config->group_name, config->filename_sorted, config->filename_attribute, config->filename_meta); } else { set_filenames(tstep, config_init, config); } if (config->nsteps == 1) { final_buff = sorting_single_tstep(mpi_size, mpi_rank, config, &rsize); if (config->tracking_traj) { get_tracked_particle_info(final_buff, qindex, row_size, rsize, i, ntf, tags, config->nptl_traj, tracked_particles); } if(config->collect_data == 1) { free(final_buff); } } else { for (tstep = (i-1) * config->tinterval; tstep < i*config->tinterval; tstep++) { snprintf(config->group_name, MAX_FILENAME_LEN, "%s%d", "/Step#", tstep); final_buff = sorting_single_tstep(mpi_size, mpi_rank, config, &rsize); if (config->tracking_traj) { get_tracked_particle_info(final_buff, qindex, row_size, rsize, tstep, nsteps_tot, tags, config->nptl_traj, tracked_particles); } if(config->collect_data == 1) { free(final_buff); } } } } } else { if (mpi_rank == 0) { printf("Input filename: %s\n", config->filename); printf("Group name: %s\n", config->group_name); printf("Output filename: %s\n", config->filename_sorted); printf("Meta data filename: %s\n", config->filename_meta); } set_filenames(config->tstep, config_init, config); final_buff = sorting_single_tstep(mpi_size, mpi_rank, config, &rsize); if(config->collect_data == 1) { free(final_buff); } } MPI_Barrier(MPI_COMM_WORLD); if (config->tracking_traj) { MPI_Reduce(tracked_particles, tracked_particles_sum, nsteps_tot*config->nptl_traj*row_size, MPI_CHAR, MPI_SUM, 0, MPI_COMM_WORLD); /* Save the particle data. */ if (mpi_rank == 0) { save_tracked_particles(config->filename_traj, tracked_particles_sum, nsteps_tot, config->nptl_traj, row_size, dataset_num, max_type_size, dname_array, tags); } free(tracked_particles); if (mpi_rank == 0) { free(tracked_particles_sum); } free(tags); free(dname_array); } MPI_Barrier(MPI_COMM_WORLD); t1 = MPI_Wtime(); if(mpi_rank == 0) { printf("Overall time is [%f]s \n", (t1 - t0)); } free_configuration(config); free_configuration(config_init); MPI_Finalize(); return 0; }