int bound_mpi_int(int boundstage, int boundvartype, PFTYPE (*prim)[NSTORE2][NSTORE3][NUMPFLAGS]) { int dir; #if(USEMPI) /* These arrays contain designations that identify * each recv and send */ static MPI_Request requests[COMPDIM * 2 * 2]; // format of map for requests[dir*2+recv/send(0/1)] #endif #if(USEMPI) /////////////// // dir=1 if((boundstage==STAGE0)||(boundstage==STAGEM1)){ for(dir=X1UP;dir<=X1DN;dir++) if(dirgenset[boundvartype][dir][DIRIF]) pack_int(dir,boundvartype,prim,workbc_int); for(dir=X1UP;dir<=X1DN;dir++) if(dirgenset[boundvartype][dir][DIRIF]) sendrecv_int(dir,boundvartype,workbc_int,requests); } if((boundstage==STAGE1)||(boundstage==STAGEM1)){ for(dir=X1UP;dir<=X1DN;dir++) if(dirgenset[boundvartype][dir][DIRIF]) recvwait(dir,requests); for(dir=X1UP;dir<=X1DN;dir++) if(dirgenset[boundvartype][dir][DIRIF]) unpack_int(dir,boundvartype,workbc_int,prim); for(dir=X1UP;dir<=X1DN;dir++) if(dirgenset[boundvartype][dir][DIRIF]) sendwait(dir,requests); } /////////////// // dir=2 if((boundstage==STAGE2)||(boundstage==STAGEM1)){ for(dir=X2UP;dir<=X2DN;dir++) if(dirgenset[boundvartype][dir][DIRIF]) pack_int(dir,boundvartype,prim,workbc_int); for(dir=X2UP;dir<=X2DN;dir++) if(dirgenset[boundvartype][dir][DIRIF]) sendrecv_int(dir,boundvartype,workbc_int,requests); } if((boundstage==STAGE3)||(boundstage==STAGEM1)){ for(dir=X2UP;dir<=X2DN;dir++) if(dirgenset[boundvartype][dir][DIRIF]) recvwait(dir,requests); for(dir=X2UP;dir<=X2DN;dir++) if(dirgenset[boundvartype][dir][DIRIF]) unpack_int(dir,boundvartype,workbc_int,prim); for(dir=X2UP;dir<=X2DN;dir++) if(dirgenset[boundvartype][dir][DIRIF]) sendwait(dir,requests); } /////////////// // dir=3 if((boundstage==STAGE4)||(boundstage==STAGEM1)){ for(dir=X3UP;dir<=X3DN;dir++) if(dirgenset[boundvartype][dir][DIRIF]) pack_int(dir,boundvartype,prim,workbc_int); for(dir=X3UP;dir<=X3DN;dir++) if(dirgenset[boundvartype][dir][DIRIF]) sendrecv_int(dir,boundvartype,workbc_int,requests); } if((boundstage==STAGE5)||(boundstage==STAGEM1)){ for(dir=X3UP;dir<=X3DN;dir++) if(dirgenset[boundvartype][dir][DIRIF]) recvwait(dir,requests); for(dir=X3UP;dir<=X3DN;dir++) if(dirgenset[boundvartype][dir][DIRIF]) unpack_int(dir,boundvartype,workbc_int,prim); for(dir=X3UP;dir<=X3DN;dir++) if(dirgenset[boundvartype][dir][DIRIF]) sendwait(dir,requests); } // now corner zones will be filled correctly // GODMARK: If made fixup_utoprim() and check_solution() not use corner zones could bound all directions at once -- probably not important performance hit // end if mpi #endif return(0); }
/* * read configuration sent by scanner and populate "config" in * ENGINE_USER structure */ static int init_unpack(ENGINE_USER * usr, char * buffer, int size) { EC_CONFIG * cfg = usr->config; int ofs = 0; int tag = unpack_int(buffer, &ofs); assert(tag == MSG_CONFIG); int scanner_config_size = unpack_int(buffer, &ofs); read_config(buffer + ofs, scanner_config_size, cfg); ofs += scanner_config_size; int mapping_config_size = unpack_int(buffer, &ofs); parseEntriesFromBuffer(buffer + ofs, mapping_config_size, cfg); ELLNODE * node; for(node = ellFirst(&cfg->devices); node; node = ellNext(node)) { EC_DEVICE * device = (EC_DEVICE *)node; printf("%s\n", device->name); ELLNODE * node1; for(node1 = ellFirst(&device->pdo_entry_mappings); node1; node1 = ellNext(node1)) { EC_PDO_ENTRY_MAPPING * mapping = (EC_PDO_ENTRY_MAPPING *)node1; if(strcmp(mapping->pdo_entry->name, mapping->pdo_entry->parent->name) == 0) { printf(" %s\n", mapping->pdo_entry->name); } else { printf(" %s %s\n", mapping->pdo_entry->parent->name, mapping->pdo_entry->name); } } } return 0; }
/* unpack sphere from double and integer buffers (unpacking starts at dpos and ipos in * d and i and no more than a specific number of doubles and ints can be red) */ SPHERE* SPHERE_Unpack (void *solfec, int *dpos, double *d, int doubles, int *ipos, int *i, int ints) { SPHERE *sph; int j; ERRMEM (sph = MEM_CALLOC (sizeof (SPHERE))); sph->surface = unpack_int (ipos, i, ints); sph->volume = unpack_int (ipos, i, ints); unpack_doubles (dpos, d, doubles, sph->cur_center, 3); unpack_doubles (dpos, d, doubles, (double*)sph->cur_point, 9); sph->cur_radius = unpack_double (dpos, d, doubles); unpack_doubles (dpos, d, doubles, sph->ref_center, 3); unpack_doubles (dpos, d, doubles, (double*)sph->ref_point, 9); sph->ref_radius = unpack_double (dpos, d, doubles); j = unpack_int (ipos, i, ints); /* unpack material existence flag */ if (j) { SOLFEC *sol = solfec; char *label = unpack_string (ipos, i, ints); ASSERT_DEBUG_EXT (sph->mat = MATSET_Find (sol->mat, label), "Failed to find material when unpacking a sphere"); free (label); } return sph; }
static void handle_resize(struct tmate_session *session, struct tmate_unpacker *uk) { session->min_sx = unpack_int(uk); session->min_sy = unpack_int(uk); recalculate_sizes(); }
/* unpack ellipsoid from double and integer buffers (unpacking starts at dpos and ipos in * d and i and no more than a specific number of doubles and ints can be red) */ ELLIP* ELLIP_Unpack (void *solfec, int *dpos, double *d, int doubles, int *ipos, int *i, int ints) { ELLIP *eli; int j; ERRMEM (eli = MEM_CALLOC (sizeof (ELLIP))); eli->surface = unpack_int (ipos, i, ints); eli->volume = unpack_int (ipos, i, ints); unpack_doubles (dpos, d, doubles, eli->cur_center, 3); unpack_doubles (dpos, d, doubles, (double*)eli->cur_point, 9); unpack_doubles (dpos, d, doubles, eli->ref_center, 3); unpack_doubles (dpos, d, doubles, (double*)eli->ref_point, 9); unpack_doubles (dpos, d, doubles, eli->ref_sca, 3); unpack_doubles (dpos, d, doubles, eli->ref_rot, 9); unpack_doubles (dpos, d, doubles, eli->cur_sca, 3); unpack_doubles (dpos, d, doubles, eli->cur_rot, 9); j = unpack_int (ipos, i, ints); /* unpack material existence flag */ if (j) { SOLFEC *sol = solfec; char *label = unpack_string (ipos, i, ints); ASSERT_DEBUG_EXT (eli->mat = MATSET_Find (sol->mat, label), "Failed to find material when unpacking a eliere"); free (label); } return eli; }
static void tmate_client_resize(struct tmate_unpacker *uk) { /* TODO This is sad, we might want our own client. */ tmate_sx = unpack_int(uk); tmate_sy = unpack_int(uk); recalculate_sizes(); /* TODO Handle reconnection cases */ }
int bound_mpi_int(int boundstage, int prim[][N2M][N3M][NUMPFLAGS]) { int dir; #if(USEMPI) /* These arrays contain designations that identify * each recv and send */ static MPI_Request requests[COMPDIM * 2 * 2]; // format of map for requests[dir*2+recv/send(0/1)] #endif #if(USEMPI) if((boundstage==STAGE0)||(boundstage==STAGEM1)){ for(dir=X1UP;dir<=X1DN;dir++) if(dirset[BOUNDPRIMTYPE][dir][DIRIF]) pack_int(dir,prim,workbc_int); for(dir=X1UP;dir<=X1DN;dir++) if(dirset[BOUNDPRIMTYPE][dir][DIRIF]) sendrecv_int(dir,workbc_int,requests); } if((boundstage==STAGE1)||(boundstage==STAGEM1)){ for(dir=X1UP;dir<=X1DN;dir++) if(dirset[BOUNDPRIMTYPE][dir][DIRIF]) recvwait(dir,requests); for(dir=X1UP;dir<=X1DN;dir++) if(dirset[BOUNDPRIMTYPE][dir][DIRIF]) unpack_int(dir,workbc_int,prim); for(dir=X1UP;dir<=X1DN;dir++) if(dirset[BOUNDPRIMTYPE][dir][DIRIF]) sendwait(dir,requests); } if((boundstage==STAGE2)||(boundstage==STAGEM1)){ for(dir=X2UP;dir<=X2DN;dir++) if(dirset[BOUNDPRIMTYPE][dir][DIRIF]) pack_int(dir,prim,workbc_int); for(dir=X2UP;dir<=X2DN;dir++) if(dirset[BOUNDPRIMTYPE][dir][DIRIF]) sendrecv_int(dir,workbc_int,requests); } if((boundstage==STAGE3)||(boundstage==STAGEM1)){ for(dir=X2UP;dir<=X2DN;dir++) if(dirset[BOUNDPRIMTYPE][dir][DIRIF]) recvwait(dir,requests); for(dir=X2UP;dir<=X2DN;dir++) if(dirset[BOUNDPRIMTYPE][dir][DIRIF]) unpack_int(dir,workbc_int,prim); for(dir=X2UP;dir<=X2DN;dir++) if(dirset[BOUNDPRIMTYPE][dir][DIRIF]) sendwait(dir,requests); } if((boundstage==STAGE4)||(boundstage==STAGEM1)){ for(dir=X3UP;dir<=X3DN;dir++) if(dirset[BOUNDPRIMTYPE][dir][DIRIF]) pack_int(dir,prim,workbc_int); for(dir=X3UP;dir<=X3DN;dir++) if(dirset[BOUNDPRIMTYPE][dir][DIRIF]) sendrecv_int(dir,workbc_int,requests); } if((boundstage==STAGE5)||(boundstage==STAGEM1)){ for(dir=X3UP;dir<=X3DN;dir++) if(dirset[BOUNDPRIMTYPE][dir][DIRIF]) recvwait(dir,requests); for(dir=X3UP;dir<=X3DN;dir++) if(dirset[BOUNDPRIMTYPE][dir][DIRIF]) unpack_int(dir,workbc_int,prim); for(dir=X3UP;dir<=X3DN;dir++) if(dirset[BOUNDPRIMTYPE][dir][DIRIF]) sendwait(dir,requests); } // end if mpi #endif return(0); }
static void handle_exec_cmd_str(__unused struct tmate_session *session, struct tmate_unpacker *uk) { struct cmd_q *cmd_q; struct cmd_list *cmdlist; char *cause; u_int i; int client_id = unpack_int(uk); char *cmd_str = unpack_string(uk); if (cmd_string_parse(cmd_str, &cmdlist, NULL, 0, &cause) != 0) { tmate_failed_cmd(client_id, cause); free(cause); goto out; } cmd_q = cmdq_new(NULL); cmdq_run(cmd_q, cmdlist, NULL); cmd_list_free(cmdlist); cmdq_free(cmd_q); /* error messages land in cfg_causes */ for (i = 0; i < cfg_ncauses; i++) { tmate_failed_cmd(client_id, cfg_causes[i]); free(cfg_causes[i]); } free(cfg_causes); cfg_causes = NULL; cfg_ncauses = 0; out: free(cmd_str); }
static void tmate_client_exec_cmd(struct tmate_unpacker *uk) { struct cmd_q *cmd_q; struct cmd_list *cmdlist; char *cause; int client_id = unpack_int(uk); char *cmd_str = unpack_string(uk); if (cmd_string_parse(cmd_str, &cmdlist, NULL, 0, &cause) != 0) { tmate_failed_cmd(client_id, cause); free(cause); goto out; } /* error messages land in cfg_causes */ ARRAY_FREE(&cfg_causes); cmd_q = cmdq_new(NULL); cmdq_run(cmd_q, cmdlist); cmd_list_free(cmdlist); cmdq_free(cmd_q); if (!ARRAY_EMPTY(&cfg_causes)) { cause = ARRAY_ITEM(&cfg_causes, 0); tmate_failed_cmd(client_id, cause); free(cause); ARRAY_FREE(&cfg_causes); } out: free(cmd_str); }
ptr<pub3::expr_t> msgpack_t::unpack_negative_fixnum () { int8_t b; bool ok = unpack_int (&b); assert (ok); return pub3::expr_int_t::alloc (b); }
int msa_recv_pkt(msa_pkt_t *pkt, int sfd) { byte_t *dt = 0; byte_t st_u = 0; size_t st_sz = 0, id_sz = 0, sz_sz = 0; unsigned int id_u = 0, sz_u = 0; assert(sfd >= 0); st_sz = sizeof(byte_t); id_sz = sizeof(int); sz_sz = sizeof(int); dt = malloc(st_sz); msa_recv_all(sfd, dt, st_sz); st_u = unpack_byte(dt); pkt->st = st_u; free(dt); dt = 0; dt = malloc(id_sz); msa_recv_all(sfd, dt, id_sz); id_u = unpack_int(dt); pkt->id = id_u; free(dt); dt = 0; dt = malloc(sz_sz); msa_recv_all(sfd, dt, sz_sz); sz_u = unpack_int(dt); pkt->sz = sz_u; free(dt); dt = 0; if (sz_u != 0) { dt = malloc(sz_u * sizeof(char)); msa_recv_all(sfd, dt, sz_u * sizeof(char)); pkt->da = unpack_str(dt, sz_u * sizeof(char)); free(dt); dt = 0; } else { pkt->da = 0; } return 0; /* do some error checking? */ }
static void handle_pane_key(__unused struct tmate_session *_session, struct tmate_unpacker *uk) { struct session *s; struct window_pane *wp; int pane_id = unpack_int(uk); key_code key = unpack_int(uk); s = RB_MIN(sessions, &sessions); if (!s) return; wp = find_window_pane(s, pane_id); if (!wp) return; window_pane_key(wp, NULL, s, key, NULL); }
ptr<pub3::expr_t> msgpack_t::unpack_map32 () { consume_byte (); u_int32_t n; bool ok = unpack_int (&n); ptr<pub3::expr_t> ret; if (ok) { ret = unpack_map (n); } return ret; }
ptr<pub3::expr_t> msgpack_t::unpack_raw16 () { consume_byte (); u_int16_t s; bool ok = unpack_int (&s); ptr<pub3::expr_t> ret; if (ok) { ret = unpack_raw (s); } return ret; }
ptr<pub3::expr_t> msgpack_t::unpack_array16 () { consume_byte (); u_int16_t n; bool ok = unpack_int (&n); ptr<pub3::expr_t> ret; if (ok) { ret = unpack_array (n); } return ret; }
void process_msg(unsigned char *content, int nbytes, message_t type) { //place test code for parsing received message here printf("recv'd message: "); switch(type) { case HANDSHAKE: printf("Handshake from %d\n", unpack_int(content)); break; case CHOKE: printf("CHOKE\n"); break; case UNCHOKE: printf("UNCHOKE\n"); break; case INTERESTED: printf("INTERESTED\n"); break; case NOT_INTERESTED: printf("NOT_INTERESTED\n"); break; case HAVE: printf("HAVE piece %d\n", unpack_int(content)); break; case BITFIELD: printf("BITFIELD: "); int i; for (i = 0 ; i < g_bitfield_len ; i++) { printf("%X ", content[i]); } break; case REQUEST: printf("REQUEST piece %d\n", unpack_int(content)); break; case PIECE: printf("PIECE \n"); extract_and_save_piece(nbytes, content, 4); break; default: break; } }
static void handle_exec_cmd(__unused struct tmate_session *session, struct tmate_unpacker *uk) { struct cmd_q *cmd_q; struct cmd_list *cmdlist; struct cmd *cmd; char *cause; u_int i; unsigned int argc; char **argv; int client_id = unpack_int(uk); argc = uk->argc; argv = xmalloc(sizeof(char *) * argc); for (i = 0; i < argc; i++) argv[i] = unpack_string(uk); cmd = cmd_parse(argc, argv, NULL, 0, &cause); if (!cmd) { tmate_failed_cmd(client_id, cause); free(cause); goto out; } cmdlist = xcalloc(1, sizeof *cmdlist); cmdlist->references = 1; TAILQ_INIT(&cmdlist->list); TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry); cmd_q = cmdq_new(NULL); cmdq_run(cmd_q, cmdlist, NULL); cmd_list_free(cmdlist); cmdq_free(cmd_q); /* error messages land in cfg_causes */ for (i = 0; i < cfg_ncauses; i++) { tmate_failed_cmd(client_id, cfg_causes[i]); free(cfg_causes[i]); } free(cfg_causes); cfg_causes = NULL; cfg_ncauses = 0; out: cmd_free_argv(argc, argv); }
void tmate_dispatch_slave_message(struct tmate_session *session, struct tmate_unpacker *uk) { int cmd = unpack_int(uk); switch (cmd) { #define dispatch(c, f) case c: f(session, uk); break dispatch(TMATE_IN_NOTIFY, handle_notify); dispatch(TMATE_IN_LEGACY_PANE_KEY, handle_legacy_pane_key); dispatch(TMATE_IN_RESIZE, handle_resize); dispatch(TMATE_IN_EXEC_CMD_STR, handle_exec_cmd_str); dispatch(TMATE_IN_SET_ENV, handle_set_env); dispatch(TMATE_IN_READY, handle_ready); dispatch(TMATE_IN_PANE_KEY, handle_pane_key); dispatch(TMATE_IN_EXEC_CMD, handle_exec_cmd); default: tmate_info("Bad message type: %d", cmd); } }
static void handle_message(struct tmate_decoder *decoder, msgpack_object obj) { struct tmate_unpacker _uk; struct tmate_unpacker *uk = &_uk; init_unpacker(uk, obj); switch (unpack_int(uk)) { case TMATE_NOTIFY: tmate_notify(uk); break; case TMATE_CLIENT_PANE_KEY: tmate_client_pane_key(uk); break; case TMATE_CLIENT_RESIZE: tmate_client_resize(uk); break; case TMATE_CLIENT_EXEC_CMD: tmate_client_exec_cmd(uk); break; case TMATE_CLIENT_ENV: tmate_client_env(uk); break; case TMATE_CLIENT_READY: tmate_client_ready(decoder, uk); break; default: decoder_error(); } }
static void tmate_client_pane_key(struct tmate_unpacker *uk) { struct session *s; struct window *w; struct window_pane *wp; int key = unpack_int(uk); s = RB_MIN(sessions, &sessions); if (!s) return; w = s->curw->window; if (!w) return; wp = w->active; if (!wp) return; window_pane_key(wp, s, key); }
static void handle_legacy_pane_key(__unused struct tmate_session *_session, struct tmate_unpacker *uk) { struct session *s; struct window *w; struct window_pane *wp; int key = unpack_int(uk); s = RB_MIN(sessions, &sessions); if (!s) return; w = s->curw->window; if (!w) return; wp = w->active; if (!wp) return; window_pane_key(wp, NULL, s, key, NULL); }
int bound_mpi_int_dir(int boundstage, int finalstep, int whichdir, int boundvartype, PFTYPE (*prim)[NSTORE2][NSTORE3][NUMPFLAGS]) { int dir; static MPI_Request requests[COMPDIM * 2 * 2]; static int didpostrecvs[COMPDIM*2]={0}; int dirstart,dirfinish; if(whichdir==-1 || whichdir==1){ dirstart=X1UP; dirfinish=X1DN;} if(whichdir==-2 || whichdir==2){ dirstart=X2UP; dirfinish=X2DN;} if(whichdir==-3 || whichdir==3){ dirstart=X3UP; dirfinish=X3DN;} //////////// // // pre-post recv's // // OPTMARK: Could avoid dir-dependent MPI calls in step_ch.c (currently true!) and post all recv's for all dirs at once. // OPTMARK: Or setup MPIFLOWCONTROL==2 or SUPERMPI // //////////// if(whichdir==-1 || whichdir==-2 || whichdir==-3){ if((boundstage==STAGEM1)||(boundstage==STAGE0)){ for(dir=dirstart;dir<=dirfinish;dir++){ if(dirgenset[boundvartype][dir][DIRIF]){ recvonly_int(dir,boundvartype,workbc_int,requests); didpostrecvs[dir]=1; } } } } else if(whichdir==1 || whichdir==2 || whichdir==3){ ////////////////// // // per-whichdir (1,2,3) conditionals for bounding. Assume whichdir=1 done first, then 2, then 3, so that corners are done correctly as done with normal bounds. // ////////////////// /////////////////// // // x or y or z -dir // once dir=0,1(X1UP,X1DN) is done, so can start 2,3(X2UP,X2DN) // ///////////////// if((boundstage==STAGEM1)||(boundstage==STAGE0&&whichdir==1 || boundstage==STAGE2&&whichdir==2 || boundstage==STAGE4&&whichdir==3)){ for(dir=dirstart;dir<=dirfinish;dir++){ if(dirgenset[boundvartype][dir][DIRIF]){ if(didpostrecvs[dir]==0){ dualfprintf(fail_file,"Did not post recv and tried to already pack: dir=%d\n",dir); myexit(234525155); } pack_int(dir,boundvartype,prim,workbc_int); } } for(dir=dirstart;dir<=dirfinish;dir++) if(dirgenset[boundvartype][dir][DIRIF]) sendonly_int(dir,boundvartype,workbc_int,requests); } if((boundstage==STAGEM1)||(boundstage==STAGE1&&whichdir==1 || boundstage==STAGE3&&whichdir==2 || boundstage==STAGE5&&whichdir==3)){ for(dir=dirstart;dir<=dirfinish;dir++) if(dirgenset[boundvartype][dir][DIRIF]){ recvwait(dir,requests); didpostrecvs[dir]=0; // done with recv's } for(dir=dirstart;dir<=dirfinish;dir++) if(dirgenset[boundvartype][dir][DIRIF]) unpack_int(dir,boundvartype,workbc_int,prim); for(dir=dirstart;dir<=dirfinish;dir++) if(dirgenset[boundvartype][dir][DIRIF]) sendwait(dir,requests); } } else{ dualfprintf(fail_file,"No such whichdir=%d in boundmpiint.c\n",whichdir); myexit(1986290387); } // now corner zones will be filled correctly // GODMARK: If made fixup_utoprim() and check_solution() not use corner zones could bound all directions at once -- probably not important performance hit return(0); }