int main(int argc, char *argv[]) { int error = 0; Context ctx; if (argc < 4) { fprintf(stderr, "Correct usage %s <config_file> <data_file> <engine>\n", argv[0]); return -1; } if (!_read_config(&ctx, argv[1])) return -1; ctx.f = fopen(argv[2], "r"); if (!ctx.f) { fprintf(stderr, "Failed to open %s\n", argv[1]); return -1; } ctx.sml_engine = atoi(argv[3]); ctx.sml = _sml_new(ctx.sml_engine); ctx.reads = ctx.rights = ctx.predictions = 0; if (!ctx.sml || !_initialize_sml(&ctx)) { fprintf(stderr, "Failed to initialize sml\n"); error = -1; goto end; } while (_read_data(&ctx)) { _do_prediction(&ctx); ctx.first_train = true; if ((error = sml_process(ctx.sml))) { fprintf(stderr, "sml_process error number %d\n", error); break; } ctx.first_train = false; if ((error = sml_process(ctx.sml))) { fprintf(stderr, "sml_process error number %d\n", error); break; } } sml_print_debug(ctx.sml, false); printf("Right guesses: %d of %d (%d games) \n", ctx.rights, ctx.predictions, ctx.reads); printf("Right predictions percentage:%f%%\n", ctx.rights * 100.0 / ctx.reads); printf("Total right predictions percentage:%f%%\n", ctx.rights * 100.0 / ctx.predictions); sml_free(ctx.sml); _free_players(ctx.players, ctx.num_players); end: fclose(ctx.f); return error; }
int main(int argc, char **argv[]) { /* <reference> */ float inSubMat[M][M], outSubMat[M][M], LU[M][M], L[M][M], U[M][M]; int subdist, rowdist, coldist; int i, j, dist, k1, k2, p1, p2, q1, q2, q3; /* </reference> */ double t0, t1; t0 = wall_clock(); for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { if (i == j) { outMat[i][j] = N; } else { outMat[i][j] = 1; } } } /* <master id="234567"> */ _distributor = _open_space("distributor", 0, "234567"); _constructor = _open_space("constructor", 0, "234567"); i = 0; while (i < N) { j = i + M - 1; dist = M; if (j > N-1) { j = N-1; dist = N - i; } /* LU factors for submatrix */ for (k1 = 0; k1 < dist; k1++) { for (k2 = 0; k2 < dist; k2++) { inSubMat[k1][k2] = outMat[i+k1][i+k2]; } } LUFactor(inSubMat, outSubMat, dist); /* update */ for (k1 = 0; k1 < dist; k1++) { for (k2 = 0; k2 < dist; k2++) { outMat[i+k1][i+k2] = outSubMat[k1][k2]; LU[k1][k2] = outSubMat[k1][k2]; } } /* Solve triangles, LZ and WU */ for (k1 = j+1; k1 < N; k1 = k1+M) { k2 = k1 + M - 1; subdist = M; if (k2 > N-1) { k2 = N - 1; subdist = N - k1; } /* Solve LZ */ for (p1 = i; p1 < i+M; p1++) { for (p2 = k1; p2 <= k2; p2++) { inSubMat[p1-i][p2-k1] = outMat[p1][p2]; } } TriangleSolver(LU, inSubMat, outSubMat, subdist, 1); /* update */ for (p1 = i; p1 < i+M; p1++) { for (p2 = k1; p2 <= k2; p2++) { outMat[p1][p2] = outSubMat[p1-i][p2-k1]; } } /* Solve WU */ for (p1 = i; p1 < i+M; p1++) { for (p2 = k1; p2 <= k2; p2++) { inSubMat[p2-k1][p1-i] = outMat[p2][p1]; } } TriangleSolver(LU, inSubMat, outSubMat, subdist, 2); /* update */ for (p1 = i; p1 < i+M; p1++) { for (p2 = k1; p2 <= k2; p2++) { outMat[p2][p1] = outSubMat[p2-k1][p1-i]; } } } _cleanup_space(_distributor, "234567"); _cleanup_space(_constructor, "234567"); /* <token action="SET" idxset="(k1)"/> */ sprintf(_tp_name, "token#%s", "234567"); sprintf(_tp_token, "=(k1:%d~%d,%d:#%d)", j+1, N, 1, M); _tp_size = sizeof(_tp_token); _tokens = _set_token(_distributor, _tp_name, (char *)_tp_token, _tp_size); if (_tokens < 0) exit(-1); /* <send var="i" type="int"/> */ sprintf(_tp_name, "int:i#%s", "234567"); _tp_size = sizeof(int); _tp_i_234567 = &i; _status = _send_data(_distributor, _tp_name, (char *)_tp_i_234567, _tp_size); if (_status < 0) exit(-1); /* <send var="j" type="int"/> */ sprintf(_tp_name, "int:j#%s", "234567"); _tp_size = sizeof(int); _tp_j_234567 = &j; _status = _send_data(_distributor, _tp_name, (char *)_tp_j_234567, _tp_size); if (_status < 0) exit(-1); /* <send var="outMat" type="float[N(i~N)][N(i~N)]"/> */ sprintf(_tp_name, "float(%d)(%d):outMat#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "234567", (i), (N), 1, (i), (N), 1, sizeof(float)); _tp_size = (((N) - (i)) * ((N) - (i))) * sizeof(float); _tp_outMat_234567 = (float *)malloc(_tp_size); for (_x0_234567 = (i), _y0_234567 =0; _x0_234567 < (N); _x0_234567 +=1, _y0_234567 ++) { for (_x1_234567 = (i), _y1_234567 =0; _x1_234567 < (N); _x1_234567 +=1, _y1_234567 ++) { _tp_outMat_234567[_y0_234567 * ((N) - (i)) + _y1_234567] = outMat[_x0_234567][_x1_234567]; } } _status = _send_data(_distributor, _tp_name, (char *)_tp_outMat_234567, _tp_size); if (_status < 0) exit(-1); free(_tp_outMat_234567); /* <read var="outMat" type="float[N(j+1~N)][N(j+1~N)]"/> */ sprintf(_tp_name, "float(%d)(%d):outMat#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "234567", (j+1), (N), 1, (j+1), (N), 1, sizeof(float)); _tp_size = (((N) - (j+1)) * ((N) - (j+1))) * sizeof(float); _tp_outMat_234567 = (float *)malloc(_tp_size); _tp_size = _read_data(_constructor, _tp_name, (char *)_tp_outMat_234567, _tp_size); if (_tp_size < 0) exit(-1); for (_x0_234567 = (j+1), _y0_234567 =0; _x0_234567 < (N); _x0_234567 +=1, _y0_234567 ++) { for (_x1_234567 = (j+1), _y1_234567 =0; _x1_234567 < (N); _x1_234567 +=1, _y1_234567 ++) { outMat[_x0_234567][_x1_234567] = _tp_outMat_234567[_y0_234567 * ((N) - (j+1)) + _y1_234567]; } } free(_tp_outMat_234567); i = i + M; } _close_space(_constructor, "234567", 1); _close_space(_distributor, "234567", 1); /* </master> */ /* for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { printf("%6.3f ", outMat[i][j]); } printf("\n"); } */ t1 = wall_clock() - t0; if (t1>0) printf(" (%f) MFLOPS.\n", (float) 2*N*N*N/3/t1); else printf(" MFLOPS: Not measured.\n"); printf("elapse time = %10.6f\n", t1/1000000); return 0; }
main(int argc, char **argv[]) { /* <reference id="123456"> */ int scalar = 0; double A[N][N], B[N][N], C[N][N]; int i, j, k; /* </reference> */ for (i = 0; i < N ; i++) { for (j = 0; j < N; j++) { A[i][j] = (double) i * j ; B[i][j] = (double) i * j ; C[i][j] = 0; } } /* <master id="123456"> */ _distributor = _open_space("distributor", 0, "123456"); _constructor = _open_space("constructor", 0, "123456"); _cleanup_space(_distributor, "123456"); _cleanup_space(_constructor, "123456"); /* <send var="scalar" type="int" opt="ONCE|XCHG"/> */ sprintf(_tp_name, "int:scalar#%s", "123456"); _tp_size = sizeof(int); _tp_scalar_123456 = &scalar; _status = _send_data(_constructor, _tp_name, (char *)_tp_scalar_123456, _tp_size); if (_status < 0) exit(-1); /* <send var="scalar" type="int" opt="ONCE"/> */ sprintf(_tp_name, "int:scalar#%s", "123456"); _tp_size = sizeof(int); _tp_scalar_123456 = &scalar; _status = _send_data(_distributor, _tp_name, (char *)_tp_scalar_123456, _tp_size); if (_status < 0) exit(-1); /* <send var="A" type="double[N ][N ]" opt="ONCE|XCHG"/> */ sprintf(_tp_name, "double(%d)(%d):A#%s", (N), (N), "123456"); _tp_size = ((N) * (N)) * sizeof(double); _tp_A_123456 = (double *)malloc(_tp_size); for (_x0_123456 = 0; _x0_123456 < (N); _x0_123456 +=1) { for (_x1_123456 = 0; _x1_123456 < (N); _x1_123456 +=1) { _tp_A_123456[_x0_123456 * (N) + _x1_123456] = A[_x0_123456][_x1_123456]; } } _status = _send_data(_constructor, _tp_name, (char *)_tp_A_123456, _tp_size); if (_status < 0) exit(-1); free(_tp_A_123456); /* <send var="A" type="double[N(i:i-1) ][N ]" opt="ONCE|XCHG"/> */ sprintf(_tp_name, "double(%d)(%d):A#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "123456", (_i_start-1), (_i_stop-1), _i_step, 0, (N), 1, sizeof(double)); _tp_size = ((((_i_stop-1) - (_i_start-1) - 1) / _i_step + 1) * (N)) * sizeof(double); _tp_A_123456 = (double *)malloc(_tp_size); for (_x0_123456 = (_i_start-1), _y0_123456 =0; _x0_123456 < (_i_stop-1); _x0_123456 +=_i_step, _y0_123456 ++) { for (_x1_123456 = 0; _x1_123456 < (N); _x1_123456 +=1) { _tp_A_123456[_y0_123456 * (N) + _x1_123456] = A[_x0_123456][_x1_123456]; } } _status = _send_data(_constructor, _tp_name, (char *)_tp_A_123456, _tp_size); if (_status < 0) exit(-1); free(_tp_A_123456); /* <send var="A" type="double[N ][N(k) ]" opt="ONCE"/> */ sprintf(_tp_name, "double(%d)(%d):A#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "123456", 0, (N), 1, _k_start, _k_stop, _k_step, sizeof(double)); _tp_size = ((N) * ((_k_stop - _k_start - 1) / _k_step + 1)) * sizeof(double); _tp_A_123456 = (double *)malloc(_tp_size); for (_x0_123456 = 0; _x0_123456 < (N); _x0_123456 +=1) { for (_x1_123456 = _k_start, _y1_123456 =0; _x1_123456 < _k_stop; _x1_123456 +=_k_step, _y1_123456 ++) { _tp_A_123456[_x0_123456 * ((_k_stop - _k_start - 1) / _k_step + 1) + _y1_123456] = A[_x0_123456][_x1_123456]; } } _status = _send_data(_distributor, _tp_name, (char *)_tp_A_123456, _tp_size); if (_status < 0) exit(-1); free(_tp_A_123456); /* <send var="A" type="double[N(i) ][N(k:$H-1)]" opt="ONCE"/> */ sprintf(_tp_name, "double(%d)(%d):A#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "123456", _i_start, _i_stop, _i_step, _k_stop, (_k_stop-1), _k_step, sizeof(double)); _tp_size = (((_i_stop - _i_start - 1) / _i_step + 1) * (((_k_stop-1) - _k_stop - 1) / _k_step + 1)) * sizeof(double); _tp_A_123456 = (double *)malloc(_tp_size); for (_x0_123456 = _i_start, _y0_123456 =0; _x0_123456 < _i_stop; _x0_123456 +=_i_step, _y0_123456 ++) { for (_x1_123456 = _k_stop, _y1_123456 =0; _x1_123456 < (_k_stop-1); _x1_123456 +=_k_step, _y1_123456 ++) { _tp_A_123456[_y0_123456 * (((_k_stop-1) - _k_stop - 1) / _k_step + 1) + _y1_123456] = A[_x0_123456][_x1_123456]; } } _status = _send_data(_distributor, _tp_name, (char *)_tp_A_123456, _tp_size); if (_status < 0) exit(-1); free(_tp_A_123456); /* <token action="SET" idxset="(i)(k)"/> */ sprintf(_tp_name, "token#%s", "123456"); sprintf(_tp_token, "=(i:%d~%d,%d:#%d)(k:%d~%d,%d:^%d)", 0, N, 1, 100, 0, N, 1, 20); _tp_size = sizeof(_tp_token); _tokens = _set_token(_distributor, _tp_name, (char *)_tp_token, _tp_size); if (_tokens < 0) exit(-1); /* <send var="scalar" type="int" opt="XCHG"/> */ sprintf(_tp_name, "int:scalar#%s", "123456"); _tp_size = sizeof(int); _tp_scalar_123456 = &scalar; _status = _send_data(_constructor, _tp_name, (char *)_tp_scalar_123456, _tp_size); if (_status < 0) exit(-1); /* <send var="scalar" type="int"/> */ sprintf(_tp_name, "int:scalar#%s", "123456"); _tp_size = sizeof(int); _tp_scalar_123456 = &scalar; _status = _send_data(_distributor, _tp_name, (char *)_tp_scalar_123456, _tp_size); if (_status < 0) exit(-1); /* <send var="B" type="double[N ][N ]"/> */ sprintf(_tp_name, "double(%d)(%d):B#%s", (N), (N), "123456"); _tp_size = ((N) * (N)) * sizeof(double); _tp_B_123456 = (double *)malloc(_tp_size); for (_x0_123456 = 0; _x0_123456 < (N); _x0_123456 +=1) { for (_x1_123456 = 0; _x1_123456 < (N); _x1_123456 +=1) { _tp_B_123456[_x0_123456 * (N) + _x1_123456] = B[_x0_123456][_x1_123456]; } } _status = _send_data(_distributor, _tp_name, (char *)_tp_B_123456, _tp_size); if (_status < 0) exit(-1); free(_tp_B_123456); /* <send var="B" type="double[N(i) ][N ]"/> */ sprintf(_tp_name, "double(%d)(%d):B#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "123456", _i_start, _i_stop, _i_step, 0, (N), 1, sizeof(double)); _tp_size = (((_i_stop - _i_start - 1) / _i_step + 1) * (N)) * sizeof(double); _tp_B_123456 = (double *)malloc(_tp_size); for (_x0_123456 = _i_start, _y0_123456 =0; _x0_123456 < _i_stop; _x0_123456 +=_i_step, _y0_123456 ++) { for (_x1_123456 = 0; _x1_123456 < (N); _x1_123456 +=1) { _tp_B_123456[_y0_123456 * (N) + _x1_123456] = B[_x0_123456][_x1_123456]; } } _status = _send_data(_distributor, _tp_name, (char *)_tp_B_123456, _tp_size); if (_status < 0) exit(-1); free(_tp_B_123456); /* <send var="B" type="double[N ][N(k:k-1) ]" opt="XCHG"/> */ sprintf(_tp_name, "double(%d)(%d):B#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "123456", 0, (N), 1, (_k_start-1), (_k_stop-1), _k_step, sizeof(double)); _tp_size = ((N) * (((_k_stop-1) - (_k_start-1) - 1) / _k_step + 1)) * sizeof(double); _tp_B_123456 = (double *)malloc(_tp_size); for (_x0_123456 = 0; _x0_123456 < (N); _x0_123456 +=1) { for (_x1_123456 = (_k_start-1), _y1_123456 =0; _x1_123456 < (_k_stop-1); _x1_123456 +=_k_step, _y1_123456 ++) { _tp_B_123456[_x0_123456 * (((_k_stop-1) - (_k_start-1) - 1) / _k_step + 1) + _y1_123456] = B[_x0_123456][_x1_123456]; } } _status = _send_data(_constructor, _tp_name, (char *)_tp_B_123456, _tp_size); if (_status < 0) exit(-1); free(_tp_B_123456); /* <send var="B" type="double[N(i:$L-1)][N(k) ]" opt="XCHG"/> */ sprintf(_tp_name, "double(%d)(%d):B#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "123456", (_i_start-1), _i_start, _i_step, _k_start, _k_stop, _k_step, sizeof(double)); _tp_size = (((_i_start - (_i_start-1) - 1) / _i_step + 1) * ((_k_stop - _k_start - 1) / _k_step + 1)) * sizeof(double); _tp_B_123456 = (double *)malloc(_tp_size); for (_x0_123456 = (_i_start-1), _y0_123456 =0; _x0_123456 < _i_start; _x0_123456 +=_i_step, _y0_123456 ++) { for (_x1_123456 = _k_start, _y1_123456 =0; _x1_123456 < _k_stop; _x1_123456 +=_k_step, _y1_123456 ++) { _tp_B_123456[_y0_123456 * ((_k_stop - _k_start - 1) / _k_step + 1) + _y1_123456] = B[_x0_123456][_x1_123456]; } } _status = _send_data(_constructor, _tp_name, (char *)_tp_B_123456, _tp_size); if (_status < 0) exit(-1); free(_tp_B_123456); /* <read var="C" type="double[N ][N ]"/> */ sprintf(_tp_name, "double(%d)(%d):C#%s", (N), (N), "123456"); _tp_size = ((N) * (N)) * sizeof(double); _tp_C_123456 = (double *)malloc(_tp_size); _tp_size = _read_data(_constructor, _tp_name, (char *)_tp_C_123456, _tp_size); if (_tp_size < 0) exit(-1); for (_x0_123456 = 0; _x0_123456 < (N); _x0_123456 +=1) { for (_x1_123456 = 0; _x1_123456 < (N); _x1_123456 +=1) { C[_x0_123456][_x1_123456] = _tp_C_123456[_x0_123456 * (N) + _x1_123456]; } } free(_tp_C_123456); /* <read var="C" type="double[N(i:i-1) ][N ]" opt="XCHG"/> */ sprintf(_tp_name, "double(%d)(%d):C#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "123456", (_i_start-1), (_i_stop-1), _i_step, 0, (N), 1, sizeof(double)); _tp_size = ((((_i_stop-1) - (_i_start-1) - 1) / _i_step + 1) * (N)) * sizeof(double); _tp_C_123456 = (double *)malloc(_tp_size); _tp_size = _read_data(_distributor, _tp_name, (char *)_tp_C_123456, _tp_size); if (_tp_size < 0) exit(-1); for (_x0_123456 = (_i_start-1), _y0_123456 =0; _x0_123456 < (_i_stop-1); _x0_123456 +=_i_step, _y0_123456 ++) { for (_x1_123456 = 0; _x1_123456 < (N); _x1_123456 +=1) { C[_x0_123456][_x1_123456] = _tp_C_123456[_y0_123456 * (N) + _x1_123456]; } } free(_tp_C_123456); /* <read var="C" type="double[N ][N(k:k-1) ]" opt="XCHG"/> */ sprintf(_tp_name, "double(%d)(%d):C#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "123456", 0, (N), 1, (_k_start-1), (_k_stop-1), _k_step, sizeof(double)); _tp_size = ((N) * (((_k_stop-1) - (_k_start-1) - 1) / _k_step + 1)) * sizeof(double); _tp_C_123456 = (double *)malloc(_tp_size); _tp_size = _read_data(_distributor, _tp_name, (char *)_tp_C_123456, _tp_size); if (_tp_size < 0) exit(-1); for (_x0_123456 = 0; _x0_123456 < (N); _x0_123456 +=1) { for (_x1_123456 = (_k_start-1), _y1_123456 =0; _x1_123456 < (_k_stop-1); _x1_123456 +=_k_step, _y1_123456 ++) { C[_x0_123456][_x1_123456] = _tp_C_123456[_x0_123456 * (((_k_stop-1) - (_k_start-1) - 1) / _k_step + 1) + _y1_123456]; } } free(_tp_C_123456); /* <read var="C" type="double[N(i:$H-1)][N(k:$L-1)]"/> */ sprintf(_tp_name, "double(%d)(%d):C#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "123456", _i_stop, (_i_stop-1), _i_step, (_k_start-1), _k_start, _k_step, sizeof(double)); _tp_size = ((((_i_stop-1) - _i_stop - 1) / _i_step + 1) * ((_k_start - (_k_start-1) - 1) / _k_step + 1)) * sizeof(double); _tp_C_123456 = (double *)malloc(_tp_size); _tp_size = _read_data(_constructor, _tp_name, (char *)_tp_C_123456, _tp_size); if (_tp_size < 0) exit(-1); for (_x0_123456 = _i_stop, _y0_123456 =0; _x0_123456 < (_i_stop-1); _x0_123456 +=_i_step, _y0_123456 ++) { for (_x1_123456 = (_k_start-1), _y1_123456 =0; _x1_123456 < _k_start; _x1_123456 +=_k_step, _y1_123456 ++) { C[_x0_123456][_x1_123456] = _tp_C_123456[_y0_123456 * ((_k_start - (_k_start-1) - 1) / _k_step + 1) + _y1_123456]; } } free(_tp_C_123456); /* <read var="scalar" type="int" opt="_MAX|XCHG"/> */ sprintf(_tp_name, "int:scalar#%s?MAX@%d", "123456", _tokens); _tp_size = sizeof(int); _tp_scalar_123456 = &scalar; _tp_size = _read_data(_distributor, _tp_name, (char *)_tp_scalar_123456, _tp_size); if (_tp_size < 0) exit(-1); /* <read var="scalar" type="int" opt="_MIN"/> */ sprintf(_tp_name, "int:scalar#%s?MIN@%d", "123456", _tokens); _tp_size = sizeof(int); _tp_scalar_123456 = &scalar; _tp_size = _read_data(_constructor, _tp_name, (char *)_tp_scalar_123456, _tp_size); if (_tp_size < 0) exit(-1); _close_space(_constructor, "123456", 1); _close_space(_distributor, "123456", 1); /* </master> */ for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { printf("%8.1f ", C[i][j]); } printf("\n"); } exit(0); }
main(int argc, char **argv[]) { /* <reference id="123456"> */ int i, j, k; /* </reference> */ for (i = 0; i < N ; i++) { for (j = 0; j < N; j++) { A[i][j] = (double) i * j ; B[i][j] = (double) i * j ; C[i][j] = 0; } } /* <master id="123456"> */ _distributor = _open_space("distributor", 0, "123456"); _constructor = _open_space("constructor", 0, "123456"); _cleanup_space(_distributor, "123456"); _cleanup_space(_constructor, "123456"); /* <send var="B" type="double[N ][N ]" opt="ONCE"/> */ sprintf(_tp_name, "double(%d)(%d):B#%s", (N), (N), "123456"); _tp_size = ((N) * (N)) * sizeof(double); _tp_B_123456 = (double *)malloc(_tp_size); for (_x0_123456 = 0; _x0_123456 < (N); _x0_123456 +=1) { for (_x1_123456 = 0; _x1_123456 < (N); _x1_123456 +=1) { _tp_B_123456[_x0_123456 * (N) + _x1_123456] = B[_x0_123456][_x1_123456]; } } _status = _send_data(_distributor, _tp_name, (char *)_tp_B_123456, _tp_size); if (_status < 0) exit(-1); free(_tp_B_123456); /* <token action="SET" idxset="(i)"/> */ sprintf(_tp_name, "token#%s", "123456"); sprintf(_tp_token, "=(i:%d~%d,%d:#%d)", 0, N, 1, G); _tp_size = sizeof(_tp_token); _tokens = _set_token(_distributor, _tp_name, (char *)_tp_token, _tp_size); if (_tokens < 0) exit(-1); /* <send var="A" type="double[N ][N ]"/> */ sprintf(_tp_name, "double(%d)(%d):A#%s", (N), (N), "123456"); _tp_size = ((N) * (N)) * sizeof(double); _tp_A_123456 = (double *)malloc(_tp_size); for (_x0_123456 = 0; _x0_123456 < (N); _x0_123456 +=1) { for (_x1_123456 = 0; _x1_123456 < (N); _x1_123456 +=1) { _tp_A_123456[_x0_123456 * (N) + _x1_123456] = A[_x0_123456][_x1_123456]; } } _status = _send_data(_distributor, _tp_name, (char *)_tp_A_123456, _tp_size); if (_status < 0) exit(-1); free(_tp_A_123456); /* <read var="C" type="double[N ][N ]"/> */ sprintf(_tp_name, "double(%d)(%d):C#%s", (N), (N), "123456"); _tp_size = ((N) * (N)) * sizeof(double); _tp_C_123456 = (double *)malloc(_tp_size); _tp_size = _read_data(_constructor, _tp_name, (char *)_tp_C_123456, _tp_size); if (_tp_size < 0) exit(-1); for (_x0_123456 = 0; _x0_123456 < (N); _x0_123456 +=1) { for (_x1_123456 = 0; _x1_123456 < (N); _x1_123456 +=1) { C[_x0_123456][_x1_123456] = _tp_C_123456[_x0_123456 * (N) + _x1_123456]; } } free(_tp_C_123456); _close_space(_constructor, "123456", 1); _close_space(_distributor, "123456", 1); /* </master> */ for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { printf("%8.1f ", C[i][j]); } printf("\n"); } exit(0); }
int main() { /* <reference> */ double A[N][N]; double v; int i, j; /* </reference> */ v = 99.9; /* <master id="123"> */ _distributor = _open_space("distributor", 0, "123"); _constructor = _open_space("constructor", 0, "123"); _cleanup_space(_distributor, "123"); _cleanup_space(_constructor, "123"); /* <send var="v" type="double" opt="ONCE"/> */ sprintf(_tp_name, "double:v#%s", "123"); _tp_size = sizeof(double); _tp_v_123 = &v; _status = _send_data(_distributor, _tp_name, (char *)_tp_v_123, _tp_size); if (_status < 0) exit(-1); /* <token action="SET" idxset="(j)"/> */ sprintf(_tp_name, "token#%s", "123"); sprintf(_tp_token, "=(j:%d~%d,%d:#%d)", 0, N, 1, G); _tp_size = sizeof(_tp_token); _tokens = _set_token(_distributor, _tp_name, (char *)_tp_token, _tp_size); if (_tokens < 0) exit(-1); /* <send var="A" type="double[N][N(j)]"/> */ sprintf(_tp_name, "double(%d)(%d):A#%s", (N), (N), "123"); _tp_size = ((N) * (N)) * sizeof(double); _tp_A_123 = (double *)malloc(_tp_size); for (_x0_123 = 0; _x0_123 < (N); _x0_123 +=1) { for (_x1_123 = 0; _x1_123 < (N); _x1_123 +=1) { _tp_A_123[_x0_123 * (N) + _x1_123] = A[_x0_123][_x1_123]; } } _status = _send_data(_distributor, _tp_name, (char *)_tp_A_123, _tp_size); if (_status < 0) exit(-1); free(_tp_A_123); /* <read var="A" type="double[N][N(j)]"/> */ sprintf(_tp_name, "double(%d)(%d):A#%s", (N), (N), "123"); _tp_size = ((N) * (N)) * sizeof(double); _tp_A_123 = (double *)malloc(_tp_size); _tp_size = _read_data(_constructor, _tp_name, (char *)_tp_A_123, _tp_size); if (_tp_size < 0) exit(-1); for (_x0_123 = 0; _x0_123 < (N); _x0_123 +=1) { for (_x1_123 = 0; _x1_123 < (N); _x1_123 +=1) { A[_x0_123][_x1_123] = _tp_A_123[_x0_123 * (N) + _x1_123]; } } free(_tp_A_123); _close_space(_constructor, "123", 1); _close_space(_distributor, "123", 1); /* </master> */ }
/** * Read Update Cache Pool with Buffer */ VOID ReadUpdateCachePool( PCACHE_POOL CachePool, PUCHAR Buf, LONGLONG Offset, ULONG Length #ifdef READ_VERIFY ,PDEVICE_OBJECT LowerDeviceObject ,ULONG DiskNumber ,ULONG PartitionNumber #endif ) { PUCHAR origBuf; ULONG i, front_offset, front_skip, end_cut, origLen; PCACHE_BLOCK pBlock; BOOLEAN front_broken, end_broken; origBuf = Buf; origLen = Length; detect_broken(Offset, Length, front_broken, end_broken, front_offset, front_skip, end_cut); Offset /= BLOCK_SIZE; Length /= BLOCK_SIZE; if(front_broken == TRUE) { #ifdef WRITE_BACK_ENABLE if (_QueryPoolByIndex(CachePool, Offset-1, &pBlock) == TRUE && pBlock->Modified == TRUE) { _read_data(Buf, pBlock, front_offset, front_skip); } #endif Buf += front_skip; } for (i = 0; i < Length; i++) { LONGLONG Index = Offset + i; if (_QueryPoolByIndex(CachePool, Index, &pBlock) == TRUE) { DO_READ_VERIFY(CachePool, &CachePool->Storage, pBlock); #ifdef WRITE_BACK_ENABLE if (pBlock->Modified == TRUE) { _read_data(Buf, pBlock, 0, BLOCK_SIZE); } #endif _IncreaseBlockReference(CachePool, pBlock); } else if (_IsFull(CachePool) == FALSE) { pBlock = _AddNewBlockToPool(CachePool, Index, Buf, FALSE); } else { pBlock = _FindBlockToReplace(CachePool, Index, Buf, FALSE); } Buf += BLOCK_SIZE; } if (end_broken == TRUE) { #ifdef WRITE_BACK_ENABLE if (_QueryPoolByIndex(CachePool, Offset+Length, &pBlock) == TRUE && pBlock->Modified == TRUE) { _read_data(Buf, pBlock, 0, end_cut); } #endif Buf += end_cut; } ASSERT(Buf - origBuf == origLen); }
int readKeyFile(int lock) { FILE *fp; char buf[129]; /* 128 bytes + one ensured '\0' character */ mp_int num; int ver[3]; if ( ! _file_exists(_key_file_name()) ) return 0; if ( ! _file_exists(_cnt_file_name()) ) return 0; if ( ! _file_exists(_gen_file_name()) ) return 0; /* * 1. Reading key file */ fp = fopen(_key_file_name(), "r"); if ( ! fp) return 0; /* If file is opened we can assume that there's a directory * where we can hold lock file */ if (lock) lockingFailed = doLocking(); /* fread can fail; then strlen used in * _ppp_flags might not work as supposed. * It would be best to check values returned by * fread() each time it's used. */ memset(buf, 0, sizeof(buf)); fread(buf, 1, sizeof(buf) - 1, fp); buf[sizeof(buf) - 1] = '\0'; /* Ensure \0 existance so we can treat this buffer with scanf */ fclose(fp); ver[0] = _ppp_version(buf); if (ver[0] < 0) goto error; pppSetFlags(_ppp_flags(buf)); /* load flags */ /* read key */ mp_init(&num); if ( ! _read_data(buf, &num)) goto error; setSeqKey(&num); /* * 2. Reading cnt file */ fp = fopen(_cnt_file_name(), "r"); if ( ! fp) goto error; fread(buf, 1, sizeof(buf) - 1, fp); buf[sizeof(buf) - 1] = '\0'; fclose(fp); ver[1] = _ppp_version(buf); if (ver[1] < 0) goto error; if ( ! _read_data(buf, &num)) goto error; setCurrPasscodeNum(&num); /* * 3. Reading gen file */ fp = fopen(_gen_file_name(), "r"); if ( ! fp) goto error; fread(buf, 1, sizeof(buf) - 1, fp); buf[sizeof(buf) - 1] = '\0'; fclose(fp); ver[2] = _ppp_version(buf); if (ver[2] < 0) goto error; if ( ! _read_data(buf, &num)) goto error; setLastCardGenerated(&num); memset(buf, 0, sizeof(buf)); mp_clear(&num); if ( (ver[0] != ver[1]) || (ver[1] != ver[2]) ) { /* Inconsistency in PPP version among the three data files */ goto error; } /* tell PPP code which version the key expects */ setKeyVersion(ver[0]); return 1; error: memset(buf, 0, sizeof(buf)); mp_clear(&num); if (lock) doUnlocking(); return 0; }
static void * cfio_comm(void *argv) { int clt, ret, i; cfio_msg_t *msg; double IO_time = 0.0, time_temp; int handled_reqs; #ifdef SEND_ADDR for (i = 0; i < client_num; ++i) { cfio_rdma_server_recv_addr(i); } #endif clt = 0; while (comm_done_cnt != client_num) { handled_reqs = cfio_rdma_server_wait_some(); #ifdef DEBUG printf("server %d cfio_rdma_server_wait_some handled %d requests \n", rank, handled_reqs); #endif /// find next client which does not finish its current communication interaction and IO while (1) { clt = (clt + 1) % client_num; if (!comm_dones[clt]) { break; } } cfio_buf_addr_t *addr = (cfio_buf_addr_t *)cfio_rdma_server_get_addr(clt); if ( read_dones[clt] && rdma_buf_empty() && // means copy over (ret = cfio_rdma_addr_server_test(addr))) { /// addr has been changed by client, means new iteration or end of program #ifdef DEBUG cfio_rdma_addr_server_show(rank, client_ids[clt], addr, itrs[clt]); #endif if (1 == ret) { /// 1 == ret, means IO end (1 step over) read_addrs[clt] = addr->used_addr; read_dones[clt] = 0; } else { /// 11 == ret, means IO done (all step over) #ifdef DEBUG printf("server %d WR end, clt %d. \n", rank, clt); #endif comm_dones[clt] = 1; ++comm_done_cnt; continue; } } if (!read_dones[clt] && !rdma_buf_full()) { /// post request to RDMA read client's data _read_data(clt, addr); } if (rdma_buf_exist_msg() && // there are msgs to be copied to msg list cfio_rdma_server_test(clt)) // read request posted by clt completed successfully { /// client's data has been read to local, copy it to msg list _copy_data_to_list(clt); if (rdma_buf_empty() && // copy over read_dones[clt]) { /// copy completed and no more data to read in this itr, to ack client. cfio_rdma_addr_server_clear_signal(addr); #ifdef SEND_ADDR cfio_rdma_server_send_ack(clt); cfio_rdma_server_recv_addr(clt); #else cfio_rdma_server_write_addr(clt); #endif #ifdef DEBUG printf("itr %d server %d client %d WR addr. \n", itrs[clt], rank, client_ids[clt]); #endif } } if (msg_clt_cnt == client_num) { /// all clients' data of one iteration has been copied to msg list, IO it time_temp = times_cur(); while (client_num == msg_clt_cnt) { for (i = 0; i < client_num; ++i) { msg = cfio_recv_get_first(); decode(msg); free(msg); -- msg_cnts[i]; if (0 == msg_cnts[i]) { -- msg_clt_cnt; } } } IO_time += times_cur() - time_temp; for (i = 0; i < client_num; ++i) { printf(", %d", msg_cnts[i]); } printf("\n"); #ifdef DEBUG printf("itr %d server %d IO msgs msg_clt_cnt %d. \n", low_itr, rank, msg_clt_cnt); #endif } } printf("server %d IO time %f. \n", rank, IO_time); return (void *)0; }
main(int argc, char **argv[]) { /* <worker id="234567"> */ _distributor = _open_space("distributor", 0, "234567"); _constructor = _open_space("constructor", 0, "234567"); while (1) { /* <token action="GET" idxset="(i)(j)"/> */ sprintf(_tp_name, "token#%s", "234567"); _tp_size = 0; _tp_size = _get_token(_distributor, _tp_name, (char *)_tp_token, _tp_size); if (_tp_size < 0) exit(-1); if (_tp_token[0] == '!') break; sscanf(_tp_token, "%d@(i:%d~%d,%d)(j:%d~%d,%d)", &_tokens, &_i_start, &_i_stop, &_i_step, &_j_start, &_j_stop, &_j_step); if (_tokens >= _batch_flag) { /* <read var="A" type="double[DIM+2 ][DIM+2 ]"/> */ sprintf(_tp_name, "double(%d)(%d):A#%s", (DIM+2), (DIM+2), "234567"); _tp_size = ((DIM+2) * (DIM+2)) * sizeof(double); _tp_A_234567 = (double *)malloc(_tp_size); _tp_size = _read_data(_distributor, _tp_name, (char *)_tp_A_234567, _tp_size); if (_tp_size < 0) exit(-1); for (_x0_234567 = 0; _x0_234567 < (DIM+2); _x0_234567 +=1) { for (_x1_234567 = 0; _x1_234567 < (DIM+2); _x1_234567 +=1) { A[_x0_234567][_x1_234567] = _tp_A_234567[_x0_234567 * (DIM+2) + _x1_234567]; } } free(_tp_A_234567); } _batch_flag = _tokens; /* <read var="A" type="double[DIM+2(i:$L-1)][DIM+2(j) ]" opt="XCHG"/> */ sprintf(_tp_name, "double(%d)(%d):A#%s[%d~%d,%d][%d~%d,%d]@%d", (DIM+2), (DIM+2), "234567", (_i_start-1), _i_start, _i_step, _j_start, _j_stop, _j_step, sizeof(double)); _tp_size = (((_i_start - (_i_start-1) - 1) / _i_step + 1) * ((_j_stop - _j_start - 1) / _j_step + 1)) * sizeof(double); _tp_A_234567 = (double *)malloc(_tp_size); _tp_size = _read_data(_constructor, _tp_name, (char *)_tp_A_234567, _tp_size); if (_tp_size < 0) exit(-1); for (_x0_234567 = (_i_start-1), _y0_234567 =0; _x0_234567 < _i_start; _x0_234567 +=_i_step, _y0_234567 ++) { for (_x1_234567 = _j_start, _y1_234567 =0; _x1_234567 < _j_stop; _x1_234567 +=_j_step, _y1_234567 ++) { A[_x0_234567][_x1_234567] = _tp_A_234567[_y0_234567 * ((_j_stop - _j_start - 1) / _j_step + 1) + _y1_234567]; } } free(_tp_A_234567); /* <read var="A" type="double[DIM+2(i) ][DIM+2(j:$L-1)]" opt="XCHG"/> */ sprintf(_tp_name, "double(%d)(%d):A#%s[%d~%d,%d][%d~%d,%d]@%d", (DIM+2), (DIM+2), "234567", _i_start, _i_stop, _i_step, (_j_start-1), _j_start, _j_step, sizeof(double)); _tp_size = (((_i_stop - _i_start - 1) / _i_step + 1) * ((_j_start - (_j_start-1) - 1) / _j_step + 1)) * sizeof(double); _tp_A_234567 = (double *)malloc(_tp_size); _tp_size = _read_data(_constructor, _tp_name, (char *)_tp_A_234567, _tp_size); if (_tp_size < 0) exit(-1); for (_x0_234567 = _i_start, _y0_234567 =0; _x0_234567 < _i_stop; _x0_234567 +=_i_step, _y0_234567 ++) { for (_x1_234567 = (_j_start-1), _y1_234567 =0; _x1_234567 < _j_start; _x1_234567 +=_j_step, _y1_234567 ++) { A[_x0_234567][_x1_234567] = _tp_A_234567[_y0_234567 * ((_j_start - (_j_start-1) - 1) / _j_step + 1) + _y1_234567]; } } free(_tp_A_234567); /* * Refine the values in A, these two loops consume most of * the computational time. */ resid = 0.0; /* <target index ="i" order ="1" limits="(1,rdim+1,1)" chunk ="GRAIN"> */ for (i = _i_start; i < _i_stop; i +=_i_step) /* </target> */ { /* <target index ="j" order ="1" limits="(1,DIM+1,1)" chunk ="GRAIN"> */ for (j = _j_start; j < _j_stop; j +=_j_step) /* </target> */ { Atmp = A[i][j]; A[i][j] = 0.25 * (A[i+1][j] + A[i-1][j] + A[i][j+1] + A[i][j-1]); residtmp = (Atmp!=0.0? fabs(fabs(A[i][j]-Atmp)/Atmp) : (1.0+EPS)); if (residtmp > resid) resid = residtmp; } } /* <send var="resid" type="double" opt="_MAX"/> */ sprintf(_tp_name, "double:resid#%s?MAX@%d", "234567", _tokens); _tp_size = sizeof(double); _tp_resid_234567 = &resid; _status = _send_data(_constructor, _tp_name, (char *)_tp_resid_234567, _tp_size); if (_status < 0) exit(-1); /* <send var="A" type="double[DIM+2(i) ][DIM+2(j) ]"/> */ sprintf(_tp_name, "double(%d)(%d):A#%s[%d~%d,%d][%d~%d,%d]@%d", (DIM+2), (DIM+2), "234567", _i_start, _i_stop, _i_step, _j_start, _j_stop, _j_step, sizeof(double)); _tp_size = (((_i_stop - _i_start - 1) / _i_step + 1) * ((_j_stop - _j_start - 1) / _j_step + 1)) * sizeof(double); _tp_A_234567 = (double *)malloc(_tp_size); for (_x0_234567 = _i_start, _y0_234567 =0; _x0_234567 < _i_stop; _x0_234567 +=_i_step, _y0_234567 ++) { for (_x1_234567 = _j_start, _y1_234567 =0; _x1_234567 < _j_stop; _x1_234567 +=_j_step, _y1_234567 ++) { _tp_A_234567[_y0_234567 * ((_j_stop - _j_start - 1) / _j_step + 1) + _y1_234567] = A[_x0_234567][_x1_234567]; } } _status = _send_data(_constructor, _tp_name, (char *)_tp_A_234567, _tp_size); if (_status < 0) exit(-1); free(_tp_A_234567); } _close_space(_constructor, "234567", 0); _close_space(_distributor, "234567", 0); /* </worker> */ exit(0); }
uint16_t tsl2561_read_illuminance(const tsl2561_t *dev) { /* Read IR and full spectrum values */ uint16_t ir = 0; uint16_t full = 0; _read_data(dev, &full, &ir); DEBUG("[Info] Full spectrum value: %i\n", (int)full); DEBUG("[Info] IR spectrum value: %i\n", (int)ir); /* Compute illuminance */ uint32_t channel_scale; uint32_t channel_1; uint32_t channel_0; switch (dev->integration) { case TSL2561_INTEGRATIONTIME_13MS: channel_scale = TSL2561_CHSCALE_TINT0; break; case TSL2561_INTEGRATIONTIME_101MS: channel_scale = TSL2561_CHSCALE_TINT1; break; default: /* No scaling ... integration time = 402ms */ channel_scale = (1 << TSL2561_CHSCALE); break; } /* Scale for gain (1x or 16x) */ if (!dev->gain) { channel_scale = channel_scale << 4; } /* scale the channel values */ channel_0 = (full * channel_scale) >> TSL2561_CHSCALE; channel_1 = (ir * channel_scale) >> TSL2561_CHSCALE; /* find the ratio of the channel values (Channel1/Channel0) */ uint32_t ratio_1 = 0; if (channel_0 != 0) { ratio_1 = (channel_1 << (TSL2561_RATIOSCALE + 1)) / channel_0; } /* round the ratio value */ uint32_t ratio = (ratio_1 + 1) >> 1; uint32_t b, m; if (ratio <= TSL2561_K1T) { b = TSL2561_B1T; m = TSL2561_M1T; } else if (ratio <= TSL2561_K2T) { b = TSL2561_B2T; m = TSL2561_M2T; } else if (ratio <= TSL2561_K3T) { b = TSL2561_B3T; m = TSL2561_M3T; } else if (ratio <= TSL2561_K4T) { b = TSL2561_B4T; m = TSL2561_M4T; } else if (ratio <= TSL2561_K5T) { b = TSL2561_B5T; m = TSL2561_M5T; } else if (ratio <= TSL2561_K6T) { b = TSL2561_B6T; m = TSL2561_M6T; } else if (ratio <= TSL2561_K7T) { b = TSL2561_B7T; m = TSL2561_M7T; } else { b = TSL2561_B8T; m = TSL2561_M8T; } uint32_t illuminance; illuminance = ((channel_0 * b) - (channel_1 * m)); /* round lsb (2^(TSL2561_SCALE - 1)) */ illuminance += (1 << (TSL2561_LUXSCALE - 1)); /* return strip off fractional portion */ return (uint16_t)(illuminance >> TSL2561_LUXSCALE); }
main(int argc, char **argv[]) { /* <worker id="123"> */ _distributor = _open_space("distributor", 0, "123"); _constructor = _open_space("constructor", 0, "123"); /* <read var="v" type="double" opt="ONCE"/> */ sprintf(_tp_name, "double:v#%s", "123"); _tp_size = sizeof(double); _tp_v_123 = &v; _tp_size = _read_data(_distributor, _tp_name, (char *)_tp_v_123, _tp_size); if (_tp_size < 0) exit(-1); while (1) { /* <token action="GET" idxset="(i)(j)"/> */ sprintf(_tp_name, "token#%s", "123"); _tp_size = 0; _tp_size = _get_token(_distributor, _tp_name, (char *)_tp_token, _tp_size); if (_tp_size < 0) exit(-1); if (_tp_token[0] == '!') break; sscanf(_tp_token, "%d@(i:%d~%d,%d)(j:%d~%d,%d)", &_tokens, &_i_start, &_i_stop, &_i_step, &_j_start, &_j_stop, &_j_step); /* <read var="A" type="double[N(i)][N(j)]"/> */ sprintf(_tp_name, "double(%d)(%d):A#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "123", _i_start, _i_stop, 1, _j_start, _j_stop, 1, sizeof(double)); _tp_size = (((_i_stop - _i_start - 1) / 1 + 1) * ((_j_stop - _j_start - 1) / 1 + 1)) * sizeof(double); _tp_A_123 = (double *)malloc(_tp_size); _tp_size = _read_data(_distributor, _tp_name, (char *)_tp_A_123, _tp_size); if (_tp_size < 0) exit(-1); for (_x0_123 = _i_start, _y0_123 =0; _x0_123 < _i_stop; _x0_123 +=1, _y0_123 ++) { for (_x1_123 = _j_start, _y1_123 =0; _x1_123 < _j_stop; _x1_123 +=1, _y1_123 ++) { A[_x0_123][_x1_123] = _tp_A_123[_y0_123 * ((_j_stop - _j_start - 1) / 1 + 1) + _y1_123]; } } free(_tp_A_123); /* <target index ="i" order ="1" limits="(0,N,1)" chunk ="G"> */ for (i = _i_start; i < _i_stop; i +=_i_step) /* </target> */ { /* <target index ="j" order ="2" limits="(0,N,1)" chunk ="G"> */ for (j = _j_start; j < _j_stop; j +=_j_step) /* </target> */ { A[i, j] = v; } } /* <send var="A" type="double[N(i)][N(j)]"/> */ sprintf(_tp_name, "double(%d)(%d):A#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "123", _i_start, _i_stop, 1, _j_start, _j_stop, 1, sizeof(double)); _tp_size = (((_i_stop - _i_start - 1) / 1 + 1) * ((_j_stop - _j_start - 1) / 1 + 1)) * sizeof(double); _tp_A_123 = (double *)malloc(_tp_size); for (_x0_123 = _i_start, _y0_123 =0; _x0_123 < _i_stop; _x0_123 +=1, _y0_123 ++) { for (_x1_123 = _j_start, _y1_123 =0; _x1_123 < _j_stop; _x1_123 +=1, _y1_123 ++) { _tp_A_123[_y0_123 * ((_j_stop - _j_start - 1) / 1 + 1) + _y1_123] = A[_x0_123][_x1_123]; } } _status = _send_data(_constructor, _tp_name, (char *)_tp_A_123, _tp_size); if (_status < 0) exit(-1); free(_tp_A_123); } _close_space(_constructor, "123", 0); _close_space(_distributor, "123", 0); /* </worker> */ exit(0); }