int main(int argc, char** argv) { States global_states_sets[4]; States* gsets = &global_states_sets[1]; if (register_program(f1a, "f1a") == false) { return -1; } #ifdef linux if (signal(SIGALRM, sig_alrm) == SIG_ERR) exit(-1); alarm(60); #endif std::cout << "TRY SVM method ...\n"; IIF_svm_learn isl(gsets, target_program); if (isl.learn() == 0) { return 0; } std::cout << "TRY SVM-I method ...\n"; IIF_svm_i_learn isil(gsets, target_program); if (isil.learn() == 0) { return 0; } //std::cout << "TRY other method again...\n"; return 0; }
/* Slurmctld and slurmd do not really build shared memory but they use that one built by sim_mgr */ int building_shared_memory(){ int fd; fd = shm_open(SLURM_SIM_SHM, O_RDWR, S_IRUSR | S_IWUSR); if(fd < 0){ printf("Error opening %s\n", SLURM_SIM_SHM); return -1; } ftruncate(fd, 8192); timemgr_data = mmap(0, 8192, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if(!timemgr_data){ printf("mmaping %s file can not be done\n", SLURM_SIM_SHM); return -1; } /* Initializing pointers to shared memory */ current_sim = timemgr_data + SIM_SECONDS_OFFSET; current_micro = timemgr_data + SIM_MICROSECONDS_OFFSET; threads_data = timemgr_data + SIM_SYNC_ARRAY_OFFSET; current_threads = timemgr_data + SIM_THREADS_COUNT_OFFSET; proto_threads = timemgr_data + SIM_PROTO_THREADS_OFFSET; sleep_map_array = timemgr_data + SIM_SLEEP_ARRAY_MAP_OFFSET; thread_exit_array = timemgr_data + SIM_THREAD_EXIT_MAP_OFFSET; thread_new_array = timemgr_data + SIM_THREAD_NEW_MAP_OFFSET; fast_threads_counter = timemgr_data + SIM_FAST_THREADS_OFFSET; pthread_create_counter = timemgr_data + SIM_PTHREAD_CREATE_COUNTER; pthread_exit_counter = timemgr_data + SIM_PTHREAD_EXIT_COUNTER; slurmctl_pid = timemgr_data + SIM_PTHREAD_SLURMCTL_PID; slurmd_pid = timemgr_data + SIM_PTHREAD_SLURMD_PID; if((slurmctl_pid[0] == 0) || (slurmd_pid[0] == 0)){ register_program(); if(init_semaphores() < 0){ printf("semaphores initialization failed\n"); return 1; } } return 0; }
int main(int argc, char *argv[]) { /* options */ char *section = NULL; int nfragments = GFARM_FILE_DONTCARE; /* -1, actually */ char *hostname = NULL; char *hostfile = NULL; char *domainname = NULL; char *e, *gfarm_url, *file_mode_arg; gfarm_mode_t file_mode = DEFAULT_FILE_MODE; int c, i, is_dir, index; struct gfs_stat gs; e = gfarm_initialize(&argc, &argv); if (e != NULL) { fprintf(stderr, "%s: %s\n", program_name, e); exit(EXIT_FAILURE); } /* Command options */ while ((c = getopt(argc, argv, "a:fh:D:I:N:?")) != -1) { switch (c) { case 'I': case 'a': section = optarg; break; case 'N': nfragments = strtol(optarg, NULL, 0); break; case 'h': hostname = optarg; break; case 'D': domainname = optarg; break; case 'f': opt_force = 1; break; case '?': default: usage(); } } argc -= optind; argv += optind; if (argc == 0) { fprintf(stderr, "%s: missing a local filename\n", program_name); usage(); } if (argc == 1) { fprintf(stderr, "%s: missing a Gfarm URL\n", program_name); usage(); } gfarm_url = argv[argc - 1]; --argc; if (!gfarm_is_url(gfarm_url)) { fprintf(stderr, "%s: %s: %s\n", program_name, gfarm_url, GFARM_ERR_GFARM_URL_PREFIX_IS_MISSING); exit(EXIT_FAILURE); } c = 0; if (hostname != NULL) c++; if (hostfile != NULL) c++; if (domainname != NULL) c++; if (c > 1) { fprintf(stderr, "%s: more than one options are specified " "from -h, -H and -D\n", program_name); usage(); } /* * distinguish which mode is specified: * 1. program mode: * gfreg [-h <hostname>] [-a <architecture>] \ * <local-program>... <gfarm-URL> * 2. auto index mode: * gfreg [-h <hostname>] [-H <hostfile>] [-D <domainname>] \ * <local-file>... <gfarm-URL> * 3. fragment mode: * gfreg [-h <hostname>] [-N <nfragments>] -I <index> \ * <local-file>... <gfarm-URL> */ e = gfs_stat(gfarm_url, &gs); if (e == GFARM_ERR_NO_SUCH_OBJECT) { is_dir = 0; file_mode_arg = NULL; } else if (e != NULL) { fprintf(stderr, "%s: %s: %s\n", program_name, gfarm_url, e); exit(EXIT_FAILURE); } else { if (GFARM_S_ISREG(gs.st_mode)) { is_dir = 0; file_mode_arg = gfarm_url; file_mode = gs.st_mode; } else if (GFARM_S_ISDIR(gs.st_mode)) { is_dir = 1; file_mode_arg = NULL; } else { /* defensive programming. this shouldn't happen. */ fprintf(stderr, "%s: %s: unknown file type\n", program_name, gfarm_url); exit(EXIT_FAILURE); } gfs_stat_free(&gs); } c = 0; /* count of "-" in the arguments */ if (hostfile != NULL && strcmp(hostfile, STDIN_FILENAME) == 0) ++c; for (i = 0; i < argc; i++) { int fd, fd_needs_close; gfarm_mode_t m; if (!open_file(argv[i], &fd, &fd_needs_close)) exit(EXIT_FAILURE); if (!get_mode(fd, argv[i], &m)) exit(EXIT_FAILURE); if (S_ISREG(m)) { if (file_mode_arg == NULL) { /* * NOTE: this mode may be used for the mode * to create the gfarm file. */ file_mode_arg = argv[i]; file_mode = m & FILE_MODE_MASK; } if (((m & 0111) != 0) != ((file_mode & 0111) != 0)) { fprintf(stderr, "%s: program and non-program are mixed in " "%s and %s\n", program_name, file_mode_arg, argv[i]); exit(EXIT_FAILURE); } } else if (fd_needs_close) { /* if it's "-", allow non-file (e.g. pipe) */ fprintf(stderr, "%s: %s: not a regular file\n", program_name, argv[i]); exit(EXIT_FAILURE); } if (fd_needs_close) { close(fd); } else if (++c > 1) { fprintf(stderr, "%s: `-' (stdin) is specified " "multiple times\n", program_name); exit(EXIT_FAILURE); } } if ((file_mode & 0111) != 0) { /* * program mode */ int section_alloced = 0; if (!is_dir && argc != 1) { fprintf(stderr, "%s: only one file can be specified to" " register the gfarm program `%s'\n", program_name, gfarm_url); exit(EXIT_FAILURE); } if (hostfile != NULL || domainname != NULL) { fprintf(stderr, "%s: cannot use -%c to register programs\n", program_name, hostfile != NULL ? 'H' : 'D'); exit(EXIT_FAILURE); } if (nfragments != GFARM_FILE_DONTCARE) { /* * XXX - call gfarm_url_replicate() to replicate * `nfragments' copies of gfarm_url:section? */ fprintf(stderr, "%s: warning: option -N is currently ignored\n", program_name); } if (section != NULL) { ; } else if (hostname != NULL) { char *canonical; e = gfarm_host_get_canonical_name(hostname, &canonical); if (e != NULL) { if (e == GFARM_ERR_NO_SUCH_OBJECT) e = "not a filesystem node"; fprintf(stderr, "%s: host %s: %s\n", program_name, hostname, e); exit(EXIT_FAILURE); } section_alloced = 1; section = gfarm_host_info_get_architecture_by_host( canonical); free(canonical); if (section == NULL) { fprintf(stderr, "%s: %s\n", program_name, GFARM_ERR_NO_MEMORY); exit(EXIT_FAILURE); } } else if (gfarm_host_get_self_architecture(§ion) != NULL){ fprintf(stderr, "%s: missing -a option\n", program_name); exit(EXIT_FAILURE); } for (i = 0; i < argc; i++) { register_program(is_dir, gfarm_url, section, hostname, argv[i], file_mode_arg == gfarm_url || file_mode_arg == argv[i], file_mode); } if (section_alloced) free(section); } else if (section != NULL || gfs_pio_get_node_rank(&index) == NULL) { /* * fragment mode */ if (section != NULL) index = strtol(section, NULL, 0); else if (nfragments == GFARM_FILE_DONTCARE) gfs_pio_get_node_size(&nfragments); if (!is_dir && argc != 1) { fprintf(stderr, "%s: only one file can be specified to" " register a fragment %s of the gfarm file `%s'\n", program_name, section, gfarm_url); exit(EXIT_FAILURE); } if (hostfile != NULL || domainname != NULL) { fprintf(stderr, "%s: cannot use -%c with -I\n", program_name, hostfile != NULL ? 'H' : 'D'); exit(EXIT_FAILURE); } for (i = 0; i < argc; i++) { register_fragment(is_dir, gfarm_url, index, nfragments, hostname, argv[i], file_mode_arg == gfarm_url || file_mode_arg == argv[i], file_mode); } } else { /* * auto index mode */ char **hosts = NULL; if (nfragments == GFARM_FILE_DONTCARE) nfragments = argc; if (nfragments != argc) { fprintf(stderr, "%s: local file number %d " "doesn't match with -N %d\n", program_name, argc, nfragments); exit(EXIT_FAILURE); } if (is_dir && nfragments > 1) { fprintf(stderr, "%s: cannot determine the file name " "under the directory %s, " "because multiple local file names are specifed\n", program_name, gfarm_url); exit(EXIT_FAILURE); } if (hostname != NULL) { ; } else if (hostfile != NULL) { int nhosts, error_line; e = gfarm_hostlist_read(hostfile, &nhosts, &hosts, &error_line); if (e != NULL) { if (error_line != -1) fprintf(stderr, "%s: %s line %d: %s\n", program_name, hostfile, error_line, e); else fprintf(stderr, "%s: %s: %s\n", program_name, hostfile, e); exit(EXIT_FAILURE); } } else { hosts = malloc(sizeof(*hosts) * nfragments); if (hosts == NULL) { fprintf(stderr, "%s: %s\n", program_name, GFARM_ERR_NO_MEMORY); exit(EXIT_FAILURE); } if (domainname != NULL) e = gfarm_schedule_search_idle_by_domainname( domainname, nfragments, hosts); else e = gfarm_schedule_search_idle_by_all( nfragments, hosts); if (e != NULL) { fprintf(stderr, "%s: selecting filesystem nodes: %s\n", program_name, e); exit(EXIT_FAILURE); } } /* XXX - need to register in parallel? */ for (i = 0; i < argc; i++) { register_fragment(is_dir, gfarm_url, i, nfragments, hostname != NULL ? hostname : hosts[i], argv[i], 1, file_mode); } if (hostname == NULL) gfarm_strings_free_deeply(nfragments, hosts); } e = gfarm_terminate(); if (e != NULL) { fprintf(stderr, "%s: %s\n", program_name, e); exit(EXIT_FAILURE); } exit(error_happened); }