/** * Author: Martin Drab (c) 2015 * * This code is provided freely as a tutorial for use on the Hyperion cluster * at the Dept. of Solid State Engineering and Dept. of Mathematics * of the Faculty of Nuclear Sciences and Physical Engineering, Czech Technical University in Prague. * * Feel free to modify it for your own use. */ #include #include #include #include #include int main (int argc, char **argv) { int _Ret; int _NProc; /*!< Number of processes in this MPI group */ int _Rank; /*!< Number/ID of our process */ char _CPUName[MPI_MAX_PROCESSOR_NAME+1]; /*!< Name of the processor where we run */ int x; /*!< Actual size of the string within the _CPUName */ char *_EnvTMPDIR; char *_EnvTMP; struct stat _StatTMP; struct statvfs _StatVFSTMP; /* Initialize MPI */ _Ret = MPI_Init (&argc, &argv); if (_Ret != MPI_SUCCESS) { fprintf (stderr, "*** ERROR: Failed to call MPI_Init() with error code: %i\n", _Ret); MPI_Abort (MPI_COMM_WORLD, _Ret); } /* Get info about the process */ MPI_Comm_size (MPI_COMM_WORLD, &_NProc); MPI_Comm_rank (MPI_COMM_WORLD, &_Rank); MPI_Get_processor_name (_CPUName, &x); _CPUName[x] = 0; _EnvTMPDIR = getenv ("TMPDIR"); _EnvTMP = getenv ("TMP"); _Ret = stat (_EnvTMP, &_StatTMP); if (_Ret) { fprintf (stderr, "*** ERROR [%i/%i]: Failed to get stat() of TMP. (%i)", _Rank, _NProc, _Ret); MPI_Abort (MPI_COMM_WORLD, _Ret); } _Ret = statvfs (_EnvTMP, &_StatVFSTMP); if (_Ret) { fprintf (stderr, "*** ERROR [%i/%i]: Failed to get statvfs() of TMP. (%i)", _Rank, _NProc, _Ret); MPI_Abort (MPI_COMM_WORLD, _Ret); } printf ("Process %i/%i running on %s. TMP=\"%s\", TMPDIR=\"%s\", mode=0%o, UID=%u, GID=%u, available %.2f MB\n", _Rank, _NProc, _CPUName, _EnvTMP, _EnvTMPDIR, (unsigned int)_StatTMP.st_mode & 07777, (unsigned int)_StatTMP.st_uid, (unsigned int)_StatTMP.st_gid, (double)((unsigned long long)_StatVFSTMP.f_bavail * _StatVFSTMP.f_bsize)/(1024.0*1024.0)); /* Destroy MPI */ MPI_Finalize (); return 0; }