Example #1
0
int main(int argc, char **argv) {

	CALLGRIND_STOP_INSTRUMENTATION;
	CALLGRIND_ZERO_STATS;

	QCoreApplication a(argc, argv);

	QFile f((argc >= 2) ? argv[1] : "wb_male.wav");
	if (! f.open(QIODevice::ReadOnly)) {
		qFatal("Failed to open file!");
	}
	f.seek(36 + 8);

	QFile o("output.raw");
	if (!(RUNNING_ON_VALGRIND))
		if (! o.open(QIODevice::WriteOnly))
			qFatal("Failed to open output!");

	QFile vf((argc >= 3) ? argv[2] : "verify.raw");
	if (! vf.open(QIODevice::ReadOnly)) {
		qWarning("Failed to open validate file!");
	}

	QDataStream out(&o);
	QDataStream verify(&vf);

	const int iFrameSize = 320;

	QVector<QByteArray> v;
	while (1) {
		QByteArray qba = f.read(iFrameSize * 2);
		if (qba.size() != iFrameSize * 2)
			break;
		v.append(qba);
	}

	int nframes = v.size();


	qWarning("Ready to process %d frames of %d samples", nframes, iFrameSize);

	QVector<short *> qvInShort;
	QVector<float *> qvIn;
	QVector<float *> qvDirect;
	QVector<float *> qvInterpolate;
	QVector<float *> qvInterpolateMC;
	QVector<short *> qvInterpolateShort;
	QVector<float *> qv8;
	QVector<float *> qv96;

	const float sfraq1 = tfreq1 / 16000.0f;
	float fOutSize1 = iFrameSize * sfraq1;
	int iOutSize1 = lroundf(fOutSize1);

	const float sfraq2 = tfreq2 / 16000.0f;
	float fOutSize2 = iFrameSize * sfraq2;
	int iOutSize2 = lroundf(fOutSize2);

	int iOutSize8 = iFrameSize / 2;
	int iOutSize96 = iFrameSize * 6;

	if (RUNNING_ON_VALGRIND)
		nframes = qMin(nframes, 10);

	QVector<float> fInput(nframes * iFrameSize);
	QVector<float> fDirect(nframes * iOutSize1);
	QVector<float> fInterpolate(nframes * iOutSize2);
	QVector<float> fInterpolateMC(nframes * iOutSize2);
	QVector<short> sInterpolate(nframes * iOutSize2);
	QVector<float> f96(nframes * iOutSize96);
	QVector<float> f8(nframes *iOutSize8);

	for (int i=0;i<nframes;i++) {
		short *s = reinterpret_cast<short *>(v[i].data());
		float *f = fInput.data() + i * iFrameSize;

		for (int j=0;j<iFrameSize;j++)
			f[j]=s[j]+20;

		qvInShort.append(s);
		qvIn.append(f);
		qvDirect.append(fDirect.data() + i * iOutSize1);
		qvInterpolate.append(fInterpolate.data() + i * iOutSize2);
		qvInterpolateMC.append(fInterpolateMC.data() + i * iOutSize2);
		qvInterpolateShort.append(sInterpolate.data() + i * iOutSize2);
		qv8.append(f8.data() + i * iOutSize8);
		qv96.append(f96.data() + i * iOutSize96);
	}

	int err;
	SpeexResamplerState *srs1 = speex_resampler_init(1, 16000, lroundf(tfreq1), qual, &err);
	SpeexResamplerState *srs2 = speex_resampler_init(1, 16000, lroundf(tfreq2), qual, &err);
	SpeexResamplerState *srs2i = speex_resampler_init(1, 16000, lroundf(tfreq2), qual, &err);
	SpeexResamplerState *srss = speex_resampler_init(3, 16000, lroundf(tfreq2), qual, &err);

	SpeexResamplerState *srsto96 = speex_resampler_init(1, 16000, 96000, 5, &err);
	SpeexResamplerState *srs8to96 = speex_resampler_init(1, 8000, 96000, qual, &err);
	SpeexResamplerState *srs96to8 = speex_resampler_init(1, 96000, 8000, qual, &err);


#ifdef Q_OS_WIN
	if (!SetPriorityClass(GetCurrentProcess(),REALTIME_PRIORITY_CLASS))
		qWarning("Application: Failed to set priority!");
#endif

	int len;
	spx_uint32_t inlen;
	spx_uint32_t outlen;

	Timer t;
	quint64 e;

	if (! RUNNING_ON_VALGRIND) {
#ifndef Q_OS_WIN
		struct sched_param sp;
		sp.sched_priority = sched_get_priority_max(SCHED_FIFO);

		cpu_set_t cpuset;
		CPU_ZERO(&cpuset);
		CPU_SET(1, &cpuset);

		if (sched_setscheduler(getpid(), SCHED_FIFO, &sp) != 0)
			qWarning("No realtime.");
		if (mlockall(MCL_CURRENT | MCL_FUTURE) != 0)
			qWarning("No mlock.");
		if (sched_setaffinity(0, sizeof(cpuset), &cpuset) != 0)
			qWarning("No affinity");

		sched_yield();
#endif

		for (int i=0;i<nframes;++i) {
			inlen = iFrameSize;
			outlen = iOutSize96;
			speex_resampler_process_float(srsto96, 0, qvIn[i], &inlen, qv96[i], &outlen);
		}

		QVector<unsigned long long> qvTimes;
		QPair<unsigned long long, unsigned long long> ci;

		for (int j=0;j<loops;j++) {
			t.restart();
			for (int i=0;i<nframes;i++) {
				inlen = iFrameSize;
				outlen = iOutSize1;
				speex_resampler_process_float(srs1, 0, qvIn[i], &inlen, qvDirect[i], &outlen);
			}
			e = t.elapsed();
			qvTimes.append(e);
		}
		ci = confint(qvTimes);
		qWarning("Direct:      %8llu +/- %3llu usec (%d)", ci.first, ci.second, qvTimes.count(), qvTimes.count());

		qvTimes.clear();

		for (int j=0;j<loops;j++) {
			t.restart();
			for (int i=0;i<nframes;i++) {
				inlen = iFrameSize;
				outlen = iOutSize2;
				speex_resampler_process_float(srs2, 0, qvIn[i], &inlen, qvInterpolate[i], &outlen);
			}
			e = t.elapsed();
			qvTimes.append(e);
		}
		ci = confint(qvTimes);
		qWarning("Interpolate: %8llu +/- %3llu usec (%d)", ci.first, ci.second, qvTimes.count());

		qvTimes.clear();
		for (int j=0;j<loops;j++) {
			t.restart();
			for (int i=0;i<nframes;i++) {
				inlen = iOutSize96;
				outlen = iOutSize8;
				speex_resampler_process_float(srs96to8, 0, qv96[i], &inlen, qv8[i], &outlen);
			}
			e = t.elapsed();
			qvTimes.append(e);
		}
		ci = confint(qvTimes);
		qWarning("96 => 8:     %8llu +/- %3llu usec (%d)", ci.first, ci.second, qvTimes.count());

		qvTimes.clear();
		t.restart();
		for (int j=0;j<loops;j++) {
			t.restart();
			for (int i=0;i<nframes;i++) {
				inlen = iOutSize8;
				outlen = iOutSize96;
				speex_resampler_process_float(srs8to96, 0, qv8[i], &inlen, qv96[i], &outlen);
			}
			e = t.elapsed();
			qvTimes.append(e);
		}
		ci = confint(qvTimes);
		qWarning("8 => 96:     %8llu +/- %3llu usec (%d)", ci.first, ci.second, qvTimes.count());

		speex_resampler_reset_mem(srs1);
		speex_resampler_reset_mem(srs2);
	}

	t.restart();
	CALLGRIND_START_INSTRUMENTATION;

	for (int i=0;i<nframes;i++) {
		inlen = iFrameSize;
		outlen = iOutSize1;
		speex_resampler_process_float(srs1, 0, qvIn[i], &inlen, qvDirect[i], &outlen);

		inlen = iFrameSize;
		outlen = iOutSize2;
		speex_resampler_process_float(srs2, 0, qvIn[i], &inlen, qvInterpolate[i], &outlen);

		inlen = iFrameSize;
		outlen = iOutSize2;
		speex_resampler_process_int(srs2i, 0, qvInShort[i], &inlen, qvInterpolateShort[i], &outlen);

		inlen = iFrameSize / 4;
		outlen = iOutSize2 / 4;
		speex_resampler_process_interleaved_float(srss, qvIn[i], &inlen, qvInterpolateMC[i], &outlen);
	}
	e = t.elapsed();

#ifdef Q_OS_WIN
	if (!SetPriorityClass(GetCurrentProcess(),NORMAL_PRIORITY_CLASS))
		qWarning("Application: Failed to reset priority!");
#endif

	const int freq[10] = { 22050, 32000, 11025, 16000, 48000, 41000, 8000, 96000, 11025, 1600 };

	QVector<float> fMagic;

	for (int f=0;f<10;f++) {
		float fbuff[32767];
		speex_resampler_set_rate(srs1, 16000, freq[f]);
		for (int q = 0;q < 10;q++) {
			speex_resampler_set_quality(srs1, (3*q) % 7);
			inlen = iFrameSize;
			outlen = 32767;
			speex_resampler_process_float(srs1, 0, qvIn[(f*10+q) % nframes], &inlen, fbuff, &outlen);
			for (int j=0;j<outlen;j++)
				fMagic.append(fbuff[j]);
		}
		inlen = iFrameSize;
		outlen = 32767;
		speex_resampler_process_float(srs1, 0, NULL, &inlen, fbuff, &outlen);
		for (int j=0;j<outlen;j++)
			fMagic.append(fbuff[j]);
	}

	// Cropped magic test
	for (int f=0;f<10;f++) {
		float fbuff[32767];
		speex_resampler_set_rate(srs1, 16000, freq[f]);
		for (int q = 0;q < 10;q++) {
			speex_resampler_set_quality(srs1, (3*q) % 7);
			inlen = iFrameSize;
			outlen = 16;
			speex_resampler_process_float(srs1, 0, qvIn[(f*10+q) % nframes], &inlen, fbuff, &outlen);
			for (int j=0;j<outlen;j++)
				fMagic.append(fbuff[j]);
		}
		inlen = iFrameSize;
		outlen = 32767;
		speex_resampler_process_float(srs1, 0, NULL, &inlen, fbuff, &outlen);
		for (int j=0;j<outlen;j++)
			fMagic.append(fbuff[j]);
	}


	CALLGRIND_STOP_INSTRUMENTATION;

	qWarning("Used %llu usec", e);
	qWarning("%.2f times realtime", (20000ULL * nframes) / (e * 1.0));

	if (! RUNNING_ON_VALGRIND) {
		QVector<float> vDirect;
		QVector<float> vInterpolate;
		QVector<short> vsInterpolate;
		QVector<float> vMagic;
		QVector<float> vInterpolateMC;

		out << fDirect << fInterpolate << sInterpolate << fMagic << fInterpolateMC;

		if (vf.isOpen()) {
			verify >> vDirect >> vInterpolate >> vsInterpolate >> vMagic >> vInterpolateMC;

			double rmsd = veccomp(vDirect, fDirect, "SRS1");
			double rmsi = veccomp(vInterpolate, fInterpolate, "SRS2");
			veccomp(vsInterpolate, sInterpolate, "SRS2i");
			veccomp(vMagic, fMagic, "Magic");
			veccomp(vInterpolateMC, fInterpolateMC, "MC");
			qWarning("Direct: %g", rmsd);
			qWarning("Interp: %g", rmsi);
		} else {
Example #2
0
int main()
{
    FILE *file;
    char filename[32];

    // output files names
    char *fx = "data/x.dat";
    char *fx1 = "data/x1.dat";
    char *fx2 = "data/x2.dat";
    char *fxclet = "data/xclet.dat";
    char *fx1clet = "data/x1clet.dat";
    char *fx2clet = "data/x2clet.dat";
    char *fxcloud = "data/xcloud.dat";
    char *fx1cloud = "data/x1cloud.dat";
    char *fx2cloud = "data/x2cloud.dat";

    // output file descriptors
    int fd_x;
    int fd_x1;
    int fd_x2;
    int fd_xclet;
    int fd_x1clet;
    int fd_x2clet;
    int fd_xcloud;
    int fd_x1cloud;
    int fd_x2cloud;


    // temporary service variables
    double x1_clet;
    double x2_clet;
    double x1_cloud;
    double x2_cloud;

    long unsigned int i;
    unsigned int r;
    unsigned int max_n;             // number of jobs to process
    unsigned long b;

    // throughput batch arrays
    double x[K];
    double x1[K];
    double x2[K];
    double xclet[K];
    double x1clet[K];
    double x2clet[K];
    double xcloud[K];
    double x1cloud[K];
    double x2cloud[K];

    struct confint_t c;

    // opex output files
    fd_x = open(fx, O_WRONLY | O_CREAT, 00744);
    fd_x1 = open(fx1, O_WRONLY | O_CREAT, 00744);
    fd_x2 = open(fx2, O_WRONLY | O_CREAT, 00744);
    fd_xclet = open(fxclet, O_WRONLY | O_CREAT, 00744);
    fd_x1clet = open(fx1clet, O_WRONLY | O_CREAT, 00744);
    fd_x2clet = open(fx2clet, O_WRONLY | O_CREAT, 00744);
    fd_xcloud = open(fxcloud, O_WRONLY | O_CREAT, 00744);
    fd_x1cloud = open(fx1cloud, O_WRONLY | O_CREAT, 00744);
    fd_x2cloud = open(fx2cloud, O_WRONLY | O_CREAT, 00744);
    if (fd_x == -1 || fd_x1 == -1 || fd_x2 == -1 || 
        fd_xclet == -1 || fd_x1clet == -1 || fd_x2clet == -1 ||
        fd_xcloud == -1 || fd_x1cloud == -1 || fd_x2cloud == -1)
        handle_error("opening an output file");

    for (r = 0; r < R; r++) {

        // init structures
        memset(x, 0, K * sizeof(double));
        memset(x1, 0, K * sizeof(double));
        memset(x2, 0, K * sizeof(double));
        memset(xclet, 0, K * sizeof(double));
        memset(x1clet, 0, K * sizeof(double));
        memset(x2clet, 0, K * sizeof(double));
        memset(xcloud, 0, K * sizeof(double));
        memset(x1cloud, 0, K * sizeof(double));
        memset(x2cloud, 0, K * sizeof(double));

        // open the file
        sprintf(filename, "data/throughput_%d.dat", r);
        file = fopen(filename, "r");
        if (!file)
            handle_error("opening data file");

        // get batch size
        b = N_JOBS / K;
        max_n = b * K;

        // get data
        for (i = 0; i < max_n; i++) {
            if (fscanf(file, "%lf %lf %lf %lf\n",
                &x1_clet, &x2_clet, &x1_cloud, &x2_cloud) == EOF)
                handle_error("file too short"); 

            x[i / b] += x1_clet + x2_clet + x1_cloud + x2_cloud;
            x1[i / b] += x1_clet + x1_cloud;
            x2[i / b] += x2_clet + x2_cloud;
            xclet[i / b] += x1_clet + x2_clet;
            x1clet[i / b] += x1_clet;
            x2clet[i / b] += x2_clet;
            xcloud[i / b] += x1_cloud + x2_cloud;
            x1cloud[i / b] += x1_cloud;
            x2cloud[i / b] += x2_cloud;
        }

        // close the input file
        if (fclose(file) == EOF)
            handle_error("closing data file");

        // compute batch means
        for (i = 0; i < K; i++) {
            x[i] /= b;
            x1[i] /= b;
            x2[i] /= b;
            xclet[i] /= b;
            x1clet[i] /= b;
            x2clet[i] /= b;
            xcloud[i] /= b;
            x1cloud[i] /= b;
            x2cloud[i] /= b;
        }

        // print results 
        printf("\n  Replication %d results\n", r);

        c = confint(x, K, ALPHA); 
        dprintf(fd_x, "%f %f\n", c.mean, c.w);
        printf("system throughput ......... = %lf  +/- %lf\n", c.mean, c.w);

        c = confint(x1, K, ALPHA); 
        dprintf(fd_x1, "%f %f\n", c.mean, c.w);
        printf("class 1 throughput ........ = %lf  +/- %lf\n", c.mean, c.w);

        c = confint(x2, K, ALPHA); 
        dprintf(fd_x2, "%f %f\n", c.mean, c.w);
        printf("class 2 throughput ........ = %lf  +/- %lf\n", c.mean, c.w);

        c = confint(xclet, K, ALPHA); 
        dprintf(fd_xclet, "%f %f\n", c.mean, c.w);
        printf("cloudlet throughput ....... = %lf  +/- %lf\n", c.mean, c.w);

        c = confint(x1clet, K, ALPHA); 
        dprintf(fd_x1clet, "%f %f\n", c.mean, c.w);
        printf("class 1 cloudlet throughput = %lf  +/- %lf\n", c.mean, c.w);

        c = confint(x2clet, K, ALPHA); 
        dprintf(fd_x2clet, "%f %f\n", c.mean, c.w);
        printf("class 2 cloudlet throughput = %lf  +/- %lf\n", c.mean, c.w);

        c = confint(xcloud, K, ALPHA); 
        dprintf(fd_xcloud, "%f %f\n", c.mean, c.w);
        printf("cloud throughput .......... = %lf  +/- %lf\n", c.mean, c.w);
        
        c = confint(x1cloud, K, ALPHA); 
        dprintf(fd_x1cloud, "%f %f\n", c.mean, c.w);
        printf("class 1 cloud throughput .. = %lf  +/- %lf\n", c.mean, c.w);

        c = confint(x2cloud, K, ALPHA); 
        dprintf(fd_x2cloud, "%f %f\n", c.mean, c.w);
        printf("class 2 cloud throughput .. = %lf  +/- %lf\n", c.mean, c.w);
    }

    // close output file
    if (close(fd_x) == -1)
        handle_error("closing output file");
    if (close(fd_x1) == -1)
        handle_error("closing output file");
    if (close(fd_x2) == -1)
        handle_error("closing output file");
    if (close(fd_xclet) == -1)
        handle_error("closing output file");
    if (close(fd_x1clet) == -1)
        handle_error("closing output file");
    if (close(fd_x2clet) == -1)
        handle_error("closing output file");
    if (close(fd_xcloud) == -1)
        handle_error("closing output file");
    if (close(fd_x1cloud) == -1)
        handle_error("closing output file");
    if (close(fd_x2cloud) == -1)
        handle_error("closing output file");

    return EXIT_SUCCESS;
}
Example #3
0
int main()
{
    FILE *file;
    char filename[32];

    // output file names
    char *fs = "data/s.dat";
    char *fs1 = "data/s1.dat";
    char *fs2 = "data/s2.dat";
    char *fsclet = "data/sclet.dat";
    char *fs1clet = "data/s1clet.dat";
    char *fs2clet = "data/s2clet.dat";
    char *fscloud = "data/scloud.dat";
    char *fs1cloud = "data/s1cloud.dat";
    char *fs2cloud = "data/s2cloud.dat";
    char *fsintr = "data/sintr.dat";

    // output file descriptors
    int fd_s;
    int fd_s1;
    int fd_s2;
    int fd_sclet;
    int fd_s1clet;
    int fd_s2clet;
    int fd_scloud;
    int fd_s1cloud;
    int fd_s2cloud;
    int fd_sintr;

    // temporary service variables
    long unsigned int id;
    double s1_clet;
    double s2_clet;
    double s1_cloud;
    double s2_cloud;
    double setup;

    // completions
    unsigned long c1_clet;
    unsigned long c2_clet;
    unsigned long c1_cloud;
    unsigned long c2_cloud;
    unsigned long c_setup;

    // counters
    unsigned long n1;
    unsigned long n2;
    unsigned long n1_clet;
    unsigned long n2_clet;
    unsigned long n1_cloud;
    unsigned long n2_cloud;
    unsigned long n_intr;
    
    // batch sizes 
    unsigned long b;
    unsigned long b1;
    unsigned long b2;
    unsigned long b_clet;
    unsigned long b1_clet;
    unsigned long b2_clet;
    unsigned long b_cloud;
    unsigned long b1_cloud;
    unsigned long b2_cloud;
    unsigned long b_intr;

    long unsigned int i;
    unsigned int r;

    // service batch arrays
    double s[K];
    double s1[K];
    double s2[K];
    double sclet[K];
    double s1clet[K];
    double s2clet[K];
    double scloud[K];
    double s1cloud[K];
    double s2cloud[K];
    double sintr[K];

    struct confint_t c;

    // open output files
    fd_s = open(fs, O_WRONLY | O_CREAT, 00744);
    fd_s1 = open(fs1, O_WRONLY | O_CREAT, 00744);
    fd_s2 = open(fs2, O_WRONLY | O_CREAT, 00744);
    fd_sclet = open(fsclet, O_WRONLY | O_CREAT, 00744);
    fd_s1clet = open(fs1clet, O_WRONLY | O_CREAT, 00744);
    fd_s2clet = open(fs2clet, O_WRONLY | O_CREAT, 00744);
    fd_scloud = open(fscloud, O_WRONLY | O_CREAT, 00744);
    fd_s1cloud = open(fs1cloud, O_WRONLY | O_CREAT, 00744);
    fd_s2cloud = open(fs2cloud, O_WRONLY | O_CREAT, 00744);
    fd_sintr = open(fsintr, O_WRONLY | O_CREAT, 00744);
    if (fd_sintr == -1 || fd_s == -1 || fd_s1 == -1 || fd_s2 == -1 || 
        fd_sclet == -1 || fd_s1clet == -1 || fd_s2clet == -1 ||
        fd_scloud == -1 || fd_s1cloud == -1 || fd_s2cloud == -1)
        handle_error("opening an output file");

    for (r = 0; r < R; r++) {

        // init variables 
        memset(s, 0, K * sizeof(double));
        memset(s1, 0, K * sizeof(double));
        memset(s2, 0, K * sizeof(double));
        memset(sclet, 0, K * sizeof(double));
        memset(s1clet, 0, K * sizeof(double));
        memset(s2clet, 0, K * sizeof(double));
        memset(scloud, 0, K * sizeof(double));
        memset(s1cloud, 0, K * sizeof(double));
        memset(s2cloud, 0, K * sizeof(double));
        memset(sintr, 0, K * sizeof(double));
        n1 = 0;
        n2 = 0;
        n1_clet = 0;
        n2_clet = 0;
        n1_cloud = 0;
        n2_cloud = 0;
        n_intr = 0;

        // open the file
        sprintf(filename, "data/service_%d.dat", r);
        file = fopen(filename, "r");
        if (!file)
            handle_error("opening data file");

        // read completions
        if (fscanf(file, "-1 %ld %ld %ld %ld %ld\n",
            &c1_clet, &c2_clet, &c1_cloud, &c2_cloud, &c_setup) == EOF)
            handle_error("reading completions"); 

        // compute batch sizes
        b = (c1_clet + c2_clet + c1_cloud + c2_cloud) / K;
        b1 = (c1_clet + c1_cloud) / K;
        b2 = (c2_clet + c2_cloud) / K;
        b_clet = (c1_clet + c2_clet) / K;
        b1_clet = c1_clet / K;
        b2_clet = c2_clet / K;
        b_cloud = (c1_cloud + c2_cloud) / K;
        b1_cloud = c1_cloud / K;
        b2_cloud = c2_cloud / K;
        b_intr = c_setup / K;

        if (!b1_cloud) {
            fputs("\nWARNING: not enough class 1 jobs executed on the cloud. "
                    "The value will not be reliable\n", stderr);
            b1_cloud = 1;
        }

        // get data
        while (fscanf(file, "%ld %lf %lf %lf %lf %lf\n", &id,
                &s1_clet, &s2_clet, &s1_cloud, &s2_cloud, &setup) != EOF) {

            s[id / b] += s1_clet + s2_clet + s1_cloud + s2_cloud + setup;

            if (s1_clet || s1_cloud) {
                s1[n1 / b1] += s1_clet + s1_cloud;
                n1++;
            }
            if (s2_clet || s2_cloud) {
                s2[n2 / b2] += s2_clet + s2_cloud + setup;
                n2++;
            }
            if (s1_clet) {
                s1clet[n1_clet / b1_clet] += s1_clet;
                sclet[(n1_clet + n2_clet) / b_clet] += s1_clet;
                n1_clet++;
            }
            if (s2_clet && !setup) {
                s2clet[n2_clet / b2_clet] += s2_clet;
                sclet[(n1_clet + n2_clet) / b_clet] += s2_clet;
                n2_clet++;
            }
            if (s1_cloud) {
                s1cloud[n1_cloud / b1_cloud] += s1_cloud;
                scloud[(n1_cloud + n2_cloud) / b_cloud] += s1_cloud;
                n1_cloud++;
            }
            if (s2_cloud) {
                s2cloud[n2_cloud / b2_cloud] += s2_cloud;
                scloud[(n1_cloud + n2_cloud) / b_cloud] += s2_cloud;
                n2_cloud++;
            }
            if (setup) {
                sintr[n_intr / b_intr] += s2_clet + s2_cloud + setup;
                n_intr++;
            }
        }

        // close the file
        if (fclose(file) == EOF)
            handle_error("closing data file");

        // compute batch means
        for (i = 0; i < K; i++) {
            s[i] /= b;
            s1[i] /= b1;
            s2[i] /= b2;
            s1clet[i] /= b1_clet;
            s2clet[i] /= b2_clet;
            sclet[i] /= b_clet;
            s1cloud[i] /= b1_cloud;
            s2cloud[i] /= b2_cloud;
            scloud[i] /= b_cloud;
            sintr[i] /= b_intr;
        }

        // print results 
        printf("\n  Replication %d results:\n", r);
        c = confint(s, K, ALPHA); 
        dprintf(fd_s, "%f %f\n", c.mean, c.w);
        printf("system service time ......... = %f  +/- %f\n", c.mean, c.w);
        printf("autocorralation between batches: %f\n", autocor(s, K, 1));
        c = confint(s1, K, ALPHA); 
        dprintf(fd_s1, "%f %f\n", c.mean, c.w);
        printf("class 1 service time ........ = %f  +/- %f\n", c.mean, c.w);
        printf("autocorralation between batches: %f\n", autocor(s1, K, 1));
        c = confint(s2, K, ALPHA); 
        dprintf(fd_s2, "%f %f\n", c.mean, c.w);
        printf("class 2 service time ........ = %f  +/- %f\n", c.mean, c.w);
        printf("autocorralation between batches: %f\n", autocor(s2, K, 1));
        c = confint(s1clet, K, ALPHA); 
        dprintf(fd_s1clet, "%f %f\n", c.mean, c.w);
        printf("class 1 cloudlet service time = %f  +/- %f\n", c.mean, c.w);
        printf("autocorralation between batches: %f\n", autocor(s1clet, K, 1));
        c = confint(s2clet, K, ALPHA); 
        dprintf(fd_s2clet, "%f %f\n", c.mean, c.w);
        printf("class 2 cloudlet service time = %f  +/- %f\n", c.mean, c.w);
        printf("autocorralation between batches: %f\n", autocor(s2clet, K, 1));
        c = confint(sclet, K, ALPHA); 
        dprintf(fd_sclet, "%f %f\n", c.mean, c.w);
        printf("cloudlet service time ....... = %f  +/- %f\n", c.mean, c.w);
        printf("autocorralation between batches: %f\n", autocor(sclet, K, 1));
        c = confint(s1cloud, K, ALPHA); 
        dprintf(fd_s1cloud, "%f %f\n", c.mean, c.w);
        printf("class 1 cloud service time .. = %f  +/- %f\n", c.mean, c.w);
        printf("autocorralation between batches: %f\n", autocor(s1cloud, K, 1));
        c = confint(s2cloud, K, ALPHA); 
        dprintf(fd_s2cloud, "%f %f\n", c.mean, c.w);
        printf("class 2 cloud service time .. = %f  +/- %f\n", c.mean, c.w);
        printf("autocorralation between batches: %f\n", autocor(s2cloud, K, 1));
        c = confint(scloud, K, ALPHA); 
        dprintf(fd_scloud, "%f %f\n", c.mean, c.w);
        printf("cloud service time .......... = %f  +/- %f\n", c.mean, c.w);
        printf("autocorralation between batches: %f\n", autocor(scloud, K, 1));
        c = confint(sintr, K, ALPHA); 
        dprintf(fd_sintr, "%f %f\n", c.mean, c.w);
        printf("interrupted jobs service time = %f  +/- %f\n", c.mean, c.w);
        printf("autocorralation between batches: %f\n", autocor(sintr, K, 1));
    }

    // close output file
    if (close(fd_s) == -1)
        handle_error("closing output file");
    if (close(fd_s1) == -1)
        handle_error("closing output file");
    if (close(fd_s2) == -1)
        handle_error("closing output file");
    if (close(fd_sclet) == -1)
        handle_error("closing output file");
    if (close(fd_s1clet) == -1)
        handle_error("closing output file");
    if (close(fd_s2clet) == -1)
        handle_error("closing output file");
    if (close(fd_scloud) == -1)
        handle_error("closing output file");
    if (close(fd_s1cloud) == -1)
        handle_error("closing output file");
    if (close(fd_s2cloud) == -1)
        handle_error("closing output file");
    if (close(fd_sintr) == -1)
        handle_error("closing output file");

    return EXIT_SUCCESS;
}