Count all active WPARs from the Global WPAR and retrieve per-WPAR data

The following program is an example of a count of all active WPARS from the global WPAR and also retrieves per-WPAR data.

main ()
{
        pm_prog_t prog;
        pm_wpar_ctx_info_t *wp_list;
        int nwpars;

        /* set programming */
        ...
        prog.mode.b.wpar_all = 1;  /* collect per-WPAR data */
        pm_set_program(&prog);

        pm_start();
        ... workload ...
        pm_stop();

        /* retrieve the number of WPARs that were active during the counting */
        nwpars = 0;
        pm_get_wplist(NULL, NULL, &nwpars);
        /* allocate an array large enough to retrieve WPARs contexts */
        wp_list = malloc(nwpars * sizeof (pm_wpar_ctx_info_t));
        /* retrieve WPARs contexts */
        pm_get_wplist(NULL, wp_list, &nwpars);

        /* retrieve and print data for each WPAR */
        for (i = 0; i < nwpars; i++) {
            printf("WPAR: %s (CID=%d)\n", wp_list[i].name, wp_list[i].cid);
            pm_get_data_wp(wp_list[i].hwpar, &data);
        }

        free(wp_list);

        pm_delete_program();
}