caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] Re: complex bigarrays
@ 2001-11-08 23:13 David Gurr
  0 siblings, 0 replies; 8+ messages in thread
From: David Gurr @ 2001-11-08 23:13 UTC (permalink / raw)
  To: caml-list, ohl; +Cc: xavier.leroy

> OTOH, there are many numerical libraries (e.g. LAPACK) that
> explicitely declare two REAL arrays and use the entries as real and
> imaginary parts.  However, this is a library choice and sidesteps
> Fortran's COMPLEX type altogether.

There are also libraries that do  Re[C(1)] Re[C(2)] Im[C(1)] Im[C(2)]
etc in order to make use of Altivec packed arith.  
-D
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

* Re: [Caml-list] Re: complex bigarrays
  2001-11-08 17:56       ` Thorsten Ohl
  2001-11-08 18:12         ` Joerg Czeranski
  2001-11-08 18:20         ` Ken Rose
@ 2001-11-08 18:35         ` David McClain
  2 siblings, 0 replies; 8+ messages in thread
From: David McClain @ 2001-11-08 18:35 UTC (permalink / raw)
  To: caml-list

> AFAIK, the C compiler is free to pad structures for better alignment,
> resulting in better performance.  Isn't it even free to reorder
> elements?

No C compiler in its right mind would dare reorder the elements of an array
or struct.... padding is another issue. C is a high-level Assembly language,
and as such it produces what you write for the most part.

I used to write C compilers for a living, and I became intimately familiar
with the old specs... I used to be able to write C and see in my mind as I
went along, exactly which registers were being banged on (back in the days
of the MC680x0).

If this implicit contract were broken by some vendor an enormous amount of
legacy code would also break. They wouldn't dare!!!

- DM
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

* Re: [Caml-list] Re: complex bigarrays
  2001-11-08 17:56       ` Thorsten Ohl
  2001-11-08 18:12         ` Joerg Czeranski
@ 2001-11-08 18:20         ` Ken Rose
  2001-11-08 18:35         ` David McClain
  2 siblings, 0 replies; 8+ messages in thread
From: Ken Rose @ 2001-11-08 18:20 UTC (permalink / raw)
  To: ohl; +Cc: caml-list, shiv

Thorsten Ohl wrote:

> AFAIK, the C compiler is free to pad structures for better alignment,
> resulting in better performance.  Isn't it even free to reorder
> elements?

No, it's not free to reorder them.  C89, section 6.5.2.1 semantics,
paragraph 9

"Within a structure object, the non-bit-field members and the units in
which bit-fields reside have addresses that increase in the order in
which they are declared."

They can be padded anywhere except at the beginning.

 - ken
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

* Re: [Caml-list] Re: complex bigarrays
  2001-11-08 17:56       ` Thorsten Ohl
@ 2001-11-08 18:12         ` Joerg Czeranski
  2001-11-08 18:20         ` Ken Rose
  2001-11-08 18:35         ` David McClain
  2 siblings, 0 replies; 8+ messages in thread
From: Joerg Czeranski @ 2001-11-08 18:12 UTC (permalink / raw)
  To: ohl; +Cc: caml-list

On Thu, 8 Nov 2001 18:56:09 +0100
Thorsten Ohl <ohl@hep.tu-darmstadt.de> wrote:
> shiv@mac.com writes:
> > I have read (some where) that this might cause problems with some C
> > compilers on some machines. That is, if we define struct {float re;
> > float im} A[10]; Then the entries in A may not be packed together as
> > we might expect.
>
> AFAIK, the C compiler is free to pad structures for better alignment,
> resulting in better performance.  Isn't it even free to reorder
> elements?

No, it isn't.  Order must always be preserved, and no padding is allowed
in front of the first component.

You can always use an array of two elements for each complex:
float A[10][2];  (Or rather typedef float complex_t[2]; complex_t A[10];)
Then the compiler isn't allowed to use any padding.

C99 has introduced complex float, complex double, complex long double,
but I don't think there's a definition of the representation.

regards,
jörch
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

