def load_bal(cx, npart): ''' cx is list of (complexity, gid) pairs on this process return: an LPT balanced list of gids that should belong to this process ''' elapse = h.startsw() #send to rank 0 r = all2all({0: cx}) # make a list of all the (cx, gid) s = {} if rank == 0: c = [] for i in r.values(): c += i del r #distribute by LPT parts = lpt(c, npart) print statistics(parts) for i, p in enumerate(parts): s.update({i: p[1]}) else: del r #send each partition to the proper rank local = all2all(s) del s if rank == 0: print "load_bal time %g" % (h.startsw() - elapse) return local[0]
def load_bal(cx, npart): ''' cx is list of (complexity, gid) pairs on this process return: an LPT balanced list of gids that should belong to this process ''' elapse = h.startsw() #send to rank 0 r = all2all({0:cx}) # make a list of all the (cx, gid) s = {} if rank == 0: c = [] for i in r.values(): c += i del r #distribute by LPT parts = lpt(c, npart) print statistics(parts) for i,p in enumerate(parts): s.update({i : p[1]}) else: del r #send each partition to the proper rank local = all2all(s) del s if rank == 0: print "load_bal time %g" % (h.startsw()-elapse) return local[0]
def detect_over_connected_gc(_cilist): # granule cells new connections msg = {} ggid2ci = {} for _ci in _cilist: ggid = _ci[3] try: msg[ggid2rank(ggid)].append(_ci[3]) except KeyError: msg[ggid2rank(ggid)] = [ _ci[3] ] try: ggid2ci[ggid].append(_ci) except KeyError: ggid2ci[ggid] = [ _ci ] msg = all2all(msg) # check for the over connected msg_remove = {} for rr, ggids in msg.items(): for ggid in ggids: if gc2nconn[ggid] >= params.granule_nmax_spines: try: msg_remove[rr].append(ggid) except KeyError: msg_remove[rr] = [ ggid ] else: gc2nconn[ggid] += 1 msg_remove = all2all(msg_remove) # return good_pair = [] bad_pair = [] for ggids in msg_remove.values(): for ggid in ggids: bad_pair.append(ggid2ci[ggid][0]) del ggid2ci[ggid][0] for _cilist2 in ggid2ci.values(): for ci in _cilist2: good_pair.append(ci) return good_pair, bad_pair
def mk_gconnection_info_part2(model): #transfer the gconnection info to the proper rank and make granule_gids set model.rank_gconnections = all2all(model.rank_gconnections) util.elapsed('rank_gconnections known') model.granule_gids = set([ i[3] for r in model.rank_gconnections for i in model.rank_gconnections[r] ]) util.elapsed('granule gids known on each rank')
def detect_intraglom_conn(cilist, GL_to_GCs): # build message msg = {} for rr in range(nhost): msg[rr] = [] for ci in cilist: if ci: glomid = mgid2glom(ci[0]) #params.cellid2glomid(ci[0]) for rr in glom2ranks( glomid): # ranks to inform are only those > current rank if rr == rank: continue msg[rr].append( (glomid, ci[3])) # information must be exchanged msg = all2all(msg) # exchange the new conn. # merge all connections tocheck = set() for rr, connpair in msg.items(): if rr >= rank: tocheck.update(connpair) # update connectivity info for glomid, ggid in connpair: try: GL_to_GCs[glomid].add(granules.ggid2pos[ggid]) except KeyError: pass # distinguish between well vs already existing good_pair = [] bad_pair = [] for ci in cilist: if ci: if (mgid2glom(ci[0]), ci[3]) in tocheck: bad_pair.append(ci) else: good_pair.append(ci) return good_pair, bad_pair
def init(): data = {} for uid in range(nhost): data.update({ uid:(getmodel().mitrals.keys()) }) data = a2a.all2all(data) mgids = [] for _mgids in data.values(): mgids += _mgids mgids = set(mgids) # initialize source for mgid in getmodel().mitrals.keys(): mpriden = split.mpriden(mgid) if not mpriden: continue rgj = params.ranstream(mgid, params.stream_gap_junction) mpriden.push() secref = h.SectionRef() h.pop_section() h.mk_gj_src(pc, mgid, secref) glomid = mgid2glom(mgid) sistergids = [] # no longer all to all, only a chain if not (ismtufted(mgid) and (mgid - nmi) % nmt == (nmt - 1)): if ismitral(mgid) and mgid % nmxg == (nmxg - 1): sistergids += [glomid * nmt + nmi] else: sistergids += [mgid + 1] if not (ismitral(mgid) and mgid % nmxg == 0): if ismtufted(mgid) and (mgid - nmi) % nmt == 0: sistergids += [(glomid + 1) * nmxg - 1] else: sistergids += [mgid - 1] sistergids = mgids.intersection(range(glomid * nmxg, glomid * nmxg + nmxg) + range(glomid * nmt + nmi, glomid * nmt + nmt + nmi)).difference([ mgid ]) for sistermgid in sistergids: gap = h.Gap(mpriden(0.99)) if ismitral(mgid) and ismitral(sistermgid): gap.g = rgj.uniform(gj_min_g1, gj_max_g1) elif ismtufted(mgid) and ismtufted(sistermgid): gap.g = rgj.uniform(gj_min_g3, gj_max_g3) else: gap.g = rgj.uniform(gj_min_g2, gj_max_g2) getmodel().gj[(mgid, sistermgid)] = gap pc.barrier() # initialize targets for key, gap in getmodel().gj.items(): mgid, sistermgid = key pc.target_var(gap, gap._ref_vgap, sistermgid) util.elapsed('Gap junctions built')
def mk_gconnection_info_part2(model): #transfer the gconnection info to the proper rank and make granule_gids set model.rank_gconnections = all2all(model.rank_gconnections) util.elapsed('rank_gconnections known') model.granule_gids = set([i[3] for r in model.rank_gconnections for i in model.rank_gconnections[r]]) util.elapsed('granule gids known on each rank')
r = gid2rank(ggid) if not model.rank_gconnections.has_key(r): model.rank_gconnections.update({r : []}) model.rank_gconnections[r].append(ci) def mk_gconnection_info_part2(model): #transfer the gconnection info to the proper rank and make granule_gids set model.rank_gconnections = all2all(model.rank_gconnections) util.elapsed('rank_gconnections known') model.granule_gids = set([i[3] for r in model.rank_gconnections for i in model.rank_gconnections[r]]) util.elapsed('granule gids known on each rank') def mk_gconnection_info(model): mk_gconnection_info_part1(model) mk_gconnection_info_part2(model) util.elapsed('mk_gconnection_info (#granules = %d)'%int(pc.allreduce(len(model.granule_gids),1))) if __name__ == '__main__': model = getmodel() mk_mitrals(model) mk_mconnection_info(model) mk_gconnection_info_part1(model) sizes = all2all(model.rank_gconnections, -1) for r in util.serialize(): print rank, " all2all sizes ", sizes if rank == 0: print "determine_connections ", h.startsw()-t_begin
def mk_gconnection_info_part2(model): #transfer the gconnection info to the proper rank and make granule_gids set model.rank_gconnections = all2all(model.rank_gconnections) util.elapsed('rank_gconnections known') model.granule_gids = set([ i[3] for r in model.rank_gconnections for i in model.rank_gconnections[r] ]) util.elapsed('granule gids known on each rank') def mk_gconnection_info(model): mk_gconnection_info_part1(model) mk_gconnection_info_part2(model) util.elapsed('mk_gconnection_info (#granules = %d)' % int(pc.allreduce(len(model.granule_gids), 1))) if __name__ == '__main__': model = getmodel() mk_mitrals(model) mk_mconnection_info(model) mk_gconnection_info_part1(model) sizes = all2all(model.rank_gconnections, -1) for r in util.serialize(): print rank, " all2all sizes ", sizes if rank == 0: print "determine_connections ", h.startsw() - t_begin
def multisplit_distrib(model): enter = h.startsw() cxlist = determine_multisplit_complexity(model) #start over destroy_model(model) # but we still have model.mconnections and model.rank_gconnections # from the round-robin distribution perspective. # we will need to tell the ranks where to distribute that information cxlist = load_bal(cxlist, nhost) #cxlist is the list of (cx,(gid,piece)) we want on this process # the new distribution of mitrals and granules model.gids = set([item[1][0] for item in cxlist]) model.mitral_gids = set([gid for gid in model.gids if gid < params.gid_granule_begin]) model.granule_gids = model.gids - model.mitral_gids # for splitting need gid:[pieceindices] gid2pieces = {} for item in cxlist: gid = item[1][0] piece = item[1][1] if not gid2pieces.has_key(gid): gid2pieces.update({gid:[]}) gid2pieces[gid].append(piece) # get the correct mconnections and gconnections # Round-robin ranks that presently have the connection info for the gids rr = {} for gid in model.gids: r = gid%nhost if not rr.has_key(r): rr.update({r:[]}) rr[r].append(gid); rr = all2all(rr) # rr is now the ranks for where to send the synapse information # all the gids in rr were 'owned' by the round-robin distribution # may wish to revisit so that only synapse info for relevant pieces is # scattered. mc = model.mconnections gc = model.rank_gconnections # construct a ggid2connection dict ggid2connection = {} for r in gc: for ci in gc[r]: ggid = ci[3] if not ggid2connection.has_key(ggid): ggid2connection.update({ggid:[]}) ggid2connection[ggid].append(ci) for r in rr: gids = rr[r] mgci = [] rr[r] = mgci for gid in gids: if mc.has_key(gid): mgci.append(mc[gid]) else: mgci.append(ggid2connection[gid]) mgci = all2all(rr) # mgci contains all the connection info needed by the balanced distribution # create mitrals and granules, split and register and create synapses nmc.dc.mk_mitrals(model) # whole cells nmc.build_granules(model) for gid in gid2pieces: if gid < params.Nmitral: split.splitmitral(gid, model.mitrals[gid], gid2pieces[gid]) pc.multisplit() nmc.register_mitrals(model) nmc.register_granules(model) # build_synapses() ... use mgci to build explicitly model.mgrss = {} for r in mgci: for cil in mgci[r]: for ci in cil: if not model.mgrss.has_key(mgrs.mgrs_gid(ci[0], ci[3], ci[6])): rsyn = mgrs.mk_mgrs(*ci[0:7]) if rsyn: model.mgrss.update({rsyn.md_gid : rsyn}) nmultiple = int(pc.allreduce(mgrs.multiple_cnt(), 1)) if rank == 0: print 'nmultiple = ', nmultiple detectors = h.List("AmpaNmda") util.elapsed('%d ampanmda for reciprocalsynapses constructed'%int(pc.allreduce(detectors.count(),1))) detectors = h.List("FastInhib") util.elapsed('%d fi for reciprocalsynapses constructed'%int(pc.allreduce(detectors.count(),1))) detectors = h.List("ThreshDetect") util.elapsed('%d ThreshDetect for reciprocalsynapses constructed'%int(pc.allreduce(detectors.count(),1))) if rank == 0: print 'multisplit_distrib time ', h.startsw() - enter
def multisplit_distrib(model): enter = h.startsw() cxlist = determine_multisplit_complexity(model) #start over destroy_model(model) # fake cell to solve problem with gap junctions # init_fake_cell() # but we still have model.mconnections and model.rank_gconnections # from the round-robin distribution perspective. # we will need to tell the ranks where to distribute that information cxlist = load_bal( cxlist, nhost) #cxlist is the list of (cx,(gid,piece)) we want on this process # the new distribution of mitrals and granules model.gids = set([item[1][0] for item in cxlist]) model.mitral_gids = set( [gid for gid in model.gids if ismitral(gid) or ismtufted(gid)]) model.granule_gids = set([gid for gid in model.gids if isgranule(gid)]) model.blanes_gids = set([gid for gid in model.gids if isblanes(gid)]) # for splitting need gid:[pieceindices] gid2pieces = {} for item in cxlist: gid = item[1][0] piece = item[1][1] if not gid2pieces.has_key(gid): gid2pieces[gid] = [] gid2pieces[gid].append(piece) # get the correct mconnections and gconnections # Round-robin ranks that presently have the connection info for the gids rr = {} for gid in model.gids: r = gid % nhost if not rr.has_key(r): rr[r] = [] rr[r].append(gid) rr = all2all(rr) # rr is now the ranks for where to send the synapse information # all the gids in rr were 'owned' by the round-robin distribution # may wish to revisit so that only synapse info for relevant pieces is # scattered. mc = model.mconnections gc = model.rank_gconnections # construct a ggid2connection dict ggid2connection = {} for r in gc: for ci in gc[r]: ggid = ci[3] if not ggid2connection.has_key(ggid): ggid2connection[ggid] = [] ggid2connection[ggid].append(ci) for r in rr: gids = rr[r] mgci = [] rr[r] = mgci for gid in gids: if mc.has_key(gid): mgci.append(mc[gid]) elif gidfunc.isgranule(gid): mgci.append(ggid2connection[gid]) mgci = all2all(rr) # mgci contains all the connection info needed by the balanced distribution # create mitrals and granules, split and register and create synapses nmc.dc.mk_mitrals(model) # whole cells nmc.build_granules(model) nmc.build_blanes(model) for gid in gid2pieces: if ismitral(gid) or ismtufted(gid): split.splitmitral(gid, model.mitrals[gid], gid2pieces[gid]) pc.multisplit() nmc.register_mitrals(model) nmc.register_granules(model) nmc.register_blanes(model) # build_synapses() ... use mgci to build explicitly model.mgrss = {} for r in mgci: for cil in mgci[r]: for ci in cil: if not model.mgrss.has_key(mgrs.mgrs_gid(ci[0], ci[3], ci[6])): rsyn = mgrs.mk_mgrs(*ci[0:7]) if rsyn: model.mgrss[rsyn.md_gid] = rsyn nmultiple = int(pc.allreduce(mgrs.multiple_cnt(), 1)) # it is faster if generated again blanes.mk_gl2b_connections() # excitatory for mgid, blanes_gid, w in model.mt2blanes_connections: syn = blanes.mt2blanes(mgid, blanes_gid, w) model.mt2blanes[syn.gid] = syn blanes.mk_b2g_connections() # inhibitory synapses from blanes to gc for ggid, blanes_gid, w in model.blanes2gc_connections: syn = blanes.blanes2granule(blanes_gid, ggid, w) model.blanes2gc[syn.gid] = syn if rank == 0: print 'nmultiple = ', nmultiple detectors = h.List("AmpaNmda") util.elapsed('%d ampanmda for reciprocalsynapses constructed' % int(pc.allreduce(detectors.count(), 1))) detectors = h.List("FastInhib") util.elapsed('%d fi for reciprocalsynapses constructed' % int(pc.allreduce(detectors.count(), 1))) detectors = h.List("ThreshDetect") util.elapsed('%d ThreshDetect for reciprocalsynapses constructed' % int(pc.allreduce(detectors.count(), 1))) util.elapsed('%d mt to bc' % int(pc.allreduce(len(model.mt2blanes), 1))) util.elapsed('%d bc to gc' % int(pc.allreduce(len(model.blanes2gc), 1))) if rank == 0: print 'multisplit_distrib time ', h.startsw() - enter
def whole_cell_distrib(model): enter = h.startsw() cx = determine_complexity(model) #start over destroy_model(model) # but we still have model.mconnections and model.rank_gconnections # from the round-robin distribution perspective. # we will need to tell the ranks where to distribute that information cx = load_bal(cx, nhost) #cx is the list of (cx,gid) we want on this process # the new distribution of mitrals and granules model.gids = set([item[1] for item in cx]) model.mitral_gids = set( [gid for gid in model.gids if gid < params.gid_granule_begin]) model.granule_gids = model.gids - model.mitral_gids # get the correct mconnections and gconnections # Round-robin ranks that presently have the connection info for the gids rr = {} for gid in model.gids: r = gid % nhost if not rr.has_key(r): rr[r] = [] rr[r].append(gid) rr = all2all(rr) # rr is now the ranks for where to send the synapse information # all the gids in rr were 'owned' by the round-robin distribution mc = model.mconnections gc = model.rank_gconnections # construct a ggid2connection dict ggid2connection = {} for r in gc: for ci in gc[r]: ggid = ci[3] if not ggid2connection.has_key(ggid): ggid2connection[ggid] = [] ggid2connection[ggid].append(ci) for r in rr: gids = rr[r] mgci = [] rr[r] = mgci for gid in gids: if mc.has_key(gid): mgci.append(mc[gid]) else: mgci.append(ggid2connection[gid]) mgci = all2all(rr) # mgci contains all the connection info needed by the balanced distribution # create mitrals and granules and register and create synapses nmc.dc.mk_mitrals(model) nmc.register_mitrals(model) nmc.build_granules(model) nmc.register_granules(model) # build_synapses() ... use mgci to build explicitly model.mgrss = {} for r in mgci: for cil in mgci[r]: for ci in cil: if not model.mgrss.has_key(mgrs.mgrs_gid(ci[0], ci[3], ci[6])): rsyn = mgrs.mk_mgrs(*ci[0:7]) if rsyn: model.mgrss[rsyn.md_gid] = rsyn nmultiple = int(pc.allreduce(mgrs.multiple_cnt(), 1)) if rank == 0: print 'nmultiple = ', nmultiple detectors = h.List("ThreshDetect") util.elapsed('%d ThreshDetect for reciprocalsynapses constructed' % int(pc.allreduce(detectors.count(), 1))) if rank == 0: print 'whole_cell_distrib time ', h.startsw() - enter
def whole_cell_distrib(model): enter = h.startsw() cx = determine_complexity(model) # start over destroy_model(model) # but we still have model.mconnections and model.rank_gconnections # from the round-robin distribution perspective. # we will need to tell the ranks where to distribute that information cx = load_bal(cx, nhost) # cx is the list of (cx,gid) we want on this process # the new distribution of mitrals and granules model.gids = set([item[1] for item in cx]) model.mitral_gids = set([gid for gid in model.gids if gid < params.gid_granule_begin]) model.granule_gids = model.gids - model.mitral_gids # get the correct mconnections and gconnections # Round-robin ranks that presently have the connection info for the gids rr = {} for gid in model.gids: r = gid % nhost if not rr.has_key(r): rr.update({r: []}) rr[r].append(gid) rr = all2all(rr) # rr is now the ranks for where to send the synapse information # all the gids in rr were 'owned' by the round-robin distribution mc = model.mconnections gc = model.rank_gconnections # construct a ggid2connection dict ggid2connection = {} for r in gc: for ci in gc[r]: ggid = ci[3] if not ggid2connection.has_key(ggid): ggid2connection.update({ggid: []}) ggid2connection[ggid].append(ci) for r in rr: gids = rr[r] mgci = [] rr[r] = mgci for gid in gids: if mc.has_key(gid): mgci.append(mc[gid]) else: mgci.append(ggid2connection[gid]) mgci = all2all(rr) # mgci contains all the connection info needed by the balanced distribution # create mitrals and granules and register and create synapses nmc.dc.mk_mitrals(model) nmc.register_mitrals(model) nmc.build_granules(model) nmc.register_granules(model) # build_synapses() ... use mgci to build explicitly model.mgrss = {} for r in mgci: for cil in mgci[r]: for ci in cil: if not model.mgrss.has_key(mgrs.mgrs_gid(ci[0], ci[3], ci[6])): rsyn = mgrs.mk_mgrs(*ci[0:7]) if rsyn: model.mgrss.update({rsyn.md_gid: rsyn}) nmultiple = int(pc.allreduce(mgrs.multiple_cnt(), 1)) if rank == 0: print "nmultiple = ", nmultiple detectors = h.List("ThreshDetect") util.elapsed("%d ThreshDetect for reciprocalsynapses constructed" % int(pc.allreduce(detectors.count(), 1))) if rank == 0: print "whole_cell_distrib time ", h.startsw() - enter
def multisplit_distrib(model): enter = h.startsw() cxlist = determine_multisplit_complexity(model) #start over destroy_model(model) # but we still have model.mconnections and model.rank_gconnections # from the round-robin distribution perspective. # we will need to tell the ranks where to distribute that information cxlist = load_bal( cxlist, nhost) #cxlist is the list of (cx,(gid,piece)) we want on this process # the new distribution of mitrals and granules model.gids = set([item[1][0] for item in cxlist]) model.mitral_gids = set( [gid for gid in model.gids if gid < params.gid_granule_begin]) model.granule_gids = model.gids - model.mitral_gids # for splitting need gid:[pieceindices] gid2pieces = {} for item in cxlist: gid = item[1][0] piece = item[1][1] if not gid2pieces.has_key(gid): gid2pieces.update({gid: []}) gid2pieces[gid].append(piece) # get the correct mconnections and gconnections # Round-robin ranks that presently have the connection info for the gids rr = {} for gid in model.gids: r = gid % nhost if not rr.has_key(r): rr.update({r: []}) rr[r].append(gid) rr = all2all(rr) # rr is now the ranks for where to send the synapse information # all the gids in rr were 'owned' by the round-robin distribution # may wish to revisit so that only synapse info for relevant pieces is # scattered. mc = model.mconnections gc = model.rank_gconnections # construct a ggid2connection dict ggid2connection = {} for r in gc: for ci in gc[r]: ggid = ci[3] if not ggid2connection.has_key(ggid): ggid2connection.update({ggid: []}) ggid2connection[ggid].append(ci) for r in rr: gids = rr[r] mgci = [] rr[r] = mgci for gid in gids: if mc.has_key(gid): mgci.append(mc[gid]) else: mgci.append(ggid2connection[gid]) mgci = all2all(rr) # mgci contains all the connection info needed by the balanced distribution # create mitrals and granules, split and register and create synapses nmc.dc.mk_mitrals(model) # whole cells nmc.build_granules(model) for gid in gid2pieces: if gid < params.Nmitral: split.splitmitral(gid, model.mitrals[gid], gid2pieces[gid]) pc.multisplit() nmc.register_mitrals(model) nmc.register_granules(model) # build_synapses() ... use mgci to build explicitly model.mgrss = {} for r in mgci: for cil in mgci[r]: for ci in cil: if not model.mgrss.has_key(mgrs.mgrs_gid(ci[0], ci[3], ci[6])): rsyn = mgrs.mk_mgrs(*ci[0:7]) if rsyn: model.mgrss.update({rsyn.md_gid: rsyn}) nmultiple = int(pc.allreduce(mgrs.multiple_cnt(), 1)) if rank == 0: print 'nmultiple = ', nmultiple detectors = h.List("AmpaNmda") util.elapsed('%d ampanmda for reciprocalsynapses constructed' % int(pc.allreduce(detectors.count(), 1))) detectors = h.List("FastInhib") util.elapsed('%d fi for reciprocalsynapses constructed' % int(pc.allreduce(detectors.count(), 1))) detectors = h.List("ThreshDetect") util.elapsed('%d ThreshDetect for reciprocalsynapses constructed' % int(pc.allreduce(detectors.count(), 1))) if rank == 0: print 'multisplit_distrib time ', h.startsw() - enter