Usenet comp.os.linux.alpha (1997-2013)
 help / color / mirror / Atom feed
* Re: A Fortran/C code malloc problem
  1999-03-24  5:00 A Fortran/C code malloc problem b_duke
@ 1999-03-24  5:00 ` Robert Harley
  1999-03-25  5:00   ` b_duke
  1999-03-25  5:00 ` Larry Zimmerman
  1 sibling, 1 reply; 5+ messages in thread
From: Robert Harley @ 1999-03-24  5:00 UTC (permalink / raw)



b_duke@my-dejanews.com writes:
>[...]
> The problem is that the number returned by malloc is far too
> large giving an offset from X(1) that is far too large. It is
> 182 Gb and can not be converted to an INTEGER*4

Well yes.  Alpha Linux is a 64-bit O.S. so there is no reason
whatsoever for the difference between two pointers to fit in 32 bits.


> required for the rest of the code to access the memory.

If the rest of the code requires the difference to fit in 32 bits,
then it is broken.


> Can anyone explain what is going on here? Have I blundered
> with the code?

No, you haven't.


> Can you reproduce this on other alpha linux systems?

I haven't tried but I'm sure they're all the same.


Bye,
  Rob.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* A Fortran/C code malloc problem
@ 1999-03-24  5:00 b_duke
  1999-03-24  5:00 ` Robert Harley
  1999-03-25  5:00 ` Larry Zimmerman
  0 siblings, 2 replies; 5+ messages in thread
From: b_duke @ 1999-03-24  5:00 UTC (permalink / raw)


I have been struggling for some weeks with the port of an established
program to Alpha linux. It is a fortran code that calls a small
amount of C which in turn calls malloc to allocate dynamic memory.
The offset of the memory so allocated from the beginning of an
array X(1) is then used to access various areas. I'm not interesting
in changing this. It is'nt my code and it works on almost every
other machine except alpha linux. I just want to get it to work.

I am aware that malloc returns a long int pointer and that long
int is 8 bytes on alpha linux, while it is 4 bytes on PC Linux.

The code below isolates the problem from the main program. It
seems to give exactly the results I get from the main program.
I have tried to force everything that should be IINTEGER*8 to be
so, even to making the functions external so I can declare them.

      Program TEST
      IMPLICIT NONE
      DOUBLE PRECISION X
      INTEGER*8 LOCMEM,LOCX,LOFFS1,LOFFS2,MEMGET,LADDRS
      INTEGER*4 MEMLIM,LOFFS
      COMMON /F/ X(1)
      EXTERNAL MEMGET
      EXTERNAL LADDRS
      LOCX=LADDRS(X(1))
      MEMLIM = 100000
      LOCMEM = MEMGET(MEMLIM)
C  Allocate MEMLIM words (8 bytes) of memory.
      LOFFS1 = LOCMEM - LOCX
      LOFFS2 = (LOFFS1+7)/8 + 1
C  WE NEED LOFFS TO BE I*4
      LOFFS = LOFFS2
      WRITE(*,1) LOCMEM
      WRITE(*,1) LOCX
      WRITE(*,1) LOFFS1
      WRITE(*,1) LOFFS2
      WRITE(*,1) LOFFS
 1    FORMAT(1x,I16)
      STOP
      END

with this C linked in:-

long memget_(nwords) long *nwords;
   { unsigned int nbytes;
     long nn;
     nbytes = (*nwords+2)*8;
     nn = (long) malloc(nbytes);
     printf("size of nn = %ld nn = %ld\n",sizeof(nn),nn);
     return nn; }

/* Taking out the nn stuff and doing return malloc gives the
same result. */

long laddrs_(arg) long arg;
   { return(arg); }

laddrs is used in place of loc to give the address of X(1), so
I can see what is going on, but loc gives the same results.

Running this on the alpha gives:-

size of nn = 8 nn = 1466015604752
    1466015604752
       4832925752
    1461182679000
     182647834876
      -2035758852

long is *8 and the number in memget is the same as the one coming out.

On a PC under linux, I get:-

size of nn = 4 nn = 1074581512
       1074581512
        134546552
        940034960
        117504371
        117504371

after altering the INTEGER*8 to INTEGER*4 and this seems fine.

The problem is that the number returned by malloc is far too
large giving an offset from X(1) that is far too large. It is
182 Gb and can not be converted to an INTEGER*4 required for
the rest of the code to access the memory.

Can anyone explain what is going on here? Have I blundered
with the code? Can you reproduce this on other alpha linux
systems? I would welcome any assistence. Please e-mail your
replies and I will summarise to comp.os.linux.alpha.

Brian Salter-Duke.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: A Fortran/C code malloc problem
  1999-03-24  5:00 ` Robert Harley