* Re: [Caml-list] Re: complex bigarrays
       [not found]     ` <81DA66D2-D46E-11D5-82F9-003065BDAA76@mac.com>
@ 2001-11-08 17:56       ` Thorsten Ohl
  2001-11-08 18:12         ` Joerg Czeranski
                           ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Thorsten Ohl @ 2001-11-08 17:56 UTC (permalink / raw)
  To: caml-list, shiv

shiv@mac.com writes:

> But most of the LAPACK complex routines do expect to see regular
> FORTRAN COMPLEX arrays

You're right.  I was incorrectly generalizing from DGEEV etc. that
take real arrays as input return (among others) complex vectors.  The
latter are represented as two real array.  Routines that take complex
inputs represent them as COMPLEX arrays.

> So I would vote to represent complex bigarrays using a single array 
> with real and imaginary parts of each element adjacent to each other in 
> that order.

I fully agree.  Even if my generalization had been correct, I would
still have voted for this, because it conforms to the Fortran language
definition.

> I have read (some where) that this might cause problems with some C
> compilers on some machines. That is, if we define struct {float re;
> float im} A[10]; Then the entries in A may not be packed together as
> we might expect.

AFAIK, the C compiler is free to pad structures for better alignment,
resulting in better performance.  Isn't it even free to reorder
elements?
-- 
Thorsten Ohl, Physics Department, TU Darmstadt -- ohl@hep.tu-darmstadt.de
http://heplix.ikp.physik.tu-darmstadt.de/~ohl/ [<=== PGP public key here]
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

* Re: [Caml-list] Re: complex bigarrays
  2001-11-08  9:28 ` [Caml-list] Re: complex bigarrays Xavier Leroy
  2001-11-08 14:59   ` Rolf Wester
@ 2001-11-08 15:35   ` Thorsten Ohl
       [not found]     ` <81DA66D2-D46E-11D5-82F9-003065BDAA76@mac.com>
  1 sibling, 1 reply; 8+ messages in thread
From: Thorsten Ohl @ 2001-11-08 15:35 UTC (permalink / raw)
  To: caml-list; +Cc: Xavier Leroy

Xavier Leroy writes:

> while in Fortran some codes use the C representation (one array of
> pairs) while others use a pair of arrays.

>From section 4.3.1.3 of the Fortran standard:
    
    The values a complex type are ordered pairs of real values.  The
    first real value is called the real second real value is called
    the imaginary part.

and from section 14.6.3.1 of the Fortran standard:

    (1) A nonpointer scalar object of type default integer, default
    real, or default logic occupies a single numeric storage unit;

    (2) A nonpointer scalar object of type double precision real or
    default complex occupies two contiguous numeric storage units;

If you declare

      COMPLEX C(2)

it is layed out as

      Re[C(1)] Im[C(1)] Re[C(2)] Im[C(2)]

Fortran compilers have no freedom here, because they must support
EQUIVALENCE and COMMON aliasing.

OTOH, there are many numerical libraries (e.g. LAPACK) that
explicitely declare two REAL arrays and use the entries as real and
imaginary parts.  However, this is a library choice and sidesteps
Fortran's COMPLEX type altogether.

-- 
Thorsten Ohl, Physics Department, TU Darmstadt -- ohl@hep.tu-darmstadt.de
http://heplix.ikp.physik.tu-darmstadt.de/~ohl/ [<=== PGP public key here]
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

* Re: [Caml-list] Re: complex bigarrays
  2001-11-08  9:28 ` [Caml-list] Re: complex bigarrays Xavier Leroy
@ 2001-11-08 14:59   ` Rolf Wester
  2001-11-08 15:35   ` Thorsten Ohl
  1 sibling, 0 replies; 8+ messages in thread
From: Rolf Wester @ 2001-11-08 14:59 UTC (permalink / raw)
  To: caml-list

Hi Xavier;

can you please tell me when this complex Bigarrays are likely to be
available?

Rolf Wester
-------------------------------------
Rolf Wester
rolf.wester@ilt.fraunhofer.de
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

* Re: [Caml-list] Re: complex bigarrays
  2001-11-06  9:05 [Caml-list] Re: OCaml speed Rolf Wester
@ 2001-11-08  9:28 ` Xavier Leroy
  2001-11-08 14:59   ` Rolf Wester
  2001-11-08 15:35   ` Thorsten Ohl
  0 siblings, 2 replies; 8+ messages in thread
From: Xavier Leroy @ 2001-11-08  9:28 UTC (permalink / raw)
  To: Rolf Wester; +Cc: caml-list

> The biggest problem is that there is no OCaml build in type complex
> and that the Bigarray doesn't have complex too (sometime ago I read
> that someone was thinking about adding complex numbers to the
> Bigarray module, I would appreciate this very much).

Adding complex arrays to the Bigarray module is on my to-do list.

One issue is how these arrays should be represented to allow
no-copying exchange between C and Fortran.  My understanding is that
in C, arrays of complex are generally represented as arrays of pairs
of floats (or doubles), while in Fortran some codes use the C
representation (one array of pairs) while others use a pair of arrays.
The array-of-pairs representation fits well the Bigarray interface,
but the pair-of-arrays approach does not.  

Could someone with numerical experience in Fortran provide more
information on this?

- Xavier Leroy
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

end of thread, other threads:[~2001-11-09  8:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-08 23:13 [Caml-list] Re: complex bigarrays David Gurr
  -- strict thread matches above, loose matches on Subject: below --
2001-11-06  9:05 [Caml-list] Re: OCaml speed Rolf Wester
2001-11-08  9:28 ` [Caml-list] Re: complex bigarrays Xavier Leroy
2001-11-08 14:59   ` Rolf Wester
2001-11-08 15:35   ` Thorsten Ohl
     [not found]     ` <81DA66D2-D46E-11D5-82F9-003065BDAA76@mac.com>
2001-11-08 17:56       ` Thorsten Ohl
2001-11-08 18:12         ` Joerg Czeranski
2001-11-08 18:20         ` Ken Rose
2001-11-08 18:35         ` David McClain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).