/******************************************************* Mosel Example Problems ====================== file distfoliopar.c ``````````````````` Running several instances of a Mosel model in parallel using several (remote) Mosel instances. Before running this model, you need to set up the NODENAME with a machine name/address of your local network. The node that is used needs to have the same version of Xpress installed and suitably licensed, and the server "xprmsrv" must have been started on this machine. *** The model started by this program cannot be run with a Community Licence for the provided data instance *** (c) 2012 Fair Isaac Corporation author: S. Heipcke, Oct 2012 *******************************************************/ #include #include #include "xprd.h" #include "bindrv.h" #define NUMPAR 2 /* Number of model instances to run */ /***************** Reading result data ******************/ struct MySolArray { const char *ind; /* index name */ double val; /* solution value */ }; struct MySolArray *solfrac; struct MySolArray *solbuy; int getbdintval(s_bindrvctx bdrv) { union { int i; double r; char b; char *str; BINDRV_LONG l;} val; bindrv_getint(bdrv,&(val.i)); return val.i; } double getbddblval(s_bindrvctx bdrv) { union { int i; double r; char b; char *str; BINDRV_LONG l;} val; bindrv_getreal(bdrv,&(val.r)); return val.r; } /**** Reading a one-dim. array 'ar' of fixed max. size ****/ static int assignFixedTableVal(s_bindrvctx bdrv, struct MySolArray *ar) { int i,ct,ctrl,j2; union { int i; double r; char b; char *str; BINDRV_LONG l;} val; ct=0; bindrv_getctrl(bdrv,&(val.i)); if (val.i==BINDRV_CTRL_OPENLST) { while(bindrv_nexttoken(bdrv)>=0) { bindrv_getctrl(bdrv,&(val.i)); ctrl=val.i; if(ctrl==BINDRV_CTRL_CLOSELST) break; else if(ctrl==BINDRV_CTRL_OPENNDX) { bindrv_getstring(bdrv,&(val.str)); ar[ct].ind=val.str; bindrv_getctrl(bdrv,&(val.i)); if(val.i==BINDRV_CTRL_CLOSENDX) { bindrv_getreal(bdrv,&(val.r)); ar[ct].val=val.r; ct++; } else { printf("Wrong file format. ')' expected.\n"); return 1; } } else { printf("Wrong file format. '(' expected.\n"); return 2; } } } else { printf("Wrong file format. '[' expected.\n"); return 3; } return 0; } static int readSol(char *filename) { s_bindrvctx bdrv; FILE *f; union { int i; double r; char b; char *str; BINDRV_LONG l;} val; int res=0,num=0,i; printf("Solution file: %s\n", filename); f=fopen(filename,"r"); /* Use Mosel bin reader */ bdrv=bindrv_newreader((size_t (*)(void *,size_t,size_t,void*))fread,f); while(bindrv_nexttoken(bdrv)>=0 && res==0) { bindrv_getctrl(bdrv,&(val.i)); if(val.i==BINDRV_CTRL_LABEL) { bindrv_getstring(bdrv,&(val.str)); if(strcmp(val.str,"RETSOL")==0) printf("Total return: %g\n", getbddblval(bdrv)); else if(strcmp(val.str,"NUMSHARES")==0) { num = getbdintval(bdrv); printf("Number of shares: %d\n", num); } else if(strcmp(val.str,"SOLCOUNT")==0) printf("Solution number: %d\n", getbdintval(bdrv)); else if(strcmp(val.str,"SOLSTATUS")==0) printf("Solution status: %d\n", getbdintval(bdrv)); else if (strcmp(val.str,"BUY")==0) res=assignFixedTableVal(bdrv, solbuy); else if (strcmp(val.str,"FRAC")==0) res=assignFixedTableVal(bdrv, solfrac); else printf("Unexpected label: %s", val.str); } else { printf("Wrong file format\n"); res=4; } } bindrv_delete(bdrv); fclose(f); for(i=0;i