sk_ptr_t sk_event_module_init(sk_cycle_t *cycle) { sk_shm_t shm; size_t size,cl; u_char *shared; int limit; struct rlimit rlmt; if(getrlimit(RLIMIT_NOFILE,&rlmt) == -1){ //ERR LOG } if(sk_accept_mutex_ptr){ return SK_OK; } cl = 128; size = cl /*sk_accept_mutex*/ +cl /*sk_connection_counter*/ +cl;/*sk_temp_number*/ shm.size = size; shm.name.len = sizeof("sk_share_zone"); shm.name.data = (u_char*)"sk_share_zone"; shm.log = cycle->log; if(sk_shm_alloc(&shm) != SK_OK){ FATAL_ERR("malloc shmtx error"); return SK_ERR; } shared = shm.addr; sk_accept_mutex_ptr = (sk_atomic_t *)shared; sk_accept_mutex.spin = (sk_uptr_t) -1; if(sk_shmtx_create(&sk_accept_mutex,shared,cycle->lock_file.data)!= SK_OK){ FATAL_ERR("malloc shmtx error"); return SK_ERR; } sk_mempool_mutex.spin = (sk_uptr_t) -1; if(sk_shmtx_create(&sk_mempool_mutex,shared,cycle->lock_file.data)!= SK_OK){ FATAL_ERR("malloc shmtx error"); return SK_ERR; } sk_connection_counter = (sk_atomic_t *)(shared +1 * cl); (void)sk_atomic_cmp_set(sk_connection_counter,0,1); //sk_temp_number = (sk_atomic_t *)(shared+2 * cl); cycle->connection_n = 1024; return SK_OK; }
/** * @brief * * @param s * @param dims * @param size */ static void parse_dims(const char* s, size_t** dims, size_t* size) { if(s == NULL){ return; } const char* seps = ":"; char sep = seps[0]; size_t len = strlen(s); char* s_copy = malloc(sizeof(char*) * len + 1); strcpy(s_copy, s); // Count separators (*size) = 0; for (size_t i = 0; i < len; ++i) { if (s_copy[i] == sep) { ++(*size); } } ++(*size); *dims = (size_t*) malloc(*size * sizeof(*dims)); // Get values char *pch = strtok(s_copy, seps); char *end = NULL; size_t i = 0; while (pch != NULL) { (*dims)[i] = (size_t) strtol(pch, &end, 10); pch=strtok(NULL, seps); ++i; } free(s_copy); // Sanity checks if (i != *size) { FATAL_ERR("Couldn't parse dimensions from %s. Correct format is t:x:y:z\n", s); } for (size_t i = 0; i < *size; ++i) { if ((*dims)[i] <= 0) { FATAL_ERR("Bad dimension specifications in %s (parsed value is <0)\n", s); } } }
ssize_t cstp_send_file(worker_st *ws, const char *file) { FILE* fp; char buf[512]; ssize_t len, total = 0; int ret; fp = fopen(file, "r"); if (fp == NULL) return GNUTLS_E_FILE_ERROR; while ( (len = fread( buf, 1, sizeof(buf), fp)) > 0) { ret = cstp_send(ws, buf, len); FATAL_ERR(ws, ret); total += ret; } fclose(fp); return total; }
int main(int argc, char ** argv){ MPI_Init(&argc, &argv); // Default values struct args args; args.procs.nn = 0; args.procs.ppn = 0; args.dgeom_size = 0; args.dgeom = NULL; args.bgeom_size = 0; args.bgeom = NULL; args.cgeom_size = 0; args.cgeom = NULL; args.testfn = NULL; args.write_test = 0; args.read_test = 0; args.report_type = REPORT_HUMAN; args.par_access = NC_INDEPENDENT; args.is_unlimited = 0; args.verify = 0; args.fill_value = 0; char * dg = NULL, * bg = NULL, *cg = NULL, *iot = "ind", *xf = "human"; option_help options [] = { {'n' , "nn" , "Number of nodes" , OPTION_OPTIONAL_ARGUMENT , 'd' , & args.procs.nn} , {'p' , "ppn" , "Number of processes" , OPTION_OPTIONAL_ARGUMENT , 'd' , & args.procs.ppn} , {'d' , "data-geometry" , "Data geometry (t:x:y:z)" , OPTION_OPTIONAL_ARGUMENT , 's' , & dg} , {'b' , "block-geometry" , "Block geometry (t:x:y:z)" , OPTION_OPTIONAL_ARGUMENT , 's' , & bg} , {'c' , "chunk-geometry" , "Chunk geometry (t:x:y:z|auto)" , OPTION_OPTIONAL_ARGUMENT , 's' , & cg} , {'r' , "read" , "Enable read benchmark" , OPTION_FLAG , 'd' , & args.read_test} , {'w' , "write" , "Enable write benchmark" , OPTION_FLAG , 'd' , & args.write_test} , {'t' , "io-type" , "Independent / Collective I/O (ind|coll)" , OPTION_OPTIONAL_ARGUMENT , 's' , & iot} , {'u' , "unlimited" , "Enable unlimited time dimension" , OPTION_FLAG , 'd' , & args.is_unlimited} , {'f' , "testfile" , "Filename of the testfile" , OPTION_OPTIONAL_ARGUMENT , 's' , & args.testfn} , {'x' , "output-format" , "Output-Format (parser|human)" , OPTION_OPTIONAL_ARGUMENT , 's' , & xf} , {'F' , "use-fill-value" , "Write a fill value" , OPTION_FLAG , 'd', & args.fill_value} , {0 , "verify" , "Verify that the data read is correct (reads the data again)", OPTION_FLAG , 'd' , & args.verify} , LAST_OPTION }; int rank; MPI_Comm_rank(MPI_COMM_WORLD, & rank); // check the correctness of the options only for rank 0 if (rank == 0){ printf("Benchtool (datatype: %s) \n", xstr(DATATYPE)); parseOptions(argc, argv, options); } MPI_Barrier(MPI_COMM_WORLD); if (rank != 0){ parseOptions(argc, argv, options); } parse_dims(dg, &args.dgeom, &args.dgeom_size); parse_dims(bg, &args.bgeom, &args.bgeom_size); if ((0 == strcmp(iot, "c")) | (0 == strcmp(iot, "coll")) | (0 == strcmp(iot,"collective"))) { args.par_access = NC_COLLECTIVE; } else if ((0 == strcmp(iot, "i")) | (0 == strcmp(iot, "ind")) | (0 == strcmp(iot, "independent"))) { args.par_access = NC_INDEPENDENT; } else { FATAL_ERR("Unsupported parallel access type %s\n", xf); } if (0 == strcmp(xf, "parser")) { args.report_type = REPORT_PARSER; }else if (0 == strcmp(xf, "human")) { args.report_type = REPORT_HUMAN; }else{ FATAL_ERR("Unsupported report type %s\n", xf); } if (0 == args.procs.nn) { char *end = NULL; const char* env = getenv("SLURM_NNODES"); if (NULL != env) { args.procs.nn = strtol(env, &end, 10); } if (0 == args.procs.nn) { args.procs.nn = 1; } } if (0 == args.procs.ppn) { char *end = NULL; const char* env = getenv("SLURM_NTASKS_PER_NODE"); if (NULL != env) { args.procs.ppn = strtol(env, &end, 10); } if (0 == args.procs.ppn) { args.procs.ppn = 1; } } if (NULL == args.testfn) { const char* testfn = "./testfn.nc"; args.testfn = (char*)malloc(sizeof(*args.testfn) * strlen(testfn) + 1); strcpy(args.testfn, testfn); } if (NULL == args.dgeom) { args.dgeom_size = NDIMS; args.dgeom = (size_t*)malloc(sizeof(*args.dgeom) * args.dgeom_size); args.dgeom[DT] = 100; args.dgeom[DX] = args.procs.nn * 100; args.dgeom[DY] = args.procs.ppn * 100; args.dgeom[DZ] = 10; } if (NDIMS != args.dgeom_size) { FATAL_ERR("Found %zu dimensions (expected %d).\n", args.dgeom_size, NDIMS); } // Automatic block layout if (NULL == args.bgeom) { args.bgeom_size = args.dgeom_size; args.bgeom = (size_t*)malloc(sizeof(*args.bgeom) * args.bgeom_size); args.bgeom[DT] = 1; args.bgeom[DX] = args.dgeom[DX] / args.procs.nn; args.bgeom[DY] = args.dgeom[DY] / args.procs.ppn; args.bgeom[DZ] = args.dgeom[DZ]; } if (cg != NULL && 0 == strcmp(cg, "auto")) { args.cgeom_size = args.bgeom_size; args.cgeom = (size_t*)malloc(sizeof(*args.cgeom) * args.cgeom_size); args.cgeom[DT] = 1; args.cgeom[DX] = args.bgeom[DX]; args.cgeom[DY] = args.bgeom[DY]; args.cgeom[DZ] = args.bgeom[DZ]; } else { parse_dims(cg, &args.cgeom, &args.cgeom_size); } if (NDIMS != args.bgeom_size) { FATAL_ERR("Found %zu dimensions (expected %d).\n", args.bgeom_size, NDIMS); } if (NULL != args.cgeom) { if (NDIMS != args.cgeom_size) { FATAL_ERR("Found %zu dimensions (expected %d).\n", args.cgeom_size, NDIMS); } } DEBUG_MESSAGE("dgeom (%zu:%zu:%zu:%zu)\n", args.dgeom[DT], args.dgeom[DX], args.dgeom[DY], args.dgeom[DZ]); DEBUG_MESSAGE("bgeom (%zu:%zu:%zu:%zu)\n", args.bgeom[DT], args.bgeom[DX], args.bgeom[DY], args.bgeom[DZ]); if (NULL != args.cgeom) { DEBUG_MESSAGE("cgeom (%zu:%zu:%zu:%zu)\n", args.cgeom[DT], args.cgeom[DX], args.cgeom[DY], args.cgeom[DZ]); } DEBUG_MESSAGE("(nn %zu, ppn %zu)\n", args.procs.nn, args.procs.ppn); DEBUG_MESSAGE("test filename %s\n", args.testfn); if (args.dgeom[DX] % args.procs.nn != 0) { FATAL_ERR("x must be a multiple of number of nodes.\n"); } if (args.dgeom[DY] % args.procs.ppn != 0) { FATAL_ERR("y must be a multiple of number of processes.\n"); } if (NULL != args.cgeom) { if (args.dgeom[DT] % args.cgeom[DT] != 0) { FATAL_ERR("Time range must be a multiple of time slice (range=%zu; slice=%zu)\n", args.dgeom[DT], args.cgeom[DT]); } } int nranks = 0; MPI_Comm_size(MPI_COMM_WORLD, &nranks); if (nranks != args.procs.nn * args.procs.ppn){ FATAL_ERR("Bad environment: np != nn * ppn; np(size of MPI_COMM_WORLD)=%d, nodes(nn)=%zu, ppn(procs per node)=%zu\n", nranks, args.procs.nn, args.procs.ppn); } if ((args.read_test == false) & (args.write_test == false) & (args.verify == false)) { args.write_test = true; } benchmark_t wbm; benchmark_init(&wbm); int header_printed = 0; benchmark_t rbm; benchmark_init(&rbm); if (args.write_test || args.verify) { benchmark_setup(&wbm, args.procs, NDIMS, args.dgeom, args.bgeom, args.cgeom, args.testfn, IO_MODE_WRITE, args.par_access, args.is_unlimited, args.fill_value); if(rank == 0){ print_header(& wbm); header_printed = 1; } } if (args.write_test) { benchmark_run(&wbm, NULL); report_t report; report_init(&report); report_setup(&report, &wbm); report_print(&report, args.report_type); report_destroy(&report); } if (args.read_test) { int ret; benchmark_setup(&rbm, args.procs, NDIMS, args.dgeom, args.bgeom, args.cgeom, args.testfn, IO_MODE_READ, args.par_access, args.is_unlimited, 0); if(rank == 0 && ! header_printed){ print_header(& rbm); header_printed = 1; } ret = benchmark_run(&rbm, args.verify ? wbm.block : NULL ); report_t report; report_init(&report); report_setup(&report, &rbm); report_print(&report, args.report_type); report_destroy(&report); }else if (args.verify) { int ret; benchmark_setup(& rbm, args.procs, NDIMS, args.dgeom, args.bgeom, args.cgeom, args.testfn, IO_MODE_READ, args.par_access, args.is_unlimited, 0); if(rank == 0 && ! header_printed){ print_header(& rbm); header_printed = 1; } ret = benchmark_run(& rbm, wbm.block); if (args.verify){ if (ret) { printf("TEST PASSED [%u]\n", wbm.rank); } else { printf("TEST FAILED [%u]\n", wbm.rank); } } } MPI_Finalize(); benchmark_destroy(&wbm); benchmark_destroy(&rbm); free(args.dgeom); free(args.bgeom); free(args.cgeom); free(args.testfn); return 0; }
int main(int argc, char** argv) { xm_context_t* ctx; FILE* out; uint32_t num_samples = 0; float buffer[buffer_size]; if(argc != 3) FATAL("Usage: %s <xm-file-input> <wav-file-out>\n", argv[0]); create_context_from_file(&ctx, rate, argv[1]); if(ctx == NULL) exit(1); xm_set_max_loop_count(ctx, 1); out = fopen(argv[2], "w"); if(out == NULL) FATAL_ERR("could not open output file for writing"); /* WAVE format info taken from * http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html */ /* Unlike AU, WAVE files cannot have an unknown length. This * is why we can't write directly to stdout (we need to rewind * because module length is hard to know. */ fputs("RIFF", out); puts_uint32_le(0, out); /* Chunk size. Will be filled later. */ fputs("WAVE", out); fputs("fmt ", out); /* Start format chunk */ puts_uint32_le(16, out); /* Format chunk size */ puts_uint16_le(3, out); /* IEEE float sample data */ puts_uint16_le(channels, out); /* Number of channels */ puts_uint32_le(rate, out); /* Frames/sec (sampling rate) */ puts_uint32_le(rate * channels * sizeof(float), out); /* nAvgBytesPerSec ? */ puts_uint16_le(channels * sizeof(float), out); /* nBlockAlign ? */ puts_uint16_le(8 * sizeof(float), out); /* wBitsPerSample ? */ fputs("data", out); /* Start data chunk */ puts_uint32_le(0, out); /* Data chunk size. Will be filled later. */ while(xm_get_loop_count(ctx) == 0) { xm_generate_samples(ctx, buffer, buffer_size / channels); num_samples += buffer_size; for(size_t k = 0; k < buffer_size; ++k) { union { float f; uint32_t i; } u; u.f = buffer[k]; puts_uint32_le(u.i, out); } } fseek(out, 4, SEEK_SET); puts_uint32_le(36 + num_samples * sizeof(float), out); fseek(out, 32, SEEK_SET); puts_uint32_le(num_samples * sizeof(float), out); fclose(out); xm_free_context(ctx); return 0; }