Page 1 of 1
Server Routine In parallel Job
Posted: Mon Sep 19, 2011 4:38 am
by sangi1981
Hi all,
I write a server routine to add months to a date.
I have to use this routine in parallel job, inside a transformer, but it is not possible.
I found that there are following solutions:
*) use basic transformer,
*) create parallel routine, using a c++ file in which make porting of basic code.
What are the steps needed to do second solution?
What Have I to do to implement this solution?
What Have I to know?
Where can I find some explanation or examples?
What can go wrong?
I'm on Sun Solaris Server.
Thanks lot in advance
Re: Server Routine In parallel Job
Posted: Mon Sep 19, 2011 6:00 am
by SURA
You need to create PX Routine using C++ code. You need to use the object file.
Don't imagine much and start to develop, you will get the solution.
DS User
Posted: Mon Sep 19, 2011 7:08 am
by battaliou
If you publish your server routine, I could see your rule base and translate it into PX for you. An example transformer algorithim using the INT and MOD functions:
* (YYYY-MM-DD)
YEAR = ExtDate[1,4] + Int((ExtDate[6,2] + #MONTHS#) / 12)
MONTH = Mod((ExtDate[6,2] + #MONTHS#), 12)
Posted: Mon Sep 19, 2011 12:18 pm
by sangi1981
Thanks much.
I implemented a c++ function, compiled with options from administrator, linked *.o file whit a parallel routine: seems to be good.
In this way, I have basic and c++ version....
Posted: Mon Sep 19, 2011 12:23 pm
by vinothkumar
Please post your C++ source code. In case if anyone needed they can refer.
Posted: Mon Sep 19, 2011 2:07 pm
by sangi1981
Of course.
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
char* AddMonthRoutine ( char* InDate, int AddMonths ) {
if ( InDate == NULL || *InDate == '\0' ||
strlen(InDate) == 0 || strlen(InDate) != 8 ) {
char rt[8];
time_t now = time(0);
struct tm *d;
d=localtime(&now);
strftime(rt,15,"%Y%m%d",d);
return rt;
}
if ( AddMonths < 0 ) return InDate;
char *cyyyy=(char *)malloc(sizeof(char)*4);
strncpy(cyyyy,InDate,4);
int yyyy=atoi(cyyyy);
char *cmm=(char *)malloc(sizeof(char)*2);
strncpy(cmm,InDate+4,2);
int mm=atoi(cmm);
char *cdd=(char *)malloc(2*sizeof(char));
strncpy(cdd,InDate+6,2);
int dd=atoi(cdd);
free(cyyyy); free(cmm); free(cdd);
int OutYear=yyyy+(AddMonths-(AddMonths%12))/12;
int OutMonth=mm+(AddMonths%12);
int OutDay=dd;
if ( OutMonth > 12 ) { OutYear+=1; OutMonth-=12; }
if ( OutMonth == 2 ) {
if ( OutDay > 28 ) {
int rest1=OutYear%400;
int rest2=OutYear%100;
int rest3=OutYear%4;
if ( (rest3 == 0 && rest2 != 0) || rest1 == 0 )
OutDay=29;
else
OutDay=28;
}
}
else if ( OutMonth == 4 || OutMonth == 6 || OutMonth == 9 | OutMonth == 11 )
if (OutDay > 30) OutDay=30;
else if ( OutMonth == 1 || OutMonth == 3 || OutMonth == 5 || OutMonth == 7 || OutMonth == 8 | OutMonth == 10 || OutMonth == 12 );
char cOutYear[5];
char cOutMonth[3];
char cOutDay[3];
char rData[10];
int zero=0;
sprintf(cOutYear,"%d",OutYear);
if (OutMonth < 10) { sprintf(cOutMonth,"%d%d", zero, OutMonth); }
else { sprintf(cOutMonth,"%d",OutMonth); }
if (OutDay < 10) { sprintf(cOutDay,"%d%d", zero, OutDay); }
else { sprintf(cOutDay,"%d",OutDay); }
sprintf(rData,"%s%s%s",cOutYear, cOutMonth, cOutDay);
return rData;
}