@ 1999-03-25  5:00   ` b_duke
  1999-03-25  5:00     ` Greg Lindahl
  0 siblings, 1 reply; 5+ messages in thread
From: b_duke @ 1999-03-25  5:00 UTC (permalink / raw)


In article <rz790cndtd7.fsf@corton.inria.fr>,
  Robert Harley <harley@corton.inria.fr> wrote:
>
> b_duke@my-dejanews.com writes:
> >[...]
> > The problem is that the number returned by malloc is far too
> > large giving an offset from X(1) that is far too large. It is
> > 182 Gb and can not be converted to an INTEGER*4
>
> Well yes.  Alpha Linux is a 64-bit O.S. so there is no reason
> whatsoever for the difference between two pointers to fit in 32 bits.

Yes, I agree with this, but the number still seems enormous. The main
code has worked for years on very many machines, including 64-bit
machines. It is used regularly on Alphas running Digital Unix for
example. In fact most of the development work on the main code
is carried out on DU or IBM RS6000s.

> > required for the rest of the code to access the memory.
>
> If the rest of the code requires the difference to fit in 32 bits,
> then it is broken.

I certainly expect the difference in 8 byte words to fit into 32
bits. Surely the range of mamory addresses is not that large?

> > Can anyone explain what is going on here? Have I blundered
> > with the code?
>
> No, you haven't.
>
> > Can you reproduce this on other alpha linux systems?
>
> I haven't tried but I'm sure they're all the same.
>

I would be gratefull if you could try it, particularly if your
alpha linux is bang up to date with its software. I do not
have much control over the machine I am using. I have just be
asked to test whether the code I use can be ported to Alpha
linux as they are intending to move the main university research
machine over from DU to alpha linux. This is one of the machines
used by my research group in Darwin.

> Bye,
>   Rob.

Cheers, Brian.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: A Fortran/C code malloc problem
  1999-03-25  5:00   ` b_duke
@ 1999-03-25  5:00     ` Greg Lindahl
  0 siblings, 0 replies; 5+ messages in thread
From: Greg Lindahl @ 1999-03-25  5:00 UTC (permalink / raw)


b_duke@my-dejanews.com writes:

> > Well yes.  Alpha Linux is a 64-bit O.S. so there is no reason
> > whatsoever for the difference between two pointers to fit in 32 bits.
> 
> Yes, I agree with this, but the number still seems enormous.

In fact, Linux intentionally allows a big space for the process, so
you can get offsets which are that big. Sorry; that's the way it
works. You might want to fix your code.

> It is used regularly on Alphas running Digital Unix for
> example.

DU has a different memory map for processes, and the -taso flag on the
linker for broken 32-bit programs. Does your program use -taso under
DU?

There was some discussion about duplicating -taso under Linux on the
axp-list@redhat.com mailing list, but I'm not sure if anyone is actually
working on it.

-- g




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: A Fortran/C code malloc problem
  1999-03-24  5:00 A Fortran/C code malloc problem b_duke
  1999-03-24  5:00 ` Robert Harley
@ 1999-03-25  5:00 ` Larry Zimmerman
  1 sibling, 0 replies; 5+ messages in thread
From: Larry Zimmerman @ 1999-03-25  5:00 UTC (permalink / raw)


In article <7d9vrc$clg$1@nnrp1.dejanews.com>,
	b_duke@my-dejanews.com writes:
>I have been struggling for some weeks with the port of an established
>program to Alpha linux. It is a fortran code that calls a small
>amount of C which in turn calls malloc to allocate dynamic memory.

>The code below isolates the problem from the main program. It
>      Program TEST
..
>      LOFFS2 = (LOFFS1+7)/8 + 1
You might want to try using I*8 variables instead of constants.
I have found problems with mixed size aritmetic.

>with this C linked in:-
>
>long memget_(nwords) long *nwords;
>   { unsigned int nbytes;
I think you should declare nbytes as long or size_t.

>The problem is that the number returned by malloc is far too
>large giving an offset from X(1) that is far too large. It is
This was discussed on the redhat alpha list. The problem is that
small amounts of memory are allocated in one place, and larger
amounts are allocated at a higher address that is not contiguous
with the rest of the program.

>I would welcome any assistence.
I have a similar scheme that seems to work for me. Check out:
http://walleye.gonefishing.sk.ca  click on the linux tidbits,
then look for the g77 link. If this is useful to you, feel free
to copy, use, modify it.

Larry Z.

-- 
signature withheld pending a patent/copyright search.




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1999-03-25  5:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1999-03-24  5:00 A Fortran/C code malloc problem b_duke
1999-03-24  5:00 ` Robert Harley
1999-03-25  5:00   ` b_duke
1999-03-25  5:00     ` Greg Lindahl
1999-03-25  5:00 ` Larry Zimmerman

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