Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: kaspar@rzhp9a.gsi.de (Matthias Kaspar)
Subject: DEC C / VAX C problems
Date: Fri, 14 Jan 1994 09:44:49 GMT	[thread overview]
Message-ID: <1994Jan14.104449@rzhp9a.gsi.de> (raw)

Hi everybody

Recently I got stuck with two C specific problems, one concerning DEC C on an 
OpenVMS V1.5 AXP system (DEC 3000/500), another one concerning VAX C on a 
VAXstation 4000-90, VMS-V5.5-2H4. 

I am by no means experienced in C so please don't flame me if the following 
questions seem obviuos to you. 

*****************************************************************************
*                                                                           *
* Problem 1 Using DEC C, SYSTEM$SPACE seems to delay the computation of     *
*           many functions in math.h on an OpenVMS AXP system.              *
*                                                                           *
*****************************************************************************

Use DEC C on an OpenVMS AXP system to compile the following source and analyze 
the time elapsed with the Performance Coverage Analyzer V4.1-1.

#include stdio
#include math

main()
{
double x,y=1;
int i;
for (i=0;i<200000000;i++) x=sin(y);
}

Compile and link this with the /debug qualifier. Use 
$ define lib$debug pca$collector 
and check the elapsed time with the Performance Coverage Analyzer PCA V4.1-1.

As expected, about 98% of the elapsed time is spent in the main() routine. 
Change sin(y) to cos(y) - still no problems.

Now change cos(y) to tan(y) or to sinh(y) or to cosh(y) or to tanh(y) or to 
exp(y) and you're in for a surprise. It takes ages to compute these functions 
(reduce the upper bound of the loop by two orders of magnitude if you are 
impatient) and PCA will tell you that something between 80% and 96% (!!!) of 
the time elapsed are spent in a routine called SYSTEM$SPACE. 

What does it do? When is it called? Why is it called?

Why is so much time spent there when computing some functions like tan(x), 
sinh(x), cosh(x), tanh(x) or exp(x) but practically no time when computing 
sin(x) or cos(x) ?

Might this be an OpenVMS / DEC C bug? Might this be a PCA bug? (Or do I just 
miss something terribly important when it comes to compute tan(x), sinh(x), 
cosh(x), tanh(x) or exp(x) ?) 

Does DEC know about this? What can I do about this?

How can I compute tanh(x) in DEC C (that's the function I desperately need) 
without loosing lots of CPU time in this peculiar SYSTEM$SPACE? (It doesn't 
make any sense to compose tanh(x) from a couple of exp(x)'s, because it takes 
even longer to compute an exp(x) than a tanh(x), so it wouldn't be an 
improvement. It doesn't make any sense either to call the Fortran tanh(x) from 
the DEC C program, if tried to do so but still 90%+ of the elapsed time are 
spent - you guessed it - in SYSTEM$SPACE.)

Right now I am trying a series expansion of tanh(x). However, I am not
satisfied and I would would prefer to use a built-in function.

SYSTEM$SPACE does not cause any problems computing the above functions 
in VAX C on a VAXstation, nor does SYSTEM$SPACE delays the computation 
of these functions in Fortran both on a VAX and an OpenVMS AXP system.

*******************************************************************************
*
* Problem 2 Using VAX C on a VAXstation with VMS, fwrite fails  
*           in case of fixed-length, record-formated files
*
*******************************************************************************

Somehow I do not succed to use the fwrite function on a VAXstation 
4000-90 under VMS-V5.5-2H4. Please take a look at the following source...

#include stdio
main()
{
float x[100];
int i,j;
FILE *myfile;

for (j=0;j<100;j++) x[j]=(float)j;  /* just for fun */

myfile=fopen("data.dat","w","ctx=rec","rfm=fix","mrs=512","shr=get,put");
/*I need the record format because the files have to be shareable*/
perror("\nperror after fopen...");
if (myfile==0) printf("\nfopen returns NULL pointer...");
else{
     i=fwrite(&x[0],sizeof(float), 100,myfile);
     perror("perror after fwrite... ");
     printf("\nfwrite returns...%d",i);
     fclose(myfile);
    }

/*just for fun try to reopen and read the file. However, you don't need this 
part to reproduce the error*/

myfile=fopen("data.dat","r","ctx=rec","rfm=fix","mrs=512","shr=get,put");
perror("\nperror after fopen for read...");
if (myfile==0) printf("\n fopen returns NULL pointer...");
else{
     i=fread(&x[0],sizeof(float),100,myfile);
     perror("perror after fread... ");
     printf("\nfread returns...%d",i);
     fclose(myfile);
    }
}


Now the first fopen succeds in opening the file data.dat. A $ dir data.dat/full 
tells me the file as been created correctly. The fwrite function however
returns 0 and consequently hasn't written a single byte to the file. perror 
after the fwrite gives an error message. The output I get looks like this...

perror after fopen...: error 0
perror after fwrite... : non-translatable vms error code: 0x186A4, vms message:
%rms-f-rsz, invalid record size

fwrite returns...0

The following lines are of course due to the attempt to read the empty file 
(I guess...)

perror after fopen for read...: non-translatable vms error code: 0x186A4, vms 
message:%rms-f-rsz, invalid record size
perror after fread... : non-translatable vms error code: 0x186A4, vms message:
%rms-f-rsz, invalid record size
fread returns...0
 
I have tried different record sizes (512, 1024, 2048, 4096, 8192 bytes), I have
tried to write different numbers of items and different items to the file, it
just does not work.

However, compiling the source with DEC C on an OpenVMS AXP system presents no 
problems at all, the code runs as expected and does NOT generate the above 
error messages. 100 floats (400 bytes) are written to the file, fwrite correctly
returns the number of items written, that is 100. Reading the file afterwards
works all right too. If I take this data.dat created on an OpenVMS AXP system
and copy it to the above VAXstation, the second part of the code succeds in 
opening and reading the file, so fread works with VAX C, just fwrite presents 
difficulties to me.

What can I do about this? Is this a VMS bug? (Or am I just too stupid to use 
fwrite correctly?) 

Why does it work on an OpenVMS AXP system, but fails on a VAXstation?


Thanks a lot for taking the time to read all this. Any comments or suggestions 
are most welcome. In case you know of any DEC Email address I might confront 
with these questions, please tell me.

As I don't expect these problems to be of general interest please send replies
to one of these Internet nodes:

mkaspar@axp601.gsi.de (mkaspar@[140.181.98.71])
mkaspar@vscn.gsi.de   (mkaspar@[140.181.97.141])
kaspar@IKF007.IKF.PHYSIK.UNI-FRANKFURT.DE (kaspar@[141.2.34.13])

Anyone interested in replies should send me an Email, I will of course be happy
to forward any incomming mail.

Thanks again, I really appreciate your help.

Bye,

Matthias Kaspar




             reply	other threads:[~1994-01-14  9:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-01-14  9:44 Matthias Kaspar [this message]
1994-01-14 18:21 ` DEC C / VAX C problems Steve Hobbs
1994-01-18 20:11 ` Ken Cowan
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox