static ObjectType create_array(ContextType ctx) { return create_array(ctx, 0, nullptr); }
static HRESULT String_split(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r) { match_state_t match_result, *match_ptr = &match_result; DWORD length, i, match_len = 0; const WCHAR *ptr, *ptr2, *str, *match_str = NULL; unsigned limit = ~0u; jsdisp_t *array, *regexp = NULL; jsstr_t *jsstr, *match_jsstr, *tmp_str; HRESULT hres; TRACE("\n"); if(argc != 1 && argc != 2) { FIXME("unsupported argc %u\n", argc); return E_NOTIMPL; } hres = get_string_flat_val(ctx, jsthis, &jsstr, &str); if(FAILED(hres)) return hres; length = jsstr_length(jsstr); if(argc > 1 && !is_undefined(argv[1])) { hres = to_uint32(ctx, argv[1], &limit); if(FAILED(hres)) { jsstr_release(jsstr); return hres; } } if(is_object_instance(argv[0])) { regexp = iface_to_jsdisp(get_object(argv[0])); if(regexp) { if(!is_class(regexp, JSCLASS_REGEXP)) { jsdisp_release(regexp); regexp = NULL; } } } if(!regexp) { hres = to_flat_string(ctx, argv[0], &match_jsstr, &match_str); if(FAILED(hres)) { jsstr_release(jsstr); return hres; } match_len = jsstr_length(match_jsstr); if(!match_len) { jsstr_release(match_jsstr); match_str = NULL; } } hres = create_array(ctx, 0, &array); if(SUCCEEDED(hres)) { ptr = str; match_result.cp = str; for(i=0; i<limit; i++) { if(regexp) { hres = regexp_match_next(ctx, regexp, REM_NO_PARENS, jsstr, &match_ptr); if(hres != S_OK) break; ptr2 = match_result.cp - match_result.match_len; } else if(match_str) { ptr2 = strstrW(ptr, match_str); if(!ptr2) break; } else { if(!*ptr) break; ptr2 = ptr+1; } tmp_str = jsstr_alloc_len(ptr, ptr2-ptr); if(!tmp_str) { hres = E_OUTOFMEMORY; break; } hres = jsdisp_propput_idx(array, i, jsval_string(tmp_str)); jsstr_release(tmp_str); if(FAILED(hres)) break; if(regexp) ptr = match_result.cp; else if(match_str) ptr = ptr2 + match_len; else ptr++; } } if(SUCCEEDED(hres) && (match_str || regexp) && i<limit) { DWORD len = (str+length) - ptr; if(len || match_str) { tmp_str = jsstr_alloc_len(ptr, len); if(tmp_str) { hres = jsdisp_propput_idx(array, i, jsval_string(tmp_str)); jsstr_release(tmp_str); } else { hres = E_OUTOFMEMORY; } } } if(regexp) jsdisp_release(regexp); if(match_str) jsstr_release(match_jsstr); jsstr_release(jsstr); if(SUCCEEDED(hres) && r) *r = jsval_obj(array); else jsdisp_release(array); return hres; }
static ObjectType create_array(ContextType ctx, const std::vector<ValueType> &values) { return create_array(ctx, (uint32_t)values.size(), values.data()); }
extern "C" __declspec(dllexport) int i32_create_array(const MKL_INT length, int*& x) { return create_array(length, x); }
extern "C" __declspec(dllexport) int d_create_array(const MKL_INT length, double*& x) { return create_array(length, x); }
static HRESULT create_match_array(script_ctx_t *ctx, jsstr_t *input_str, const match_state_t *result, IDispatch **ret) { const WCHAR *input; jsdisp_t *array; jsstr_t *str; DWORD i; HRESULT hres = S_OK; static const WCHAR indexW[] = {'i','n','d','e','x',0}; static const WCHAR inputW[] = {'i','n','p','u','t',0}; static const WCHAR lastIndexW[] = {'l','a','s','t','I','n','d','e','x',0}; static const WCHAR zeroW[] = {'0',0}; input = jsstr_flatten(input_str); if(!input) return E_OUTOFMEMORY; hres = create_array(ctx, result->paren_count+1, &array); if(FAILED(hres)) return hres; for(i=0; i < result->paren_count; i++) { if(result->parens[i].index != -1) str = jsstr_substr(input_str, result->parens[i].index, result->parens[i].length); else str = jsstr_empty(); if(!str) { hres = E_OUTOFMEMORY; break; } hres = jsdisp_propput_idx(array, i+1, jsval_string(str)); jsstr_release(str); if(FAILED(hres)) break; } while(SUCCEEDED(hres)) { hres = jsdisp_propput_name(array, indexW, jsval_number(result->cp-input-result->match_len)); if(FAILED(hres)) break; hres = jsdisp_propput_name(array, lastIndexW, jsval_number(result->cp-input)); if(FAILED(hres)) break; hres = jsdisp_propput_name(array, inputW, jsval_string(jsstr_addref(input_str))); if(FAILED(hres)) break; str = jsstr_alloc_len(result->cp-result->match_len, result->match_len); if(!str) { hres = E_OUTOFMEMORY; break; } hres = jsdisp_propput_name(array, zeroW, jsval_string(str)); jsstr_release(str); break; } if(FAILED(hres)) { jsdisp_release(array); return hres; } *ret = to_disp(array); return S_OK; }
/* ECMA-262 3rd Edition 15.4.4.10 */ static HRESULT Array_slice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r) { jsdisp_t *arr, *jsthis; DOUBLE range; DWORD length, start, end, idx; HRESULT hres; TRACE("\n"); hres = get_length(ctx, vthis, &jsthis, &length); if(FAILED(hres)) return hres; if(argc) { hres = to_number(ctx, argv[0], &range); if(FAILED(hres)) return hres; range = floor(range); if(-range>length || isnan(range)) start = 0; else if(range < 0) start = range+length; else if(range <= length) start = range; else start = length; } else start = 0; if(argc > 1) { hres = to_number(ctx, argv[1], &range); if(FAILED(hres)) return hres; range = floor(range); if(-range>length) end = 0; else if(range < 0) end = range+length; else if(range <= length) end = range; else end = length; } else end = length; hres = create_array(ctx, (end>start)?end-start:0, &arr); if(FAILED(hres)) return hres; for(idx=start; idx<end; idx++) { jsval_t v; hres = jsdisp_get_idx(jsthis, idx, &v); if(hres == DISP_E_UNKNOWNNAME) continue; if(SUCCEEDED(hres)) { hres = jsdisp_propput_idx(arr, idx-start, v); jsval_release(v); } if(FAILED(hres)) { jsdisp_release(arr); return hres; } } if(r) *r = jsval_obj(arr); else jsdisp_release(arr); return S_OK; }
void test_perf_nb(int dry_run) { int i, j, loop, rc, bytes, elems[2] = {MAXPROC, MAXELEMS}; int stride, k=0, ntimes; double stime, t1, t2, t3, t4, t5, t6, t7, t8, t9; double *dsrc[MAXPROC], scale=1.0; armci_hdl_t hdl_get, hdl_put, hdl_acc; create_array((void**)ddst, sizeof(double),2, elems); create_array((void**)dsrc, sizeof(double),1, &elems[1]); if(!dry_run)if(me == 0) { printf("\n\t\t\tRemote 1-D Array Section\n"); printf("section get nbget wait put nbput "); printf(" wait acc nbacc wait\n"); printf("------- -------- -------- -------- -------- --------"); printf(" -------- -------- -------- --------\n"); fflush(stdout); } for(loop=1; loop<=MAXELEMS; loop*=2, k++) { elems[1] = loop; ntimes = (int)sqrt((double)(MAXELEMS/elems[1])); if(ntimes <1) ntimes=1; /* -------------------------- SETUP --------------------------- */ /*initializing non-blocking handles,time,src & dst buffers*/ ARMCI_INIT_HANDLE(&hdl_put); ARMCI_INIT_HANDLE(&hdl_get); ARMCI_INIT_HANDLE(&hdl_acc); t1 = t2 = t3 = t4 = t5 = t6 = t7 = t8 = t9 = 0.0; for(i=0; i<elems[1]; i++) dsrc[me][i]=i*1.001*(me+1); for(i=0; i<elems[0]*elems[1]; i++) ddst[me][i]=0.0; MP_BARRIER(); /* bytes transfered */ bytes = sizeof(double)*elems[1]; MP_BARRIER(); /* -------------------------- PUT/GET -------------------------- */ if(me == 0) { for(i=1; i<nproc; i++) { stime=MP_TIMER(); for(j=0; j<ntimes; j++) if((rc=ARMCI_Put(&dsrc[me][0], &ddst[i][me*elems[1]], bytes,i))) ARMCI_Error("armci_nbput failed\n",rc); t1 += MP_TIMER()-stime; } } MP_BARRIER(); ARMCI_AllFence(); MP_BARRIER(); if(VERIFY) verify_results(PUT, elems); for(i=0; i<elems[0]*elems[1]; i++) ddst[me][i]=0.0; MP_BARRIER(); if(me == 0) { for(i=1; i<nproc; i++) { stime=MP_TIMER(); for(j=0; j<ntimes; j++) if((rc=ARMCI_Get(&dsrc[i][0], &ddst[me][i*elems[1]], bytes,i))) ARMCI_Error("armci_nbget failed\n",rc); t4 += MP_TIMER()-stime; } } MP_BARRIER(); ARMCI_AllFence(); MP_BARRIER(); if(VERIFY) verify_results(GET, elems); for(i=0; i<elems[0]*elems[1]; i++) ddst[me][i]=0.0; MP_BARRIER(); /* ------------------------ nb PUT/GET ------------------------- */ if(me == 0) { for(i=1; i<nproc; i++) { for(j=0; j<ntimes; j++) { stime=MP_TIMER(); if((rc=ARMCI_NbPut(&dsrc[me][0], &ddst[i][me*elems[1]], bytes, i, &hdl_put))) ARMCI_Error("armci_nbput failed\n",rc); t2 += MP_TIMER()-stime; stime=MP_TIMER(); ARMCI_Wait(&hdl_put); t3 += MP_TIMER()-stime; } } } MP_BARRIER(); ARMCI_AllFence(); MP_BARRIER(); if(VERIFY) verify_results(PUT, elems); for(i=0; i<elems[0]*elems[1]; i++) ddst[me][i]=0.0; MP_BARRIER(); if(me == 0) { for(i=1; i<nproc; i++) { for(j=0; j<ntimes; j++) { stime=MP_TIMER(); if((rc=ARMCI_NbGet(&dsrc[i][0], &ddst[me][i*elems[1]], bytes, i, &hdl_get))) ARMCI_Error("armci_nbget failed\n",rc); t5 += MP_TIMER()-stime; stime=MP_TIMER(); ARMCI_Wait(&hdl_get); t6 += MP_TIMER()-stime; } } } MP_BARRIER(); ARMCI_AllFence(); MP_BARRIER(); if(VERIFY) verify_results(GET, elems); for(i=0; i<elems[0]*elems[1]; i++) ddst[me][i]=0.0; MP_BARRIER(); /* ------------------------ Accumulate ------------------------- */ for(i=0; i<elems[1]; i++) dsrc[me][i]=1.0; MP_BARRIER(); stride = elems[1]*sizeof(double); scale = 1.0; for(j=0; j<ntimes; j++) { stime=MP_TIMER(); if((rc=ARMCI_AccS(ARMCI_ACC_DBL, &scale, &dsrc[me][0], &stride, &ddst[0][0], &stride, &bytes, 0, 0))) ARMCI_Error("armci_acc failed\n",rc); t7 += MP_TIMER()-stime; MP_BARRIER(); ARMCI_AllFence(); MP_BARRIER(); if(VERIFY) verify_results(ACC, elems); for(i=0; i<elems[0]*elems[1]; i++) ddst[me][i]=0.0; MP_BARRIER(); } #if 1 /* See the note below why this part is disabled */ /* ---------------------- nb-Accumulate ------------------------ */ for(i=0; i<elems[1]; i++) dsrc[me][i]=1.0; MP_BARRIER(); stride = elems[1]*sizeof(double); scale = 1.0; for(j=0; j<ntimes; j++) { stime=MP_TIMER(); if((rc=ARMCI_NbAccS(ARMCI_ACC_DBL, &scale, &dsrc[me][0], &stride, &ddst[0][0], &stride, &bytes, 0, 0, &hdl_acc))) ARMCI_Error("armci_nbacc failed\n",rc); t8 += MP_TIMER()-stime; stime=MP_TIMER(); ARMCI_Wait(&hdl_acc); t9 += MP_TIMER()-stime; MP_BARRIER(); ARMCI_AllFence(); MP_BARRIER(); if(VERIFY) verify_results(ACC, elems); for(i=0; i<elems[0]*elems[1]; i++) ddst[me][i]=0.0; MP_BARRIER(); } #endif /* print timings */ if(!dry_run) if(me==0) printf("%d\t %.2e %.2e %.2e %.2e %.2e %.2e %.2e %.2e %.2e\n", bytes, t4/ntimes, t5/ntimes, t6/ntimes, t1/ntimes, t2/ntimes, t3/ntimes, t7/ntimes, t8/ntimes, t9/ntimes); } ARMCI_AllFence(); MP_BARRIER(); if(!dry_run)if(me==0){printf("O.K.\n"); fflush(stdout);} destroy_array((void **)ddst); destroy_array((void **)dsrc); }
/** * Tests the character array with a single element. */ void test_character_array_single_element() { // Character array. fputs("Character array:\n", stdout); void* ca = NULL_POINTER; int cas = 5; create_array((void*) &ca, (void*) &CHARACTER_ARRAY, (void*) &cas); int ca1i = 0; char ca1 = 'a'; int ca2i = 1; char ca2 = 'b'; int ca3i = 2; char ca3 = 'c'; int ca4i = 3; char ca4 = '\n'; int ca5i = 4; char ca5 = '\0'; set_array_element((void*) &ca, (void*) &CHARACTER_ARRAY, (void*) &ca1i, (void*) &ca1); set_array_element((void*) &ca, (void*) &CHARACTER_ARRAY, (void*) &ca2i, (void*) &ca2); set_array_element((void*) &ca, (void*) &CHARACTER_ARRAY, (void*) &ca3i, (void*) &ca3); set_array_element((void*) &ca, (void*) &CHARACTER_ARRAY, (void*) &ca4i, (void*) &ca4); set_array_element((void*) &ca, (void*) &CHARACTER_ARRAY, (void*) &ca5i, (void*) &ca5); // Print out array contents. fputs((char*) ca, stdout); int i = 0; char* catest = CHARACTER_NULL_POINTER; while (1) { if (i >= cas) { break; } catest = (char*) (ca + i); fprintf(stderr, "ca: %c\n", *catest); i++; } destroy_array((void*) &ca, (void*) &CHARACTER_ARRAY, (void*) &cas); // Integer array. fputs("Integer array:\n", stdout); void* ia = NULL_POINTER; int ias = 5 * INTEGER_PRIMITIVE_SIZE; create_array((void*) &ia, (void*) &INTEGER_ARRAY, (void*) &ias); int ia1i = 0 * INTEGER_PRIMITIVE_SIZE; int ia1 = 9; int ia2i = 1 * INTEGER_PRIMITIVE_SIZE; int ia2 = 8; int ia3i = 2 * INTEGER_PRIMITIVE_SIZE; int ia3 = 7; int ia4i = 3 * INTEGER_PRIMITIVE_SIZE; int ia4 = 6; int ia5i = 4 * INTEGER_PRIMITIVE_SIZE; int ia5 = 5; set_array_element((void*) &ia, (void*) &INTEGER_ARRAY, (void*) &ia1i, (void*) &ia1); set_array_element((void*) &ia, (void*) &INTEGER_ARRAY, (void*) &ia2i, (void*) &ia2); set_array_element((void*) &ia, (void*) &INTEGER_ARRAY, (void*) &ia3i, (void*) &ia3); set_array_element((void*) &ia, (void*) &INTEGER_ARRAY, (void*) &ia4i, (void*) &ia4); set_array_element((void*) &ia, (void*) &INTEGER_ARRAY, (void*) &ia5i, (void*) &ia5); // Print out array contents. int j = 0; int* iatest = INTEGER_NULL_POINTER; while (1) { if (j * INTEGER_PRIMITIVE_SIZE >= ias) { break; } iatest = (int*) (ia + j * INTEGER_PRIMITIVE_SIZE); fprintf(stderr, "ia: %d\n", *iatest); j++; } destroy_array((void*) &ia, (void*) &INTEGER_ARRAY, (void*) &ias); // // Caution! In any case consider the size of the type, for all array! // Example: index * INTEGER_PRIMITIVE_SIZE // }
ObjectPtr<Array> create_array_with_size(uint32_t sz) { ObjectPtr<Array> array = create_array(); array_reserve(array, sz); return array; }
int main() { const int n = 16 * 1024; const int m = 16 * 1024; float ** a; test_timer_t timer = timer_build(); { timer_start(timer); a = create_array(n, m); kernel_0(n, m, a, 3.5); free_array(a); timer_stop(timer); printf("#0 : %d\n", timer->delta); } { timer_start(timer); a = create_array(n, m); kernel_1(n, m, a, 3.5); free_array(a); timer_stop(timer); printf("#1 : %d\n", timer->delta); } { timer_start(timer); a = create_array(n, m); kernel_2(n, m, a, 3.5); free_array(a); timer_stop(timer); printf("#2 : %d\n", timer->delta); } { timer_start(timer); a = create_array(n, m); kernel_3(n, m, a, 3.5); free_array(a); timer_stop(timer); printf("#3 : %d\n", timer->delta); } return 0; }
int main() { const int n = 16; const int m = 16; const int p = 16; const int q = 16; float ** a; float ** b; float ** c; float ** d; { a = create_array(n, p); b = create_array(p, q); c = create_array(q, m); d = create_array(n, m); kernel_0(n, m, p, q, a, b, c, d); free_array(a); free_array(b); free_array(c); free_array(d); } { a = create_array(n, p); b = create_array(p, q); c = create_array(q, m); d = create_array(n, m); kernel_1(n, m, p, q, a, b, c, d); free_array(a); free_array(b); free_array(c); free_array(d); } { a = create_array(n, p); b = create_array(p, q); c = create_array(q, m); d = create_array(n, m); kernel_2(n, m, p, q, a, b, c, d); free_array(a); free_array(b); free_array(c); free_array(d); } { a = create_array(n, p); b = create_array(p, q); c = create_array(q, m); d = create_array(n, m); kernel_3(n, m, p, q, a, b, c, d); free_array(a); free_array(b); free_array(c); free_array(d); } { a = create_array(n, p); b = create_array(p, q); c = create_array(q, m); d = create_array(n, m); kernel_4(n, m, p, q, a, b, c, d); free_array(a); free_array(b); free_array(c); free_array(d); } return 0; }
/* ECMA-262 5.1 Edition 15.12.1.2 */ static HRESULT parse_json_value(json_parse_ctx_t *ctx, jsval_t *r) { HRESULT hres; switch(skip_spaces(ctx)) { /* JSONNullLiteral */ case 'n': if(!is_keyword(ctx, nullW)) break; *r = jsval_null(); return S_OK; /* JSONBooleanLiteral */ case 't': if(!is_keyword(ctx, trueW)) break; *r = jsval_bool(TRUE); return S_OK; case 'f': if(!is_keyword(ctx, falseW)) break; *r = jsval_bool(FALSE); return S_OK; /* JSONObject */ case '{': { WCHAR *prop_name; jsdisp_t *obj; jsval_t val; hres = create_object(ctx->ctx, NULL, &obj); if(FAILED(hres)) return hres; ctx->ptr++; if(skip_spaces(ctx) == '}') { ctx->ptr++; *r = jsval_obj(obj); return S_OK; } while(1) { if(*ctx->ptr != '"') break; hres = parse_json_string(ctx, &prop_name); if(FAILED(hres)) break; if(skip_spaces(ctx) != ':') { FIXME("missing ':'\n"); heap_free(prop_name); break; } ctx->ptr++; hres = parse_json_value(ctx, &val); if(SUCCEEDED(hres)) { hres = jsdisp_propput_name(obj, prop_name, val); jsval_release(val); } heap_free(prop_name); if(FAILED(hres)) break; if(skip_spaces(ctx) == '}') { ctx->ptr++; *r = jsval_obj(obj); return S_OK; } if(*ctx->ptr++ != ',') { FIXME("expected ','\n"); break; } skip_spaces(ctx); } jsdisp_release(obj); break; } /* JSONString */ case '"': { WCHAR *string; jsstr_t *str; hres = parse_json_string(ctx, &string); if(FAILED(hres)) return hres; /* FIXME: avoid reallocation */ str = jsstr_alloc(string); heap_free(string); if(!str) return E_OUTOFMEMORY; *r = jsval_string(str); return S_OK; } /* JSONArray */ case '[': { jsdisp_t *array; unsigned i = 0; jsval_t val; hres = create_array(ctx->ctx, 0, &array); if(FAILED(hres)) return hres; ctx->ptr++; if(skip_spaces(ctx) == ']') { ctx->ptr++; *r = jsval_obj(array); return S_OK; } while(1) { hres = parse_json_value(ctx, &val); if(FAILED(hres)) break; hres = jsdisp_propput_idx(array, i, val); jsval_release(val); if(FAILED(hres)) break; if(skip_spaces(ctx) == ']') { ctx->ptr++; *r = jsval_obj(array); return S_OK; } if(*ctx->ptr != ',') { FIXME("expected ','\n"); break; } ctx->ptr++; i++; } jsdisp_release(array); break; } /* JSONNumber */ default: { int sign = 1; double n; if(*ctx->ptr == '-') { sign = -1; ctx->ptr++; skip_spaces(ctx); } if(!isdigitW(*ctx->ptr)) break; if(*ctx->ptr == '0') { ctx->ptr++; n = 0; if(is_identifier_char(*ctx->ptr)) break; }else { hres = parse_decimal(&ctx->ptr, ctx->end, &n); if(FAILED(hres)) return hres; } *r = jsval_number(sign*n); return S_OK; } } FIXME("Syntax error at %s\n", debugstr_w(ctx->ptr)); return E_FAIL; }
inline void BasicArray<T>::create() { std::size_t size = 0; MemRef mem = create_array(size, get_alloc()); // Throws init_from_mem(mem); }
/** * Creates the string. * * @param p0 the transient model * @param p1 the transient model size */ void create_string(void* p0, void* p1) { //?? log_message((void*) &INFO_LOG_LEVEL, (void*) &CREATE_STRING_MESSAGE, (void*) &CREATE_STRING_MESSAGE_COUNT); create_array(p0, (void*) &CHARACTER_ARRAY, p1); }
int main(int argc, char* argv[]) { char q[512]; MYSQL_ROW row; MYSQL_RES* res; int err = init_network(); if (err) { return err; } for (int year = 1990; year <= 2011; year++) { std::cout << "Querying " << year << "\n"; snprintf(q, 512, "select count(value) from entries where year=%d and inserted>(select updated from visualizations where name='Flow Centrality' and year=%d)", year, year); if (mysql_query(mysql, q)) { std::cerr << mysql_error(mysql) << "\n"; return -2; } res = mysql_use_result(mysql); if((row = mysql_fetch_row(res)) == 0 || atoi(row[0]) == 0) { mysql_free_result(res); continue; } mysql_free_result(res); err = read_network(year); if (err) { return err; } std::cout << "Calculating " << year << "\n"; err = disconnect(); if (err) { return err; } Basetype* betweenness = create_array(0); Basetype* in_flow = create_array(0); Basetype* out_flow = create_array(0); for (int v = 0; v < network_size; v++) { for (int w = 0; w < network_size; w++) { in_flow[v] += flows[w][v]; out_flow[v] += flows[v][w]; } } // Algorithm according to "A space-efficient parallel algorithm for computing betweenness centrality in distributed memory", p. 2 int s; #pragma omp parallel default(none) shared(betweenness, flows, network_size, in_flow, std::cerr) { #pragma omp for schedule(guided) nowait for (s = 0; s < network_size; s++) { std::vector<int> S; std::queue<int> PQ; BasetypeInt* sigma; Basetype* delta; Basetype* dist; BasetypeInt** P; BasetypeInt* P_size; Basetype* pipe; sigma = create_array_int(0); sigma[s] = 1; delta = create_array(0); P = create_double_int_array(0); P_size = create_array_int(0); dist = create_array(-1); dist[s] = 0; pipe = create_array(0); pipe[s] = -1; PQ.push(s); while (!PQ.empty()) { int v = PQ.front(); PQ.pop(); for (std::vector<int>::iterator it = S.begin(); it != S.end(); it++) { if (*it == v) { S.erase(it); break; } } S.push_back(v); for (int w = 0; w < network_size; w++) { if (w != v && w != s && flows[v][w] > 0) { Basetype c_v_w = flows[v][w]; Basetype new_pipe; if (pipe[v] < 0) { new_pipe = c_v_w; } else { new_pipe = std::min(pipe[v], c_v_w); } if (pipe[w] < new_pipe || (pipe[w] == new_pipe && dist[w] > dist[v] + 1)) { // Better best path via v PQ.push(w); pipe[w] = new_pipe; dist[w] = dist[v] + 1; sigma[w] = 0; P_size[w] = 0; } if (pipe[w] == new_pipe && dist[w] == dist[v] + 1 && !in_array(v,P[w],P_size[w])) { // Some best path via v sigma[w] += sigma[v]; P[w][P_size[w]] = v; P_size[w]++; } } } } while (!S.empty()) { int w = S.back(); S.pop_back(); for (int v_index = 0; v_index < P_size[w]; v_index++) { int v = P[w][v_index]; delta[v] += ((1 + delta[w]) * (Basetype) sigma[v]) / (Basetype) sigma[w]; } if (w != s) { #pragma omp atomic betweenness[w] += delta[w]; } } delete[] delta; delete[] sigma; delete[] dist; delete[] P_size; free_double_int_array(P); delete[] pipe; } } err = connect(); if (err) { return err; } snprintf(q, 512, "delete from visualization_data where visualization in (select id from visualizations where name='Flow Centrality' and year=%d)", year); if (mysql_query(mysql, q)) { std::cerr << mysql_error(mysql) << "\n"; return -2; } snprintf(q, 512, "select id from visualizations where name='Flow Centrality' and year=%d", year); if (mysql_query(mysql, q)) { std::cerr << mysql_error(mysql) << "\n"; return -2; } res = mysql_use_result(mysql); row = mysql_fetch_row(res); int id = atoi(row[0]); mysql_free_result(res); std::stringstream query("insert into visualization_data (visualization, sector_from, region_from, value) values ", std::ios_base::app | std::ios_base::out); for (int js = 0; js < network_size; js++) { if (js > 0) { query << ","; } query << "(" << id << ",'" << sectors[get_sector(js)] << "','" << regions[get_region(js)] << "'," << betweenness[js] << ")"; } if (mysql_query(mysql, query.str().c_str())) { std::cerr << mysql_error(mysql) << "\n"; return -2; } snprintf(q, 512, "update visualizations set updated=now() where name='Flow Centrality' and year=%d", year); if (mysql_query(mysql, q)) { std::cerr << mysql_error(mysql) << "\n"; return -2; } delete[] betweenness; free_double_array(flows); } return 0; }
/** * Creates the vector. * * @param p0 the model * @param p1 the model size */ void create_vector(void* p0, const void* p1) { //?? log_message((void*) &INFO_LOG_LEVEL, (void*) &"Create vector."); create_array(p0, (void*) &INTEGER_ARRAY, (void*) &VECTOR_COUNT); }
void test_acc_type(const int datatype) { int i = 0; int datatype_size = 0; void * scale; void * a; void *b[MAXPROC]; int elems = ELEMS; int dim = 1; int count = 0; int strideA = 0; int strideB = 0; switch(datatype) { case ARMCI_ACC_INT: datatype_size = sizeof(int); scale = malloc(datatype_size); *((int *) scale) = 1; a = malloc(elems * datatype_size); create_array((void**)b, datatype_size, dim, &elems); for(i = 0; i < elems; i++) { ((int *) a)[i] = i + me; ((int *) b[me])[i] = 0; } break; case ARMCI_ACC_LNG: datatype_size = sizeof(long); scale = malloc(datatype_size); *((long *) scale) = 1; a = malloc(elems * datatype_size); create_array((void**)b, datatype_size, dim, &elems); for(i = 0; i < elems; i++) { ((long *) a)[i] = i + me; ((long *) b[me])[i] = 0; } break; case ARMCI_ACC_FLT: datatype_size = sizeof(float); scale = malloc(datatype_size); *((float *) scale) = 1.0; a = malloc(elems * datatype_size); create_array((void**)b, datatype_size, dim, &elems); for(i = 0; i < elems; i++) { ((float *) a)[i] = (float) i + me; ((float *) b[me])[i] = 0.0; } break; case ARMCI_ACC_DBL: datatype_size = sizeof(double); scale = malloc(datatype_size); *((double *) scale) = 1.0; a = malloc(elems * datatype_size); create_array((void**)b, datatype_size, dim, &elems); for(i = 0; i < elems; i++) { ((double *) a)[i] = (double) i + me; ((double *) b[me])[i] = 0.0; } break; case ARMCI_ACC_CPL: datatype_size = sizeof(cmpl_t); scale = malloc(datatype_size); ((cmpl_t *) scale)->real = 2.0; ((cmpl_t *) scale)->imag = 1.0; a = malloc(elems * datatype_size); create_array((void**)b, datatype_size, dim, &elems); for(i = 0; i < elems; i++) { ((cmpl_t *) a)[i].real = ((float) i + me); ((cmpl_t *) a)[i].imag = ((float) i + me); ((cmpl_t *) b[me])[i].real = 0.0; ((cmpl_t *) b[me])[i].imag = 0.0; } break; case ARMCI_ACC_DCP: datatype_size = sizeof(dcmpl_t); scale = malloc(datatype_size); ((dcmpl_t *) scale)->real = 2.0; ((dcmpl_t *) scale)->imag = 1.0; a = malloc(elems * datatype_size); create_array((void**)b, datatype_size, dim, &elems); for(i = 0; i < elems; i++) { ((dcmpl_t *) a)[i].real = ((double) i + me); ((dcmpl_t *) a)[i].imag = ((double) i + me); ((dcmpl_t *) b[me])[i].real = 0.0; ((dcmpl_t *) b[me])[i].imag = 0.0; } break; default: return; break; } count = elems * datatype_size; strideA = elems * datatype_size; strideB = elems * datatype_size; ARMCI_AllFence(); MP_BARRIER(); for(i = 0; i < nproc; i++) ARMCI_AccS(datatype, scale, a, &strideA, b[(me + i) % nproc], &strideB, &count, 0, (me + i) % nproc); ARMCI_AllFence(); MP_BARRIER(); switch(datatype) { case ARMCI_ACC_INT: for(i = 0; i < elems; i++) { int compare = (i * nproc) + nproc / 2 * (nproc - 1); if(((int *)b[me])[i] != compare) { printf("ERROR accumulate ARMCI_ACC_INT [%d] = %d != %d\n", i, ((int *)b[me])[i], compare); ARMCI_Error("test_acc_type failed\n",0); } } break; case ARMCI_ACC_LNG: for(i = 0; i < elems; i++) { long compare = (i * nproc) + nproc / 2 * (nproc - 1); if(((long *)b[me])[i] != compare) { printf("ERROR accumulate ARMCI_ACC_LNG [%d] = %d != %d\n", i, ((int *)b[me])[i], compare); ARMCI_Error("test_acc_type failed\n",0); } } break; case ARMCI_ACC_FLT: for(i = 0; i < elems; i++) { float compare = (float) ((i * nproc) + nproc / 2 * (nproc - 1)); if(((float *)b[me])[i] != compare) { printf("ERROR accumulate ARMCI_ACC_FLT [%d] = %f != %f\n", i, ((float *)b[me])[i], compare); ARMCI_Error("test_acc_type failed\n",0); } } break; case ARMCI_ACC_DBL: for(i = 0; i < elems; i++) { double compare = (double) ((i * nproc) + nproc / 2 * (nproc - 1)); if(((double *)b[me])[i] != (double) ((i * nproc) + nproc / 2 * (nproc - 1))) { printf("ERROR accumulate ARMCI_ACC_DBL [%d] = %f != %f \n", i, ((double *)b[me])[i], compare); ARMCI_Error("test_acc_type failed\n",0); } } break; case ARMCI_ACC_CPL: for(i = 0; i < elems; i++) { float compare = (float) ((i * nproc) + nproc / 2 * (nproc - 1)); if(((cmpl_t *)b[me])[i].real != compare && ((cmpl_t *)b[me])[i].imag != 3 * compare) { printf("ERROR accumulate ARMCI_ACC_CPL [%d] = %f + %fj != %f + %fj\n", i, ((cmpl_t *)b[me])[i].real, ((cmpl_t *)b[me])[i].imag, compare, 3 * compare); ARMCI_Error("test_acc_type failed\n",0); } } break; case ARMCI_ACC_DCP: for(i = 0; i < elems; i++) { double compare = (double) ((i * nproc) + nproc / 2 * (nproc - 1)); if(((dcmpl_t *)b[me])[i].real != compare && ((dcmpl_t *)b[me])[i].imag != 3 * compare) { printf("ERROR accumulate ARMCI_ACC_DCP [%d] = %f + %fj != %f + %fj\n", i, ((dcmpl_t *)b[me])[i].real, ((dcmpl_t *)b[me])[i].imag, compare, 3 * compare); ARMCI_Error("test_acc_type failed\n",0); } } break; default: break; } MP_BARRIER(); ARMCI_AllFence(); MP_BARRIER(); if(me==0){printf("O.K.\n\n"); fflush(stdout);} destroy_array((void**)b); free(a); free(scale); }
HRESULT regexp_string_match(script_ctx_t *ctx, jsdisp_t *re, jsstr_t *jsstr, jsval_t *r) { static const WCHAR indexW[] = {'i','n','d','e','x',0}; static const WCHAR inputW[] = {'i','n','p','u','t',0}; static const WCHAR lastIndexW[] = {'l','a','s','t','I','n','d','e','x',0}; RegExpInstance *regexp = (RegExpInstance*)re; match_result_t *match_result; unsigned match_cnt, i; const WCHAR *str; jsdisp_t *array; HRESULT hres; str = jsstr_flatten(jsstr); if(!str) return E_OUTOFMEMORY; if(!(regexp->jsregexp->flags & REG_GLOB)) { match_state_t *match; heap_pool_t *mark; mark = heap_pool_mark(&ctx->tmp_heap); match = alloc_match_state(regexp->jsregexp, &ctx->tmp_heap, str); if(!match) { heap_pool_clear(mark); return E_OUTOFMEMORY; } hres = regexp_match_next(ctx, ®exp->dispex, 0, jsstr, &match); if(FAILED(hres)) { heap_pool_clear(mark); return hres; } if(r) { if(hres == S_OK) { IDispatch *ret; hres = create_match_array(ctx, jsstr, match, &ret); if(SUCCEEDED(hres)) *r = jsval_disp(ret); }else { *r = jsval_null(); } } heap_pool_clear(mark); return S_OK; } hres = regexp_match(ctx, ®exp->dispex, jsstr, FALSE, &match_result, &match_cnt); if(FAILED(hres)) return hres; if(!match_cnt) { TRACE("no match\n"); if(r) *r = jsval_null(); return S_OK; } hres = create_array(ctx, match_cnt, &array); if(FAILED(hres)) return hres; for(i=0; i < match_cnt; i++) { jsstr_t *tmp_str; tmp_str = jsstr_substr(jsstr, match_result[i].index, match_result[i].length); if(!tmp_str) { hres = E_OUTOFMEMORY; break; } hres = jsdisp_propput_idx(array, i, jsval_string(tmp_str)); jsstr_release(tmp_str); if(FAILED(hres)) break; } while(SUCCEEDED(hres)) { hres = jsdisp_propput_name(array, indexW, jsval_number(match_result[match_cnt-1].index)); if(FAILED(hres)) break; hres = jsdisp_propput_name(array, lastIndexW, jsval_number(match_result[match_cnt-1].index + match_result[match_cnt-1].length)); if(FAILED(hres)) break; hres = jsdisp_propput_name(array, inputW, jsval_string(jsstr)); break; } heap_free(match_result); if(SUCCEEDED(hres) && r) *r = jsval_obj(array); else jsdisp_release(array); return hres; }
proc_t* create_init_process_structure(uintptr_t pml) { proc_t* process = malloc(sizeof(proc_t)); if (process == NULL) { error(ERROR_MINIMAL_MEMORY_FAILURE, 0, 0, &create_init_process_structure); } memset(process, 0, sizeof(proc_t)); proc_spinlock_lock(&__proclist_lock); process->proc_id = ++process_id_num; list_push_right(processes, process); proc_spinlock_unlock(&__proclist_lock); process->fds = create_array(); process->pprocess = true; if (process->fds == NULL) { error(ERROR_MINIMAL_MEMORY_FAILURE, 0, 0, &create_init_process_structure); } process->threads = create_array(); if (process->threads == NULL) { error(ERROR_MINIMAL_MEMORY_FAILURE, 0, 0, &create_init_process_structure); } process->pml4 = pml; process->mem_maps = NULL; process->proc_random = rg_create_random_generator(get_unix_time()); process->parent = NULL; process->priority = 0; process->process_list.data = process; process->futexes = create_uint64_table(); process->__ob_lock = 0; if (process->futexes == NULL) { error(ERROR_MINIMAL_MEMORY_FAILURE, 0, 0, &create_init_process_structure); } process->input_buffer = create_queue_static(__message_getter); if (process->input_buffer == NULL) { error(ERROR_MINIMAL_MEMORY_FAILURE, 0, 0, &create_init_process_structure); } process->pq_input_buffer = create_queue_static(__message_getter); if (process->pq_input_buffer == NULL) { error(ERROR_MINIMAL_MEMORY_FAILURE, 0, 0, &create_init_process_structure); } process->blocked_wait_messages = create_list_static(__message_getter); if (process->blocked_wait_messages == NULL) { error(ERROR_MINIMAL_MEMORY_FAILURE, 0, 0, &create_init_process_structure); } process->temp_processes = create_list_static(__process_get_function); if (process->blocked_wait_messages == NULL) { error(ERROR_MINIMAL_MEMORY_FAILURE, 0, 0, &create_init_process_structure); } thread_t* main_thread = malloc(sizeof(thread_t)); if (main_thread == NULL) { error(ERROR_MINIMAL_MEMORY_FAILURE, 0, 0, &create_init_process_structure); } memset(main_thread, 0, sizeof(thread_t)); main_thread->parent_process = process; main_thread->tId = __atomic_add_fetch(&thread_id_num, 1, __ATOMIC_SEQ_CST); main_thread->priority = 0; main_thread->futex_block = create_list_static(__blocked_getter); if (main_thread->futex_block == NULL) { error(ERROR_MINIMAL_MEMORY_FAILURE, 0, 0, &create_init_process_structure); } main_thread->blocked = false; main_thread->blocked_list.data = main_thread; main_thread->schedule_list.data = main_thread; main_thread->last_rdi = (ruint_t)(uintptr_t)process->argc; main_thread->last_rsi = (ruint_t)(uintptr_t)process->argv; main_thread->last_rdx = (ruint_t)(uintptr_t)process->environ; main_thread->continuation = malloc(sizeof(continuation_t)); if (main_thread->continuation == NULL) { error(ERROR_MINIMAL_MEMORY_FAILURE, 0, 0, &create_init_process_structure); } main_thread->continuation->present = false; if (array_push_data(process->threads, main_thread) == 0) { error(ERROR_MINIMAL_MEMORY_FAILURE, 0, 0, &create_init_process_structure); } return process; }
/* ECMA-262 3rd Edition 15.4.4.12 */ static HRESULT Array_splice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r) { DWORD length, start=0, delete_cnt=0, i, add_args = 0; jsdisp_t *ret_array = NULL, *jsthis; jsval_t val; double d; int n; HRESULT hres = S_OK; TRACE("\n"); hres = get_length(ctx, vthis, &jsthis, &length); if(FAILED(hres)) return hres; if(argc) { hres = to_integer(ctx, argv[0], &d); if(FAILED(hres)) return hres; if(is_int32(d)) { if((n = d) >= 0) start = min(n, length); else start = -n > length ? 0 : length + n; }else { start = d < 0.0 ? 0 : length; } } if(argc >= 2) { hres = to_integer(ctx, argv[1], &d); if(FAILED(hres)) return hres; if(is_int32(d)) { if((n = d) > 0) delete_cnt = min(n, length-start); }else if(d > 0.0) { delete_cnt = length-start; } add_args = argc-2; } if(r) { hres = create_array(ctx, 0, &ret_array); if(FAILED(hres)) return hres; for(i=0; SUCCEEDED(hres) && i < delete_cnt; i++) { hres = jsdisp_get_idx(jsthis, start+i, &val); if(hres == DISP_E_UNKNOWNNAME) { hres = S_OK; }else if(SUCCEEDED(hres)) { hres = jsdisp_propput_idx(ret_array, i, val); jsval_release(val); } } if(SUCCEEDED(hres)) hres = jsdisp_propput_name(ret_array, lengthW, jsval_number(delete_cnt)); } if(add_args < delete_cnt) { for(i = start; SUCCEEDED(hres) && i < length-delete_cnt; i++) { hres = jsdisp_get_idx(jsthis, i+delete_cnt, &val); if(hres == DISP_E_UNKNOWNNAME) { hres = jsdisp_delete_idx(jsthis, i+add_args); }else if(SUCCEEDED(hres)) { hres = jsdisp_propput_idx(jsthis, i+add_args, val); jsval_release(val); } } for(i=length; SUCCEEDED(hres) && i != length-delete_cnt+add_args; i--) hres = jsdisp_delete_idx(jsthis, i-1); }else if(add_args > delete_cnt) { for(i=length-delete_cnt; SUCCEEDED(hres) && i != start; i--) { hres = jsdisp_get_idx(jsthis, i+delete_cnt-1, &val); if(hres == DISP_E_UNKNOWNNAME) { hres = jsdisp_delete_idx(jsthis, i+add_args-1); }else if(SUCCEEDED(hres)) { hres = jsdisp_propput_idx(jsthis, i+add_args-1, val); jsval_release(val); } } } for(i=0; SUCCEEDED(hres) && i < add_args; i++) hres = jsdisp_propput_idx(jsthis, start+i, argv[i+2]); if(SUCCEEDED(hres)) hres = jsdisp_propput_name(jsthis, lengthW, jsval_number(length-delete_cnt+add_args)); if(FAILED(hres)) { if(ret_array) jsdisp_release(ret_array); return hres; } if(r) *r = jsval_obj(ret_array); return S_OK; }
int create_process_base(uint8_t* image_data, int argc, char** argv, char** envp, proc_t** cpt, uint8_t asked_priority, registers_t* r) { proc_spinlock_lock(&__thread_modifier); uint8_t cpp = get_current_cput()->ct->parent_process->priority; proc_spinlock_unlock(&__thread_modifier); if (cpp > asked_priority) { return EINVAL; } int envc = 0; char** envt = envp; while (*envt != NULL) { ++envc; ++envt; } int err; if ((err = cpy_array(argc, &argv)) != 0) return err; if ((err = cpy_array(envc, &envp)) != 0) { free_array(argc, argv); return err; } // envp and argv are now kernel structures proc_t* process = malloc(sizeof(proc_t)); if (process == NULL) { return ENOMEM_INTERNAL; } memset(process, 0, sizeof(proc_t)); process->__ob_lock = 0; process->process_list.data = process; process->pprocess = true; process->fds = create_array(); if (process->fds == NULL) { free(process); return ENOMEM_INTERNAL; } process->threads = create_array(); if (process->fds == NULL) { destroy_array(process->fds); free(process); return ENOMEM_INTERNAL; } process->mem_maps = NULL; process->proc_random = rg_create_random_generator(get_unix_time()); process->parent = NULL; process->priority = asked_priority; process->pml4 = create_pml4(); if (process->pml4 == 0) { destroy_array(process->fds); free(process); return ENOMEM_INTERNAL; } process->futexes = create_uint64_table(); if (process->futexes == NULL) { destroy_array(process->threads); destroy_array(process->fds); free(process); return ENOMEM_INTERNAL; } process->input_buffer = create_queue_static(__message_getter); if (process->input_buffer == NULL) { destroy_table(process->futexes); destroy_array(process->threads); destroy_array(process->fds); free(process); return ENOMEM_INTERNAL; } process->pq_input_buffer = create_queue_static(__message_getter); if (process->input_buffer == NULL) { free_queue(process->input_buffer); destroy_table(process->futexes); destroy_array(process->threads); destroy_array(process->fds); free(process); return ENOMEM_INTERNAL; } process->blocked_wait_messages = create_list_static(__message_getter); if (process->blocked_wait_messages == NULL) { free_queue(process->pq_input_buffer); free_queue(process->input_buffer); destroy_table(process->futexes); destroy_array(process->threads); destroy_array(process->fds); free(process); return ENOMEM_INTERNAL; } process->temp_processes = create_list_static(__process_get_function); if (process->blocked_wait_messages == NULL) { free_list(process->blocked_wait_messages); free_queue(process->pq_input_buffer); free_queue(process->input_buffer); destroy_table(process->futexes); destroy_array(process->threads); destroy_array(process->fds); free(process); return ENOMEM_INTERNAL; } thread_t* main_thread = malloc(sizeof(thread_t)); if (main_thread == NULL) { free_list(process->temp_processes); free_list(process->blocked_wait_messages); free_queue(process->pq_input_buffer); free_queue(process->input_buffer); destroy_table(process->futexes); destroy_array(process->threads); destroy_array(process->fds); free(process); // TODO: free process address page return ENOMEM_INTERNAL; } memset(main_thread, 0, sizeof(thread_t)); main_thread->parent_process = process; main_thread->priority = asked_priority; main_thread->blocked = false; main_thread->continuation = malloc(sizeof(continuation_t)); if (main_thread->continuation == NULL) { free(main_thread); free_list(process->temp_processes); free_list(process->blocked_wait_messages); free_queue(process->pq_input_buffer); free_queue(process->input_buffer); destroy_table(process->futexes); destroy_array(process->threads); destroy_array(process->fds); free(process); // TODO: free process address page return ENOMEM_INTERNAL; } main_thread->continuation->present = false; main_thread->futex_block = create_list_static(__blocked_getter); if (main_thread->futex_block == NULL) { free(main_thread->continuation); free(main_thread); free_list(process->temp_processes); free_list(process->blocked_wait_messages); free_queue(process->pq_input_buffer); free_queue(process->input_buffer); destroy_table(process->futexes); destroy_array(process->threads); destroy_array(process->fds); free(process); // TODO: free process address page return ENOMEM_INTERNAL; } array_push_data(process->threads, main_thread); err = load_elf_exec((uintptr_t)image_data, process); if (err == ELF_ERROR_ENOMEM) { err = ENOMEM_INTERNAL; } else if (err != 0) { err = EINVAL; } if (err != 0) { free_list(main_thread->futex_block); free(main_thread->continuation); free(main_thread); free_list(process->temp_processes); free_list(process->blocked_wait_messages); free_queue(process->pq_input_buffer); free_queue(process->input_buffer); destroy_table(process->futexes); destroy_array(process->threads); destroy_array(process->fds); free(process); // TODO: free process address page return err; } char** argvu = argv; char** envpu = envp; if ((err = cpy_array_user(argc, &argvu, process)) != 0) { free_list(main_thread->futex_block); free(main_thread->continuation); free(main_thread); free_list(process->temp_processes); free_list(process->blocked_wait_messages); free_queue(process->pq_input_buffer); free_queue(process->input_buffer); destroy_table(process->futexes); destroy_array(process->threads); destroy_array(process->fds); free(process); // TODO: free process address page return err; } if ((err = cpy_array_user(envc, &envpu, process)) != 0) { free_list(main_thread->futex_block); free(main_thread->continuation); free(main_thread); free_list(process->temp_processes); free_list(process->blocked_wait_messages); free_queue(process->pq_input_buffer); free_queue(process->input_buffer); destroy_table(process->futexes); destroy_array(process->threads); destroy_array(process->fds); free(process); // TODO: free process address page return err; } main_thread->local_info = proc_alloc_direct(process, sizeof(tli_t)); if (main_thread->local_info == NULL) { free_list(main_thread->futex_block); free(main_thread->continuation); free(main_thread); free_list(process->temp_processes); free_list(process->blocked_wait_messages); free_queue(process->pq_input_buffer); free_queue(process->input_buffer); destroy_table(process->futexes); destroy_array(process->threads); destroy_array(process->fds); free(process); // TODO: free process address page return ENOMEM_INTERNAL; } tli_t* li = different_page_mem(process->pml4, main_thread->local_info); li->self = main_thread->local_info; for (int i=0; i<MESSAGE_BUFFER_CNT; i++) { _message_t* m = &process->output_buffer[i]; m->owner = process; m->used = false; m->message = proc_alloc_direct(process, 0x200000); if (m->message == NULL) { free_list(main_thread->futex_block); free(main_thread->continuation); free(main_thread); free_list(process->temp_processes); free_list(process->blocked_wait_messages); free_queue(process->pq_input_buffer); free_queue(process->input_buffer); destroy_table(process->futexes); destroy_array(process->threads); destroy_array(process->fds); free(process); // TODO: free process address page return ENOMEM_INTERNAL; } } process->argc = argc; process->argv = argvu; process->environ = envpu; main_thread->last_r12 = 0; main_thread->last_r11 = 0; main_thread->last_r10 = 0; main_thread->last_r9 = 0; main_thread->last_r8 = 0; main_thread->last_rax = 0; main_thread->last_rbx = 0; main_thread->last_rcx = 0; main_thread->last_rdx = 0; main_thread->last_rdi = 0; main_thread->last_rsi = 0; main_thread->last_rbp = 0; main_thread->last_rflags = 0x200; // enable interrupts proc_spinlock_lock(&__proclist_lock); main_thread->tId = __atomic_add_fetch(&thread_id_num, 1, __ATOMIC_SEQ_CST); process->proc_id = ++process_id_num; list_push_right(processes, process); proc_spinlock_unlock(&__proclist_lock); li->t = main_thread->tId; main_thread->last_rdi = (ruint_t)(uintptr_t)process->argc; main_thread->last_rsi = (ruint_t)(uintptr_t)process->argv; main_thread->last_rdx = (ruint_t)(uintptr_t)process->environ; main_thread->blocked_list.data = main_thread; main_thread->schedule_list.data = main_thread; free_array(argc, argv); free_array(envc, envp); // TODO: add split option? main_thread->last_rax = process->proc_id; enschedule_best(main_thread); *cpt = process; return 0; }
extern "C" __declspec(dllexport) int ui16_create_array(const MKL_INT length, unsigned short*& x) { return create_array(length, x); }
int cp_stage_1(cp_stage1* data, ruint_t* process_num) { int error = 0; *process_num = 0; proc_t* cp = get_current_process(); temp_proc_t* tp = malloc(sizeof(temp_proc_t)); if (tp == NULL) { goto handle_mem_error; } proc_t* process = malloc(sizeof(proc_t)); if (process == NULL) { goto handle_mem_error; } memset(process, 0, sizeof(proc_t)); tp->cstate = CP1; tp->process = process; process->__ob_lock = 0; process->process_list.data = process; if (data->privilege && cp->pprocess) process->pprocess = true; else process->pprocess = false; process->fds = create_array(); if (process->fds == NULL) { goto handle_mem_error; } process->threads = create_array(); if (process->fds == NULL) { destroy_array(process->fds); goto handle_mem_error; } process->mem_maps = NULL; process->proc_random = rg_create_random_generator(get_unix_time()); process->parent = NULL; if (data->parent) process->parent = cp; if (data->priority < 0) { process->priority = cp->priority; } else if (data->priority > 4) { error = EINVAL; goto handle_mem_error; } else process->priority = data->priority; process->futexes = create_uint64_table(); if (process->futexes == NULL) { error = ENOMEM_INTERNAL; goto handle_mem_error; } process->input_buffer = create_queue_static(__message_getter); if (process->input_buffer == NULL) { error = ENOMEM_INTERNAL; goto handle_mem_error; } process->pq_input_buffer = create_queue_static(__message_getter); if (process->input_buffer == NULL) { error = ENOMEM_INTERNAL; goto handle_mem_error; } process->blocked_wait_messages = create_list_static(__message_getter); if (process->blocked_wait_messages == NULL) { error = ENOMEM_INTERNAL; goto handle_mem_error; } process->temp_processes = create_list_static(__process_get_function); if (process->blocked_wait_messages == NULL) { error = ENOMEM_INTERNAL; goto handle_mem_error; } proc_spinlock_lock(&__proclist_lock); process->proc_id = ++process_id_num; proc_spinlock_unlock(&__proclist_lock); proc_spinlock_lock(&__proclist_lock2); if (table_set(temp_processes, (void*)process->proc_id, tp)) { proc_spinlock_unlock(&__proclist_lock2); error = ENOMEM_INTERNAL; goto handle_mem_error; } list_push_right(cp->temp_processes, process); proc_spinlock_unlock(&__proclist_lock2); return 0; handle_mem_error: if (tp != NULL) free(tp); if (process != NULL) { if (process->fds != NULL) destroy_array(process->fds); if (process->threads != NULL) destroy_array(process->threads); if (process->futexes != NULL) destroy_table(process->futexes); if (process->input_buffer != NULL) free_queue(process->input_buffer); if (process->pq_input_buffer != NULL) free_queue(process->pq_input_buffer); if (process->blocked_wait_messages != NULL) free_list(process->blocked_wait_messages); if (process->temp_processes != NULL) free_list(process->temp_processes); free(process); } return error; }
void test_aggregate(int dryrun) { int i, j, rc, bytes, elems[2] = {MAXPROC, MAXELEMS}; double *ddst_put[MAXPROC]; double *ddst_get[MAXPROC]; double *dsrc[MAXPROC]; armci_hdl_t aggr_hdl_put[MAXPROC]; armci_hdl_t aggr_hdl_get[MAXPROC]; armci_hdl_t hdl_put[MAXELEMS]; armci_hdl_t hdl_get[MAXELEMS]; armci_giov_t darr; void *src_ptr[MAX_REQUESTS], *dst_ptr[MAX_REQUESTS]; int start = 0, end = 0; double start_time; create_array(ddst_put, 2, elems); create_array(ddst_get, 2, elems); create_array(dsrc, 1, &elems[1]); for (i = 0; i < elems[1]; i++) { dsrc[me][i] = i * 1.001 * (me + 1); } for (i = 0; i < elems[0]*elems[1]; i++) { ddst_put[me][i] = 0.0; ddst_get[me][i] = 0.0; } ARMCI_Barrier(); /* only proc 0 does the work */ if (me == 0) { if (!dryrun) { printf("Transferring %d doubles (Not an array of %d doubles)\n", MAXELEMS, MAXELEMS); } /* initializing non-blocking handles */ for (i = 0; i < elems[1]; i++) { ARMCI_INIT_HANDLE(&hdl_put[i]); } for (i = 0; i < elems[1]; i++) { ARMCI_INIT_HANDLE(&hdl_get[i]); } /* aggregate handles */ for (i = 0; i < nproc; i++) { ARMCI_INIT_HANDLE(&aggr_hdl_put[i]); } for (i = 0; i < nproc; i++) { ARMCI_INIT_HANDLE(&aggr_hdl_get[i]); } for (i = 0; i < nproc; i++) { ARMCI_SET_AGGREGATE_HANDLE(&aggr_hdl_put[i]); } for (i = 0; i < nproc; i++) { ARMCI_SET_AGGREGATE_HANDLE(&aggr_hdl_get[i]); } bytes = sizeof(double); /* **************** PUT **************** */ /* register put */ start_time = armci_timer(); start = 0; end = elems[1]; for (i = 1; i < nproc; i++) { for (j = start; j < end; j++) { ARMCI_NbPutValueDouble(dsrc[me][j], &ddst_put[i][me*elems[1] + j], i, &hdl_put[j]); } for (j = start; j < end; j++) { ARMCI_Wait(&hdl_put[j]); } } if (!dryrun) { printf("%d: Value Put time = %.2es\n", me, armci_timer() - start_time); } /* vector put */ start_time = armci_timer(); for (i = 1; i < nproc; i++) { for (j = start; j < end; j++) { src_ptr[j] = (void *)&dsrc[me][j]; dst_ptr[j] = (void *)&ddst_put[i][me*elems[1] + j]; } darr.src_ptr_array = src_ptr; darr.dst_ptr_array = dst_ptr; darr.bytes = sizeof(double); darr.ptr_array_len = elems[1]; if ((rc = ARMCI_NbPutV(&darr, 1, i, &hdl_put[i]))) { ARMCI_Error("armci_nbputv failed\n", rc); } } for (i = 1; i < nproc; i++) { ARMCI_Wait(&hdl_put[i]); } if (!dryrun) { printf("%d: Vector Put time = %.2es\n", me, armci_timer() - start_time); } /* regular put */ start_time = armci_timer(); for (i = 1; i < nproc; i++) { for (j = start; j < end; j++) { if ((rc = ARMCI_NbPut(&dsrc[me][j], &ddst_put[i][me*elems[1] + j], bytes, i, &hdl_put[j]))) { ARMCI_Error("armci_nbput failed\n", rc); } } for (j = start; j < end; j++) { ARMCI_Wait(&hdl_put[j]); } } if (!dryrun) { printf("%d: Regular Put time = %.2es\n", me, armci_timer() - start_time); } /* aggregate put */ start_time = armci_timer(); for (i = 1; i < nproc; i++) { for (j = start; j < end; j++) { if ((rc = ARMCI_NbPut(&dsrc[me][j], &ddst_put[i][me*elems[1] + j], bytes, i, &aggr_hdl_put[i]))) { ARMCI_Error("armci_nbput failed\n", rc); } } } for (i = 1; i < nproc; i++) { ARMCI_Wait(&aggr_hdl_put[i]); } if (!dryrun) { printf("%d: Aggregate Put time = %.2es\n\n", me, armci_timer() - start_time); } /* **************** GET **************** */ /* vector get */ start_time = armci_timer(); for (i = 1; i < nproc; i++) { for (j = start; j < end; j++) { src_ptr[j] = (void *)&dsrc[i][j]; dst_ptr[j] = (void *)&ddst_get[me][i*elems[1] + j]; } darr.src_ptr_array = src_ptr; darr.dst_ptr_array = dst_ptr; darr.bytes = sizeof(double); darr.ptr_array_len = elems[1]; if ((rc = ARMCI_NbGetV(&darr, 1, i, &hdl_get[i]))) { ARMCI_Error("armci_nbgetv failed\n", rc); } ARMCI_Wait(&hdl_get[i]); } if (!dryrun) { printf("%d: Vector Get time = %.2es\n", me, armci_timer() - start_time); } /* regular get */ start_time = armci_timer(); for (i = 1; i < nproc; i++) { for (j = start; j < end; j++) { if ((rc = ARMCI_NbGet(&dsrc[i][j], &ddst_get[me][i*elems[1] + j], bytes, i, &hdl_get[j]))) { ARMCI_Error("armci_nbget failed\n", rc); } } for (j = start; j < end; j++) { ARMCI_Wait(&hdl_get[j]); } } if (!dryrun) { printf("%d: Regular Get time = %.2es\n", me, armci_timer() - start_time); } /* aggregate get */ start_time = armci_timer(); for (i = 1; i < nproc; i++) { for (j = start; j < end; j++) { ARMCI_NbGet(&dsrc[i][j], &ddst_get[me][i*elems[1] + j], bytes, i, &aggr_hdl_get[i]); } } for (i = 1; i < nproc; i++) { ARMCI_Wait(&aggr_hdl_get[i]); } if (!dryrun) { printf("%d: Aggregate Get time = %.2es\n", me, armci_timer() - start_time); } } ARMCI_Barrier(); ARMCI_AllFence(); ARMCI_Barrier(); /* Verify */ if (!(me == 0)) for (j = 0; j < elems[1]; j++) { if (ARMCI_ABS(ddst_put[me][j] - j * 1.001) > 0.1) { ARMCI_Error("aggregate put failed...1", 0); } } ARMCI_Barrier(); if (!dryrun)if (me == 0) { printf("\n aggregate put ..O.K.\n"); } fflush(stdout); if (me == 0) { for (i = 1; i < nproc; i++) { for (j = 0; j < elems[1]; j++) { if (ARMCI_ABS(ddst_get[me][i*elems[1] + j] - j * 1.001 *(i + 1)) > 0.1) { ARMCI_Error("aggregate get failed...1", 0); } } } } ARMCI_Barrier(); if (!dryrun)if (me == 0) { printf(" aggregate get ..O.K.\n"); } fflush(stdout); ARMCI_AllFence(); ARMCI_Barrier(); if (!dryrun)if (me == 0) { printf("O.K.\n"); fflush(stdout); } destroy_array(ddst_put); destroy_array(ddst_get); destroy_array(dsrc); }
/********************************************************************** * Function: main * Description: Main function for spice level Register File simulator. *********************************************************************/ int main(int argc, char *argv[]) { int i; char exe_str[200] = "hspice simulate_2r1w.sp>! simulate_2r1w.lis"; // exe_str is the string to be used in the system-calls. char cat_str[200]; // To display the output in simulate_mRmW.txt on terminal. int j; if(argc != (MAX_COMMAND_ARGS+1)) { fprintf(stderr,"\nERROR: Incorrect input values\n"); fprintf(stderr,"\nUsage:\n"); fprintf(stderr,"\t<D> - Content Addressable Memory (CAM) Depth (in power of 2)\n"); fprintf(stderr,"\t<W> - Width of each Word in CAM (in bits)\n"); fprintf(stderr,"\t<Rp> - Total Broadcast Ports in CAM\n"); fprintf(stderr,"\t<Wp> - Total Write Ports in CAM\n"); fprintf(stderr,"\t<T> - Temparature (in Celsius)\n"); fprintf(stderr,"\t<PATH> - Output file name with path\n"); exit(0); } //Read the command line arguments into variables D = atoi(argv[1]); W = atoi(argv[2]); Rp = atoi(argv[3]); Wp = atoi(argv[4]); temperature = atoi(argv[5]); T = 45 ; OP_PATH = argv[6]; // Print the CAM configuration on the console fprintf(stdout,"\n************* CAM Parameters *************\n"); fprintf(stdout,"\tCAM Depth (in the power of 2): %d\n",D); fprintf(stdout,"\tWidth of each Word in CAM (in bits): %d\n",W); fprintf(stdout,"\tTotal Broadcast Ports in CAM: %d\n",Rp); fprintf(stdout,"\tTotal Write Ports in CAM: %d\n",Wp); fprintf(stdout,"\tTemperature: %d\n",temperature); fprintf(stdout,"\tProcess Technology: %d\n\n\n",T); // Generate the name of top level spice simulation file strcat(strcat(strcat(strcpy(suffix,argv[3]),"r"),argv[4]),"w"); strcat(strcat(strcat(strcat(simulation_file,argv[3]),"r"),argv[4]),"w.sp"); // To compensate for the set-up time for the address-line to the input of // dynamic row-decoder before the clock-edge. if(D>=128) clk_setup = 150 + Wp*15; else if(D>=64) clk_setup = 100 + Wp*15; else clk_setup = 50 + Wp * 15; fprintf(stdout,"\nTop Level Simulation File Name: %s\n", simulation_file); // start with the instance # as 1 instance_no = 1; // To create critical simulation netlist in instance.sp create_array(D,W,Rp,Wp); if((SIM_OUT = fopen(simulation_file,"w")) == NULL) { fprintf(stderr,"\nERROR: Opening file %s:\n", simulation_file); exit(0); } // To create top-level simulation file for critical-path simulation print_file(); sprintf(exe_str,"hspice simulate_%dr%dw.sp > simulate_%dr%dw.lis",Rp,Wp,Rp,Wp); sprintf(cat_str,"cat simulate_%dr%dw.txt",Rp,Wp); i= system(exe_str); if(i != 0) printf("\nSIMULATION FAILED.... :-( \n"); result(); system(cat_str); // If simulation files are need to be removed then // uncomment following 2 linse //sprintf(cat_str,"rm -rf simulate_*",Rp,Wp); //system(cat_str); return 0; }