PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

Linking to the HOSTNM function?

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
Steven_Speer



Joined: 08 Sep 2004
Posts: 7

PostPosted: Thu Sep 16, 2004 9:16 am    Post subject: Linking to the HOSTNM function? Reply with quote

Hello,

I am compiling a Fortran function for a Windows executable using the -Munix option which causes function names to be converted to lower case with an underscore appended.

Somehow this is causing a problem with the C 3F function "hostnm".

I read the "C 3F Functions"section in the pgf77.htm document which I quote here:
Quote:

The implementation of many of the routines uses functions which reside in the C library. If a C library does not contain the necessary functions, undefined symbol errors will occur at link-time. For example, if PGI 's C library is the C library available on the system, the following 3F routines exist in the Fortran run-time library but use of these routines will result in errors at link-time:


The 'hostnm' function is in the list that follows this quotation in the manual.

I don't understand this statment, since in the line that immediately preceeds this quotation in the manual says:
Quote:

These functions and subroutines are automatically loaded from the PGI 's Fortran run-time library if referenced by a pgf77 program.


What is the trick to use the 'hostnm' function??

I am familiar with doing one of the following from a previous problem I had with undefined references: use a special interface to the function; use a 'C$PRAGMA C()' in the fortran routine to redefine the name of the function; use a special '#define' statement for 'hostnm'; or rename the function somehow?

All other undefined references were resolved but the 'hostnm' is still problematic.

-Steven Speer
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 5815
Location: The Portland Group Inc.

PostPosted: Fri Sep 17, 2004 10:37 am    Post subject: Looking into a work around Reply with quote

Sorry for my tardiness on this issue, several of us have been doing some training so I haven't be able to respond. From what I can tell, there are several of the C 3F that aren't implemented on windows, including "hostnm". Why our docs say all of them are there, is probably an oversight.

Any case, I'm trying a work around and will post it once I find something useful. From you other post, it looks like this hasn't stop you from working, so hopefully my delay hasn't hurt.

- Mat
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 5815
Location: The Portland Group Inc.

PostPosted: Mon Sep 20, 2004 9:19 am    Post subject: Reply with quote

I've tried several posible solutions with little results. At least I understand better why this wasn't implemented! The basic problem is that our Windows product is a port of our Linux product. As such, we rely on a Linux like environment (cygwin) to handle system interfaces and are limited by what it provides.

For hostnm, we would need to call the libwsock32.a function 'gethostname'. While I was able to use 'gethostname' with pgcc, pgf90 could not use it either directly or through a C wrapper function.

So this leaves us with an ugly but works solution. You need to use the the "system" function to call the shell command 'hostname' and redirect its output to a file. Then open the file, read in the host name, and finally delete the file.

Sorry I couldn't do better. Maybe someone else has an idea?
Back to top
View user's profile
hongyon



Joined: 19 Jul 2004
Posts: 551

PostPosted: Tue Sep 21, 2004 1:25 pm    Post subject: Reply with quote

Hi,
I have example program and how I compiled with PGI Win32 5.2-2 release.

Hostname is "port".
------------------------Output------------------------
PGI$ pgf90 -Munix main.f -c
PGI$ pgf90 main.o func.c -lwsock32
func.c:
PGI$ ./a.exe
port*


--------------------------main.c -------------------------
program main
character (len=256) :: nam = ""
integer result
result = hostme(nam)
print *, nam
end

-------------------------func.c-----------------------------
#include <stdio.h>
#include <unistd.h>
#if defined (_WIN32) && ! defined (__CYGWIN__)
#include <winsock.h>
#endif
int hostme_ (char* name) {
int i;
#if defined (_WIN32) && ! defined (__CYGWIN__)
WSADATA p;
WSAStartup ((2<<8) | 2, &p);
#endif
return gethostname(name,256);
}
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group