Page 1 of 1

Parallel Routine

Posted: Mon Jul 03, 2006 7:09 am
by saikrishna
Hi

I have written C code in Unix env.
the c program is as follows:

include<stdio.h>
#include<string.h>
#include<malloc.h>
char * sayhello(char *Arg1)
{
char *s1;
const char *s2="hello";
s1=(char *)malloc(20);
s1="hi";
strcat(s1,s2);
return(s1);
}


I have created a parallel routine in DS manager with the name SayHello.
called that parallel routine from a parallel job

Now I am getting the following sequence of errors

Transformer_107,5: strcat.strcat() at 0xdc97d774
Transformer_107,5: sayhello.strcat(char*,const char*)(??, ??), line 111 in "string.h"
Transformer_107,5: sayhello(char *)(??), line 12 in "sayhello.c"


Note: I tried to compile the C program using one main function and tried to run ...it is working fine in Unix env....

I tried writing my own code for strcat function...It is still giving the same error.....

Can any one please help us in this regard.....

Note: I wrote above sample code for easy to understand...but We need to use strcat function in our project..

Thanks
Sai

Posted: Mon Jul 03, 2006 8:07 am
by kumar_s
Need to look into programing logic in deep.
What happens if your code has simple, print and return command.

Posted: Mon Jul 03, 2006 3:13 pm
by ray.wurlod
Programming Tip
Whenever you use malloc(), use free() when finished with that memory.
If you call this routine one million times, you end up allocating 20MB of memory. This is known as a "memory leak".


You need to test this using a test bed (main() program) and debugger.
Is this usage of malloc() - in an assignment statement - successful?
What happens to the result of strcat()?
Ought you to return a pointer to the string s1?

Posted: Tue Jul 04, 2006 10:05 am
by Eric
Did you build a static or dynamic library?
What compiler and compile arguments did you use?
Did you follow the TrxExternalFunctions examples?

Perhaps you could post something about how you compiled you external routine?

Posted: Wed Jul 05, 2006 12:26 am
by saikrishna
Eric

We wrote parallel routines with the following options
1. Used object as object-type
2. Given External routine name
3. In Library path, we gave the path of the object file(.o)
4. In Type, we gave "External Function"

We used the following Makefile to generate object code

# =====================================================================
# Example Makefile to build the example transformer external functions
#
# AIX version, intended for demonstration purposes only.
#
# =====================================================================

TARGETLIB = libdateValid1.so
CODESRC = main1.c
TARGETOBJ = main1.o

CC = /usr/vacpp/bin/xlC_r
CCOPTIONS = -+ -O -g
LIBCC = $(CC)
LDOPTIONS = -G -qmkshrobj=1000

.SUFFIXES: .c .o

# ---------------------------------------------------------------------
# Rules
# ---------------------------------------------------------------------

all: $(TARGETLIB)

$(TARGETLIB): $(TARGETOBJ)
$(LIBCC) $(LDOPTIONS) $(TARGETOBJ) -o $(TARGETLIB)

$(TARGETOBJ): $(CODESRC)
$(CC) $(CCOPTIONS) -c $(CODESRC) -o $(TARGETOBJ)

clean:
@rm -f $(TARGETOBJ) $(TARGETLIB)

# ---------------------------------------------------------------------
# End of makefile
# ---------------------------------------------------------------------


Assume that the code is in main1.c


Could u pls look into this

Thanks
Sai

Posted: Wed Jul 05, 2006 12:31 am
by saikrishna
Hi Ray

I understood now the use of free in my program when we run for millions of rows......

But I am not able to understand where to put this free statement....
If u observe our code.....


include<stdio.h>
#include<string.h>
#include<malloc.h>
char * sayhello(char *Arg1)
{
char *s1;
const char *s2="hello";
s1=(char *)malloc(20);
s1="hi";
strcat(s1,s2);
return(s1);
}



If we put free statement before return(s1), s1 will become dangling pointer, where as if we write the free statement after return(s1), the free code is never executed......

Could u help us in this issue also....


Thanks
Sai

Posted: Wed Jul 05, 2006 5:29 am
by Eric
saikrishna wrote:Eric

We wrote parallel routines with the following options
1. Used object as object-type
2. Given External routine name
3. In Library path, we gave the path of the object file(.o)
4. In Type, we gave "External Function"
Thanks
Sai
The makefile etc looks good.

when you created the routine definition did you:
- tick the Return Type - char* in the routine definition?
- click on the arguments tab and give the name Arg1 with a native type of char*?