[ofa-general] Re: [PATCHv2] opensm/osm_mesh.c: Reorder switches for lash
Sasha Khapyorsky
sashak at voltaire.com
Wed Aug 5 02:32:28 PDT 2009
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;
(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++)
>
More information about the general
mailing list