/*****************************************************************************\ * Consume CPU and I/O resources. * * Copyright (C) 2013 Bull S. A. S. * Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois. * Written by Rod Schultz * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by * the Free Software Foundation version 2 of the License. * This 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 program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * *****************************************************************************/ #include #include #include #include #include #include #include #define SECOND2RUN 180 #define BURNBUFSIZ 1024*1024 #define CPUBUSY_PCT 40 #define READLOOP 10 #define WRITELOOP 20 // WRITELOOP must be greater than READLOOP int busyloop(int burn, int nxny, double *m1, double *m2, double *m1m2) { int i, j, k; int iters = 0; struct timeval tv; gettimeofday(&tv, NULL); int loopstart = tv.tv_usec; int curtime = tv.tv_usec; int busy = 0; int nxny_x, ioff, joff; while (busy < burn) { iters++; nxny_x = 0; for (i=0; i WRITELOOP) { printf("\nFATAL: Compile parameter READLOOP > WRITELOOP"); exit(1); } if ((env_str = getenv("SLURM_JOB_ID")) == NULL) { fprintf(stderr, "info: getenv(SLURM_JOB_ID) failed. " "(Not running Slurm?)\n"); } else { job_id = atoi(env_str); if ((env_str = getenv("SLURM_STEPID")) != NULL) { step_id = atoi(env_str); } if ((env_str = getenv("SLURM_PROCID")) != NULL) { task_id = atoi(env_str); } } burnbuf = malloc(sizeof(char)*BURNBUFSIZ); memset(burnbuf,'\0',BURNBUFSIZ); sprintf(burnpath,"/tmp/ioburn_%d_%d_%d",job_id,step_id,task_id); ms_busy = CPUBUSY_PCT*10000; m1 = malloc(sizeof(double)*nxny*nxny); m2 = malloc(sizeof(double)*nxny*nxny); m1m2 = malloc(sizeof(double)*nxny*nxny); for (i=0; i 0) actualbusy += busyloop(dobusy, nxny, m1, m2, m1m2); do_io(burnpath, burnbuf, BURNBUFSIZ, READLOOP, WRITELOOP); reads += READLOOP; writes += WRITELOOP; gettimeofday(&tv, NULL); curtime = tv.tv_usec; if (curtime < loopstart) curtime += 1000000; nap = 1000000 - (curtime - loopstart); usleep(nap); } realpctbusy = ((float) actualbusy)*100.0/((float)(SECOND2RUN*1000000)); printf("\ntest12.6.prog finished after %d seconds. busy=%3.1f%% " "Reads=%d Writes=%d SLURM_JobId=%d StepId=%d TaskId=%d\n", SECOND2RUN,realpctbusy,reads, writes,job_id,step_id,task_id); free(m1); free(m2); free(m1m2); free(burnbuf); remove(burnpath); return 0; }