Hi Matt,

On 01/15/2016 03:53 PM, Matt Thompson wrote:
There is a chance in the future I might want/need to query an environment
variable in a Fortran program, namely to figure out what switch a currently
running process is on (via SLURM_TOPOLOGY_ADDR in my case) and perhaps make a
"per-switch" communicator.[1]

So, I coded up a boring Fortran program whose only exciting lines are:

    call MPI_Get_Processor_Name(processor_name,name_length,ierror)
    call get_environment_variable("HOST",host_name)

    write (*,'(A,X,I4,X,A,X,I4,X,A,X,A)') "Process", myid, "of", npes, "is on
processor", trim(processor_name)
    write (*,'(A,X,I4,X,A,X,I4,X,A,X,A)') "Process", myid, "of", npes, "is on
host", trim(host_name)

just a side-note: the correct way to query the hostname is in this thread on stackoverflow and various Unix/POSIX/Linux books in C:

<http://stackoverflow.com/questions/504810/how-do-i-find-the-current-machines-full-hostname-in-c-hostname-and-domain-info>

I'd suggest you wrap that in Fortran's ISO C bindings and use that instead of some fragile environment variable that requires an environment variable to be set up. The process is still not entirely robust because you might end up on a non-RFC-compliant system where name lookup doesn't work.

Regards, Thomas
--
Thomas Jahns
HD(CP)^2
Abteilung Anwendungssoftware

Deutsches Klimarechenzentrum GmbH
Bundesstraße 45a • D-20146 Hamburg • Germany

Phone:  +49 40 460094-151
Fax:    +49 40 460094-270
Email:  Thomas Jahns <ja...@dkrz.de>
URL:    www.dkrz.de

Geschäftsführer: Prof. Dr. Thomas Ludwig
Sitz der Gesellschaft: Hamburg
Amtsgericht Hamburg HRB 39784

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to