[ofa-general] Re: [PATCHv2] opensm/osm_mesh.c: Reorder switches for lash
Hal Rosenstock
hal.rosenstock at gmail.com
Wed Aug 5 05:59:16 PDT 2009
Hi Sasha,
On Wed, Aug 5, 2009 at 5:32 AM, Sasha Khapyorsky <sashak at voltaire.com>wrote:
> Hi Hal,
>
> On 11:16 Wed 22 Jul , Hal Rosenstock wrote:
> >
> > +/*
> > + * sort_switches - reorder switch array
> > + */
> > +static void sort_switches(lash_t *p_lash, mesh_t *mesh)
> > +{
> > + int i, j;
> > + int num_switches = p_lash->num_switches;
> > + sort_ctx_t sort_ctx;
> > + comp_t *index;
> > + int *reverse;
> > + switch_t *s;
> > + switch_t **switches;
> > +
> > + index = malloc(num_switches * sizeof(comp_t));
> > + reverse = malloc(num_switches * sizeof(int));
> > + switches = malloc(num_switches * sizeof(switch_t *));
> > + if (!index || !reverse || !switches) {
> > + OSM_LOG(&p_lash->p_osm->log, OSM_LOG_ERROR,
> > + "Failed memory allocation - switches not
> sorted!\n");
> > + goto Exit;
> > + }
> > +
> > + sort_ctx.mesh = mesh;
> > + sort_ctx.p_lash = p_lash;
> > +
> > + for (i = 0; i < num_switches; i++) {
> > + index[i].index = i;
> > + index[i].ctx = &sort_ctx;
> > + }
> > +
> > + qsort(index, num_switches, sizeof(comp_t), compare_switch);
> > +
> > + for (i = 0; i < num_switches; i++)
> > + reverse[index[i].index] = i;
> > +
> > + for (i = 0; i < num_switches; i++) {
> > + s = p_lash->switches[index[i].index];
> > + switches[i] = s;
> > + s->id = i;
> > + for (j = 0; j < s->node->num_links; j++)
> > + s->node->links[j]->switch_id =
> > + reverse[s->node->links[j]->switch_id];
>
> Isn't it the same as:
>
> s->node->links[j]->switch_id =
> index[s->node->links[j]->switch_id].index;
No.
-- Hal
>
> (and then reverse array is obsolete)?
>
> Sasha
>
> > + }
> > +
> > + for (i = 0; i < num_switches; i++)
> > + p_lash->switches[i] = switches[i];
> > +
> > +Exit:
> > + if (switches)
> > + free(switches);
> > + if (index)
> > + free(index);
> > + if (reverse)
> > + free(reverse);
> > +}
> > +
> > +/*
> > * osm_mesh_delete - free per mesh resources
> > */
> > static void mesh_delete(mesh_t *mesh)
> > @@ -1470,6 +1561,8 @@ int osm_do_mesh_analysis(lash_t *p_lash)
> > if (reorder_links(p_lash, mesh))
> > goto err;
> >
> > + sort_switches(p_lash, mesh);
> > +
> > p = buf;
> > p += sprintf(p, "found ");
> > for (i = 0; i < mesh->dimension; i++)
> >
> _______________________________________________
> general mailing list
> general at lists.openfabrics.org
> http://lists.openfabrics.org/cgi-bin/mailman/listinfo/general
>
> To unsubscribe, please visit
> http://openib.org/mailman/listinfo/openib-general
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openfabrics.org/pipermail/general/attachments/20090805/50fc859e/attachment.html>
More information about the general
mailing list