Parallel Routine

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
saikrishna
Participant
Posts: 158
Joined: Tue Mar 15, 2005 3:16 am

Parallel Routine

Post 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
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Need to look into programing logic in deep.
What happens if your code has simple, print and return command.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Eric
Participant
Posts: 254
Joined: Mon Sep 29, 2003 4:35 am

Post 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?
saikrishna
Participant
Posts: 158
Joined: Tue Mar 15, 2005 3:16 am

Post 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
saikrishna
Participant
Posts: 158
Joined: Tue Mar 15, 2005 3:16 am

Post 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
Eric
Participant
Posts: 254
Joined: Mon Sep 29, 2003 4:35 am

Post 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*?
Post Reply