/***********************************************************************/ /* This is an example call of MIDACO 7 (Parallel: GPGPU) ------------------------------------------------------ MIDACO solves Multi-Objective Mixed-Integer Non-Linear Problems: Minimize F_1(X),... F_O(X) where X(1,...N-NI) is CONTINUOUS and X(N-NI+1,...N) is DISCRETE subject to G_j(X) = 0 (j=1,...ME) equality constraints G_j(X) >= 0 (j=ME+1,...M) inequality constraints and bounds XL <= X <= XU The problem statement of this example is given below. You can use this example as template to run your own problem. To do so: Replace the objective functions 'F' (and in case the constraints 'G') given here with your own problem and follow the below instruction steps. In this example, MIDACO evaluates a block of P iterates in parallel on a GPU (graphics card) by OpenACC directives. Compile and run (here with the NVIDIA HPC compiler): nvc -O3 -acc example_GPGPU.c midacoc.a -lm -o run ./run IMPORTANT: The function 'problem_function' is executed on the GPU for all P iterates at the same time. It is therefore declared as OpenACC routine and must be THREAD-SAFE: no 'static' variables, no global variables that are written, no input or output (printf, files) and no calls of functions that do not run on the GPU. */ /***********************************************************************/ /************************ MAIN PROGRAM *****************************/ /***********************************************************************/ #include /* OpenACC-Library */ #include #include /***********************************************************************/ #pragma acc routine seq void problem_function( double *f, double *g, double *x ); /***********************************************************************/ #include "midaco.h" /* midaco_int and the MIDACO prototypes */ /***********************************************************************/ int main() { /* Dimensions of the optimization problem */ midaco_int o, n, ni, m, me; /* Lower and upper bounds ('xl' & 'xu') and optimization variable 'x' */ static double xl[100000], xu[100000], x[100000]; /* Objectives 'f(x)' and constraints 'g(x)' */ static double f[100], g[100000]; /* MIDACO information and stop flags */ midaco_int iflag = 0, istop = 0; /* MIDACO parameter */ static double param[15]; /* MIDACO integer 'iw' and real 'rw' workspace and pareto front 'pf' */ /* (Increase 'rw' or 'iw', if MIDACO reports IFLAG = 501 or 601) */ static midaco_int iw[1000000]; static double rw[20000000], pf[2000000]; midaco_int liw, lrw, lpf, p = 1; /* Parameter for stopping criteria, printing and license */ midaco_int maxtime, maxeval, printeval, save2file, resumable, i; char key[] = "MIDACO_LIMITED_VERSION___________________ALL_RIGHTS_RESERVED"; /* Arrays and variables for the parallelization */ double *xxx, *fff, *ggg; midaco_int c; int ngpus; /*****************************************************************/ /*** Step 1: Problem definition ********************************/ /*****************************************************************/ /* STEP 1.A: Problem dimensions ******************************/ o = 1; /* Number of objectives */ n = 4; /* Number of variables (in total) */ ni = 2; /* Number of integer variables (0 <= ni <= n) */ m = 3; /* Number of constraints (in total) */ me = 1; /* Number of equality constraints (0 <= me <= m) */ /* STEP 1.B: Lower and upper bounds 'xl' & 'xu' **********************************************/ for( i=0; i1=HISTORY] */ resumable = 0; /* Resumable mode [0=NO/1=YES] */ /*****************************************************************/ /*** Step 3: Choose MIDACO parameters (FOR ADVANCED USERS) ***/ /*****************************************************************/ param[ 0] = 0.0; /* ACCURACY */ param[ 1] = 0.0; /* SEED */ param[ 2] = 0.0; /* FSTOP */ param[ 3] = 0.0; /* ALGOSTOP */ param[ 4] = 0.0; /* EVALSTOP */ param[ 5] = 0.0; /* FOCUS */ param[ 6] = 0.0; /* ANTS */ param[ 7] = 0.0; /* KERNEL */ param[ 8] = 0.0; /* ORACLE */ param[ 9] = 0.0; /* PARETOMAX */ param[10] = 0.0; /* EPSILON */ param[11] = 0.0; /* BALANCE */ param[12] = 0.0; /* CHARACTER */ param[13] = 0.0; /* SURROGATE */ param[14] = 0.0; /* PMISQP */ /*****************************************************************/ /*** Step 4: Choose Parallelization Factor ********************/ /*****************************************************************/ p = 4; /* Serial = 1, Parallel = 2,3,4,... (P GPU threads) */ /*****************************************************************/ /* Preparations for Parallelization */ /*****************************************************************/ ngpus = acc_get_num_devices( acc_device_not_host ); printf("\n [ Available GPUs on this machine: %i ] \n",ngpus); /* Allocate arrays for the block of P iterates */ xxx = (double *) malloc( (p*n) * sizeof(double) ); fff = (double *) malloc( (p*o) * sizeof(double) ); ggg = (double *) malloc( (p*m+1) * sizeof(double) ); if( xxx == NULL || fff == NULL || ggg == NULL ) { printf("\n Not enough memory for P = %i \n",p); return 1; } /* Store starting point x in all P entries of xxx */ for( c=0; c 0 ){ printf(" Solution g[0] = %f\n", g[0]); } /* printf(" Solution x[0] = %f\n", x[0]); */ /*****************************************************************/ return 0; } /***********************************************************************/ /*************************** END OF MAIN *****************************/ /***********************************************************************/ /***********************************************************************/ /********************* OPTIMIZATION PROBLEM ************************/ /***********************************************************************/ void problem_function( double *f, double *g, double *x ) { /* Objective functions F(X) */ f[0] = (x[0]-1.0)*(x[0]-1.0) + (x[1]-2.0)*(x[1]-2.0) + (x[2]-3.0)*(x[2]-3.0) + (x[3]-4.0)*(x[3]-4.0) + 1.23456789; /* Equality constraints G(X) = 0 MUST COME FIRST in g[0:me-1] */ g[0] = x[0] - 1.0; /* Inequality constraints G(X) >= 0 MUST COME SECOND in g[me:m-1] */ g[1] = x[1] - 1.333333333; g[2] = x[2] - 2.666666666; } /***********************************************************************/ /*************************** END OF FILE *****************************/ /***********************************************************************/