comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Some MAKE_DLL questions
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Some MAKE_DLL questions [message #92137] Mon, 19 October 2015 06:30 Go to next message
natha is currently offline  natha
Messages: 482
Registered: October 2007
Senior Member
Hi guys,

I've never created a sharable library from C code to be used by IDL with CALL_EXTERNAL.
I was wondering if it would be possible to create some parallel code using C + OpenMP and then generate de DLL. I don't know if this is possible since the documentation says:
"Not every possible option supported by the C compiler or system linker is addressed, only those commonly needed by IDL-related C code."

I have some more questions related to the DLLs:
- Are they platform independent? Can they be used in Mac, Win, Linux?
- How is the memory managed? Are the variables copied to a different block?

Thank you for all your help and clarifications,
Nata
Re: Some MAKE_DLL questions [message #92138 is a reply to message #92137] Mon, 19 October 2015 08:04 Go to previous messageGo to next message
Russell[1] is currently offline  Russell[1]
Messages: 101
Registered: August 2011
Senior Member
I never got make_dll to produce a shared library that used OpenMP. If you make it work, I'd love to know how you did it. I did all this on Mac OS.

-Russell


On Monday, October 19, 2015 at 9:31:26 AM UTC-4, nata wrote:
> Hi guys,
>
> I've never created a sharable library from C code to be used by IDL with CALL_EXTERNAL.
> I was wondering if it would be possible to create some parallel code using C + OpenMP and then generate de DLL. I don't know if this is possible since the documentation says:
> "Not every possible option supported by the C compiler or system linker is addressed, only those commonly needed by IDL-related C code."
>
> I have some more questions related to the DLLs:
> - Are they platform independent? Can they be used in Mac, Win, Linux?
> - How is the memory managed? Are the variables copied to a different block?
>
> Thank you for all your help and clarifications,
> Nata
Re: Some MAKE_DLL questions [message #92139 is a reply to message #92138] Mon, 19 October 2015 08:44 Go to previous messageGo to next message
natha is currently offline  natha
Messages: 482
Registered: October 2007
Senior Member
I guess is not possible. What about my other 2 questions?
Re: Some MAKE_DLL questions [message #92141 is a reply to message #92137] Mon, 19 October 2015 09:58 Go to previous messageGo to next message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On 10/19/15 7:30 AM, nata wrote:
> Hi guys,
>
> I've never created a sharable library from C code to be used by IDL
with CALL_EXTERNAL.
> I was wondering if it would be possible to create some parallel code
using C + OpenMP and then generate de DLL. I don't know if this is
possible since the documentation says:
> "Not every possible option supported by the C compiler or system
linker is addressed, only those commonly needed by IDL-related C code."

You can pass flags to the EXTRA_CFLAGS and EXTRA_LFLAGS keywords. I've
not used OpenMP, are there just special flags to use? You will also have
to make sure MAKE_DLL is set to use the correct compiler.

> I have some more questions related to the DLLs:
> - Are they platform independent? Can they be used in Mac, Win, Linux?

Absolutely not. But use the PLATFORM_EXTENSION keyword with MAKE_DLL (or
just use the correct string in the name) to make many shared objects,
each one valid and named for a particular platform. IDL will use the
correct one.

> - How is the memory managed? Are the variables copied to a different block?

I'm not sure what you mean.

> Thank you for all your help and clarifications,
> Nata
>


--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
Re: Some MAKE_DLL questions [message #92142 is a reply to message #92141] Mon, 19 October 2015 10:36 Go to previous messageGo to next message
natha is currently offline  natha
Messages: 482
Registered: October 2007
Senior Member
Thank you Michael for your reply!

About my third question; I just want to know if the variables are copied (duplicated) when they are passed to the C code.
Thank you,
Nata
Re: Some MAKE_DLL questions [message #92143 is a reply to message #92142] Mon, 19 October 2015 18:40 Go to previous messageGo to next message
Jim  Pendleton is currently offline  Jim Pendleton
Messages: 165
Registered: November 2011
Senior Member
On Monday, October 19, 2015 at 11:36:39 AM UTC-6, nata wrote:
> Thank you Michael for your reply!
>
> About my third question; I just want to know if the variables are copied (duplicated) when they are passed to the C code.
> Thank you,
> Nata

By default, scalar arguments are passed by reference. There's a VALUE keyword to CALL_EXTERNAL to control this. Arrays are always passed by reference.

Strings in particular are a special case. You'll want to understand the differences. (It's generally easier to convert them to byte arrays instead and cast the pointers to char * on the C side.)

As the online help says, "See Chapter 3, "Using CALL_EXTERNAL" (External Development Guide in the help/pdf directory of your IDL installation).

Jim P
Re: Some MAKE_DLL questions [message #92148 is a reply to message #92143] Tue, 20 October 2015 08:13 Go to previous message
natha is currently offline  natha
Messages: 482
Registered: October 2007
Senior Member
OK, so it seems to work...
I took the example code of Michael's book and I wrote the following OpenMP version:

#include <omp.h>
#include <stdio.h>
#include <stdlib.h>

float callex_total(float arr[], int *n) {

int nthreads, i, tid;
float total = 0.;

#pragma omp parallel shared(arr) private(i,tid)
{
tid = omp_get_thread_num();
if (tid == 0)
{
nthreads = omp_get_num_threads();
printf("Number of threads = %d\n", nthreads);
}

printf("Thread %d starting...\n",tid);

#pragma omp for
for (i = 0; i < *n; i++)
{
total += arr[i];
printf("Thread %d: total += arr[%d]\n",tid,i);
}

} /* end of parallel section */

return(total);
}

Then, I had to play a lot with the compiler but at the end I've found the way:

cfile='callex_total.c'
cfile_noext=file_basename(cfile, '.c')

srcdir = file_dirname(file_expand_path(cfile))

cc='gcc -fopenmp -lgomp -fPIC %c -c -o %o'
ld='gcc -fopenmp -shared -o %L %O %X'

make_dll, cfile_noext, 'IDL_Load', input_directory=srcdir, output_directory=srcdir, /verbose, /show_all_output, cc=cc, ld=ld ;;extra_cflag='-fopenmp -c'

result = call_external(cfile_noext+'.so', cfile_noext, findgen(10), 10, /f_value, /auto_glue)
print, result

And here is the output:
Thread 6 starting...
Thread 4 starting...
Thread 4: total += arr[8]
Thread 4: total += arr[9]
Thread 2 starting...
Thread 2: total += arr[4]
Thread 2: total += arr[5]
Thread 7 starting...
Thread 5 starting...
Thread 1 starting...
Thread 1: total += arr[2]
Thread 1: total += arr[3]
Thread 3 starting...
Thread 3: total += arr[6]
Thread 3: total += arr[7]
Number of threads = 8
Thread 0 starting...
Thread 0: total += arr[0]
Thread 0: total += arr[1]
45.0000

I am very glad to know that we can link OpenMP to IDL.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Read ENVI file
Next Topic: "% Unable to allocate memory" when using histogram.

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 09:22:49 PDT 2025

Total time taken to generate the page: 0.01531 seconds