// ========== Copyright Header Begin ==========================================
// OpenSPARC T2 Processor File: mpsort.C
// Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
// The above named program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License version 2 as published by the Free Software Foundation.
// The above named program is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
// You should have received a copy of the GNU General Public
// License along with this work; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
// ========== Copyright Header End ============================================
int main(int argc, char* argv[]) {
rstf_unionT* multirst = NULL;
CpuCount* cpucount = NULL;
int index[NCPUS] = { 0 };
rstf_cpuT rstcpu = { CPU_T, 0, 0, 0, 0, 0 };
int i, j, count, nrecs, cpucountrecs;
// Quick check of command line.
fprintf(stderr, "mpsort rstfile\n");
infp = fopen(argv[1], "r");
multirst = (rstf_unionT*) calloc(NRECS, sizeof(rstf_unionT));
unirst = (RstSplit*) calloc(NCPUS, sizeof(RstSplit));
for (i = 0; i < NCPUS; i++) {
unirst[i].rst = (rstf_unionT*) calloc(NRECS, sizeof(rstf_unionT));
cpucount = (CpuCount*) calloc(NRECS, sizeof(CpuCount));
nrecs = fread(multirst, sizeof(rstf_unionT), NRECS, infp);
for (i = 0; i < NCPUS; i++) {
cpucountrecs = sortRstTrace(multirst, nrecs, unirst, cpucount, &curcpu);
for (i = 0; i < cpucountrecs; i++) {
curcpu = cpucount[i].cpu;
count = cpucount[i].count;
memcpy(&multirst[j], &rstcpu, sizeof(rstf_unionT));
memcpy(&multirst[j], &unirst[curcpu].rst[index[curcpu]],
count * sizeof(rstf_unionT));
fwrite(multirst, sizeof(rstf_unionT), nrecs, outfp);
nrecs = fread(multirst, sizeof(rstf_unionT), NRECS, infp);
for (i = 0; i < NCPUS; i++) {