Using PBS batch scripting, is there a way to view the contents of PBS_NODEFILE? - mpi

I read in the qsub man page that PBS_NODEFILE is created once mpirun, mpiexec, aprun, whatever, begins to execute. Is there a way to view its contents? I tried the following:
C code catfile.c:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
char command[256];
MPI_Init(&argc, &argv);
sprintf(command, "%s %s\n", "cat", argv[1]);
printf("%s\n", command);
system(command);
MPI_Finalize();
}
In my batch script, I run with
cc -o catfile catfile.c
aprun -n 1 ./catfile $PBS_NODEFILE
Output is
cat /var/spool/PBS/aux/1894.pbs01
cat: /var/spool/PBS/aux/1894.pbs01: No such file or directory
That's all I've got. Is there another way? Thanks.

Related

Process placement with aprun -- need one process per node

I need to run an MPI code on a Cray system under aprun. For reasons I won't go into, I am being asked to run it such that no node has more than one process. I have been puzzling over the aprun man page and I'm not sure if I've figured this out or not. If I have only two processes, will this command ensure that they run on different nodes? (Let's say there are 32 cores on a node.)
> aprun -n 2 -d 32 --cc depth ./myexec
If anyone is interested, my above command line does work. I tested it with the code:
#include <mpi.h>
#include <stdio.h>
 
int main(int argc, char **argv) {
char hname[80];
int length;
 
MPI_Init(&argc, &argv);
 
MPI_Get_processor_name(hname, &length);
printf("Hello world from %s\n", hname);
MPI_Finalize();
}

What's the d_ino in dirent of the root directory and its parent directory?

I am doing an Unix programming exercise to find out the i-node number of a directory and its parent directory, I know that command "ls -ldi" satisfies my requirement but as I said I am doing Unix programming exercise and just want to further understand it so I write the following code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
int
main(int argc, char *argv[])
{
DIR *dp;
struct dirent *dirp;
if(argc != 2)
fprintf(stderr, "usage: ex1 directory_name");
if((dp = opendir(argv[1])) == NULL)
fprintf(stderr, "can't open %s", argv[1]);
while((dirp = readdir(dp)) != NULL)
if(strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0)
printf("inode number of %s is %llu\n", dirp->d_name, dirp->d_ino);
closedir(dp);
exit(0);
}
I just check all the entries of a given path and compare if the name is dot or dot-dot, if it is, then print out its d_ino.
Here is what I am confused by:
if I run "./a.out .", this acts as what "ls -ldi .", meaning they both give the i-node number of the current directory and its parent directory, but if I run "./a.out /" expecting to find out the i-node number of the root directory and its parent directory, then my program print the i-node number 2 for "." and 1 for ".." but command "ls -ldi /." and "ls -ldi /.." both print 2.
So I am wondering why this occurs.
Thanks!

Why does reading from STDOUT work?

I encountered a curious case, where reading from STDOUT works, when running a program in terminal. The question is, why and how? Let's start with code:
#include <QCoreApplication>
#include <QSocketNotifier>
#include <QDebug>
#include <QByteArray>
#include <unistd.h>
#include <errno.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
const int fd_arg = (a.arguments().length()>=2) ? a.arguments().at(1).toInt() : 0;
qDebug() << "reading from fd" << fd_arg;
QSocketNotifier n(fd_arg, QSocketNotifier::Read);
QObject::connect(&n, &QSocketNotifier::activated, [](int fd) {
char buf[1024];
auto len = ::read(fd, buf, sizeof buf);
if (len < 0) { qDebug() << "fd" << fd << "read error:" << errno; qApp->quit(); }
else if (len == 0) { qDebug() << "fd" << fd << "done"; qApp->quit(); }
else {
QByteArray data(buf, len);
qDebug() << "fd" << fd << "data" << data.length() << data.trimmed();
}
});
return a.exec();
}
Here's qmake .pro file for convenience, if someone wants to test above code:
QT += core
QT -= gui
CONFIG += c++11
TARGET = stdoutreadtest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
And here's output of 4 executions:
$ ./stdoutreadtest 0 # input from keyboard, ^D ends, works as expected
reading from fd 0
typtyptyp
fd 0 data 10 "typtyptyp"
fd 0 done
$ echo pipe | ./stdoutreadtest 0 # input from pipe, works as expected
reading from fd 0
fd 0 data 5 "pipe"
fd 0 done
$ ./stdoutreadtest 1 # input from keyboard, ^D ends, works!?
reading from fd 1
typtyp
fd 1 data 7 "typtyp"
fd 1 done
$ echo pipe | ./stdoutreadtest 1 # input from pipe, still reads keyboard!?
reading from fd 1
typtyp
fd 1 data 7 "typtyp"
fd 1 done
So, the question is, what is going on, why do the last two runs above actually read what is typed on terminal?
I also tried looking at QSocketNotifier sources here leading to here, but didn't really gain any insight.
There is no different between fd 0,1,2, all of the three fds is pointing to terminal if not redirected, they are strictly IDENTICAL!
Programs usually use 0 for input, 1 for output, 2 for error, but all of them can be different ways.
Eg, for less, ordinary usage:
prog | less
Now input of less is redirected to the prog, and less can not read any user input from stdin, so how does less get user input like scroll up/down or page up/down ?
Sure less can read user input from stdout, which is exactly what less does.
So you can use these fds wisely when you know how bash handle these fds.

Emacs embedded in a Qt Application

I've tried to embed emacs in a Qt Application using QX11EmbedContainer, and works but with two important exception. First of all, here is the code:
#include <QX11EmbedWidget>
#include <QtGui>
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QX11EmbedContainer container;
container.show();
container.resize(500, 500);
QProcess* process = new QProcess(&container);
QString executable("emacsclient");
QStringList arguments;
arguments << "--parent-id" << QString::number(container.winId());
process->start(executable, arguments);
int status = app.exec();
process->close();
return status;
}
And the compilation and execution line (and the previous thrown of the emacs server):
$ emacs -q --daemon &
// filtered output
$ g++ test.cpp -lQtGui -lQtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4
$ ./a.out
And finally, the result:
But, when or if I try to write something in the minibuffer, the size of the widget is collapsed, and the focus is also lost:
If I make click in the (now shorter) widget, I can continue working with emacs without problems, but I should resize the window in order to emacs is expanded other time as originally.
Where is the problem?
Try using a layout.
Here is the Qt5 documentation on layout management.

MPI Number of processors?

Following is my code in MPI, which I run it over a core i7 CPU (quad core), but the problem is it shows me that it's running under 1 processor CPU, which has to be 4.
int main(int argc, char *argv[])
{
int rank, size;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
printf("Hello world! I am %d of %d\n", rank, size);
MPI_Finalize();
return 0;
}
I was wondering if the problem is with MPI library or sth else?
Here is the result that it shows me:
Hello world! I am 0 of 1
Additional info:
Windows 7 - Professional x64
Prima facie it looks like you are running the program directly. Did you try using mpiexec -n 2 or -n 4?

Resources