xautopar and malloc

Hello,

I am trying to use automatic parallelization with -xautopar. I noticed that nothing but the simplest loops gets parallelized because I use unsafe functions. Adding the pragmas does_not_read/write_global_data or __attribute__((const)) lets the compiler consider these functions as safe. I understand that it is not safe to parallelize any function. But what about MT-safe functions like malloc? Should I abuse the pragmas and lie to the compiler, or is there some other pragma or attribute to tell about mt-safeness, and if so shouldn't it be set by default on all the libc functions that are known to be mt-safe? If I can't do anything but add integers in my loops, I won't be able to use this feature a lot...

[733 byte] By [Marc_Glissea] at [2007-11-27 0:34:50]
# 1
I've written an answer to this on the FAQ page for Sun Studio. http://www.genunix.org/wiki/index.php/Sun_Studio_FAQs#OpenMP_-_Why_can.27t_my_l oops_have_MT-safe_functions.3FYou can try using -xbuiltin for library funcs or -xO5 -xipo for user funcs.
ChrisQuenellea at 2007-7-11 22:42:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2

Thanks, but it does not work here (linux 32 bits). I am trying the following stupid code:

[code]

$ cat plouf.c

#include < stdlib.h >

void plouf(int n,double* t){

for(int i=0;i<n;i++){

malloc(4);

t[i]=2;

}

}

[/code]

I compile it with: suncc plouf.c -fast -xautopar -xloopinfo -c. If I remove the malloc line, it gets parallelized. With malloc, it says "call may be unsafe", and -fast already implies -xbuitin=%all. If I add -xipo on the command line, I get:

[code]

$ suncc plouf.c -fast -xautopar -xloopinfo -c -xipo

"plouf.c", line 3: not parallelized, call may be unsafe

Compression: No such file or directory

reading file: No such file or directory

/local/vegas/install/sun/sunstudio12/prod/bin/ipo: FAILED: File open failed /tmp/ipo_cmrrTUy

cc: ipo failed for plouf.c

[/code]

I assume the -xbuiltin does not work on linux yet and I have hit a bug in ipo.

But even if this worked the way you are saying, there is a need for a way to tell the compiler that a function is mt-safe when that function is provided by a user-created shared library (for archives you could argue there is -xipo_archive).>

Marc_Glissea at 2007-7-11 22:42:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 3

I get the same result on sparc/Solaris so that's not an issue.

It would seem logical to have a pragma that declares

an external function to be MT-safe.

I'm not sure the optimizer distinguishes between functions

which are "MT-safe" and functions which are "side-effect free".

If it doesn't have that notion yet, then this will be a more

significant RFE.

ChrisQuenellea at 2007-7-11 22:42:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 4

Thanks.

So should I file a bug for the -xipo weird error, a bug for -xbuiltin not telling the compiler that malloc is mt-safe, and an rfe for a pragma (or attribute) to tell that functions are mt-safe, or are you taking care of the issue (since you probably know better than me what should be done)?

By the way, your earlier comment on -xipo means that parallelization can happen at link time when there was an unsafe call at compile time that is detected to be safe at link time? That is great.

Also, does using -xbuiltin=%all mean I am not allowed to link with libmtmalloc or libumem or one of the other implementations of malloc provided by solaris?

Marc_Glissea at 2007-7-11 22:42:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 5
I filed 6549904 weird -xipo errorfor the ipo error.The other three RFEs I'll discuss with the openmp group first.
ChrisQuenellea at 2007-7-11 22:42:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 6

> [code]

> $ suncc plouf.c -fast -xautopar -xloopinfo -c -xipo

>

> ", line 3: not parallelized, call may be unsafe

> Compression: No such file or directory

> reading file: No such file or directory

> /local/vegas/install/sun/sunstudio12/prod/bin/ipo:

> FAILED: File open failed /tmp/ipo_cmrrTUy

> cc: ipo failed for plouf.c

> [/code]

It looks like you don't have bzip2 installed.

The useful info would be:

$ strace -f suncc plouf.c -fast -xautopar -xloopinfo -c -xipo 2>&1 | grep zip

$ which bzip2

$ uname -a

horsha at 2007-7-11 22:42:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 7
bzip2 indeed seems to be the issue. On debian it is installed in /bin and not in /usr/bin as sunpro expects (why use so many hardcoded paths?). If I symlink it in /usr/bin the error disappears.
Marc_Glissea at 2007-7-11 22:42:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 8
Which debian is that, btw?
horsha at 2007-7-11 22:42:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 9
This is current debian stable (etch).uname -a answers:Linux stedding 2.6.18-4-686 #1 SMP Mon Mar 26 17:17:36 UTC 2007 i686 GNU/Linuxthe version of the bzip2 package is 1.0.3-6.
Marc_Glissea at 2007-7-11 22:42:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...