int AUTO(AutoData *Data) { struct timeval *time0,*time1; integer icp[NPARX2]; doublereal par[NPARX2], thl[NPARX]; iap_type *iap; rap_type *rap; doublereal *thu; integer *iuz; doublereal *vuz; function_list list; integer i, j, k; // Initialize structures and constants gData = Data; iap = &(Data->iap); rap = &(Data->rap); Data->sp_len = Data->num_sp + (1 + floor(iap->nmx/iap->npr)); Data->sp_inc = 5; #ifdef USAGE struct rusage *init_usage,*total_usage; usage_start(&init_usage); usage_start(&total_usage); #endif #ifdef FLOATING_POINT_TRAP trapfpe(); #endif #ifdef PTHREADS global_conpar_type = CONPAR_PTHREADS; global_setubv_type = SETUBV_PTHREADS; global_reduce_type = REDUCE_PTHREADS; #endif fp9 = fopen("fort.9","w"); if(fp9 == NULL) { fprintf(stderr,"Error: Could not open fort.9\n"); exit(1); } /* Initialization : */ iap->mynode = mynode(); iap->numnodes = numnodes(); if (iap->numnodes > 1) { iap->parallel_flag = 1; } else { iap->parallel_flag = 0; } /* NOTE: thu is allocated inside this function, and the pointer is passed back. I know this is ugly, but this function does a bit of work to get thu setup correctly, as well as figuring out the size the array should be. What really should happen is to have one function which reads fort.2 and another fuction which initializes the array. That way the allocation could happen between the two calls. */ init0(iap, rap, par, icp, thl, &thu, &iuz, &vuz); /* Find restart label and determine type of restart point. */ if (iap->irs > 0) { logical found = FALSE_; findlb(iap, rap, iap->irs, &(iap->nfpr), &found); if (! found) { if (iap->mynode == 0) { fprintf(stderr,"\nRestart label %4ld not found\n",iap->irs); } exit(0); } } set_function_pointers(*iap,&list); init1(iap, rap, icp, par); chdim(iap); /* Create the allocations for the global structures used in autlib3.c and autlib5.c. These are purely an efficiency thing. The allocation and deallocation of these scratch areas takes up a nontrivial amount of time if done directly in the wrapper functions in autlib3.c*/ allocate_global_memory(*iap); /* ---------------------------------------------------------- */ /* ---------------------------------------------------------- */ /* One-parameter continuations */ /* ---------------------------------------------------------- */ /* ---------------------------------------------------------- */ #ifdef USAGE usage_end(init_usage,"main initialization"); #endif if (Data->print_input) PrintInput(Data, par, icp); // Initialize output variables if(list.type==AUTOAE) Data->u = DMATRIX(iap->nmx, iap->ndim); else { // Solution measures Data->usm = (doublereal ***)MALLOC((2+(int)(log2(Data->nsm)))*sizeof(doublereal **)); Data->usm[0] = DMATRIX(iap->nmx, iap->ndim); // MAX Data->usm[1] = DMATRIX(iap->nmx, iap->ndim); // MIN for (i=0; i<(int)(log2(Data->nsm)); i++) Data->usm[2+i] = DMATRIX(iap->nmx, iap->ndim); // Jacobian of flow if (Data->sjac) { Data->c0 = DMATRIX_3D(iap->nmx, iap->ndim, iap->ndim); Data->c1 = DMATRIX_3D(iap->nmx, iap->ndim, iap->ndim); } // Jacobian of flow along cycles (temporary storage) if (Data->sflow) { Data->a1 = DMATRIX_3D(iap->ntst, iap->ndim, iap->ndim); Data->a2 = DMATRIX_3D(iap->ntst, iap->ndim, iap->ndim); } } Data->par = DMATRIX(iap->nmx, iap->nicp); if (iap->isp >= 1) { Data->ev = DCMATRIX(iap->nmx, iap->ndim); for (i=0; i<iap->nmx; i++) { for (j=0; j<iap->ndim; j++) { Data->ev[i][j].r = NAN; // This is a flag for bad floquet multipliers Data->ev[i][j].i = NAN; } } } Data->num_u = 0; if (Data->sp == NULL) Data->num_sp = 0; Data->sp = (AutoSPData *)REALLOC(Data->sp, (Data->sp_len)*sizeof(AutoSPData)); for (i=Data->num_sp; i<Data->sp_len; i++) { Data->sp[i].u = NULL; Data->sp[i].icp = NULL; Data->sp[i].ups = NULL; Data->sp[i].udotps = NULL; Data->sp[i].rldot = NULL; Data->sp[i].a1 = NULL; Data->sp[i].a2 = NULL; } if(list.type==AUTOAE) autoae(iap, rap, par, icp, list.aelist.funi, list.aelist.stpnt, list.aelist.pvli, thl, thu, iuz, vuz); if(list.type==AUTOBV) autobv(iap, rap, par, icp, list.bvlist.funi, list.bvlist.bcni, list.bvlist.icni, list.bvlist.stpnt, list.bvlist.pvli, thl, thu, iuz, vuz); // Testing output if (Data->print_output) PrintOutput(Data); #ifdef USAGE usage_end(total_usage,"total"); #endif //time_end(time0,"Total Time ",fp9); fprintf(fp9,"----------------------------------------------"); fprintf(fp9,"----------------------------------------------\n"); //time_end(time1,"",stdout); //} FREE(thu); FREE(iuz); FREE(vuz); fclose(fp9); // Clean up special solution points that were allocated and not used Data->sp = (AutoSPData *)REALLOC(Data->sp, (Data->num_sp)*sizeof(AutoSPData)); assert(Data->sp); Data->sp_len = Data->num_sp; return 1; }
int go_go_auto() /* this is the entry at this point, xAuto has been set */ { doublereal time0, time1; integer icp[NPARX2]; doublereal par[NPARX2], thl[NPARX]; doublereal *thu; integer iuz[100]; doublereal vuz[100]; iap_type iap; rap_type rap; function_list list; int irs=xAuto.irs; if(irs>0){ fp3 = fopen(fort3,"r"); } else { fp3 = fopen(fort3,"w+"); } fp7 = fopen(fort7,"w"); fp9 = fopen(fort9,"w"); /* Initialization : */ iap.mynode = mynode(); iap.numnodes = numnodes(); if (iap.numnodes > 1) { iap.parallel_flag = 1; } else { iap.parallel_flag = 0; } /* here is the feeder code from xAuto structure */ init(&iap, &rap, par, icp, thl, &thu, iuz, vuz); /* Find restart label and determine type of restart point. */ if (iap.irs > 0) { logical found = FALSE_; findlb(&iap, &rap, iap.irs, &(iap.nfpr), &found); if (! found) { if (iap.mynode == 0) { fprintf(stderr,"\nRestart label %4ld not found\n",iap.irs); } return(0);/* bad retrun */ } } /* dump_params(iap,rap,icp,thl); */ /* this is good for debugging and writes all the auto parameters */ set_function_pointers(iap,&list); init1(&iap, &rap, icp, par); chdim(&iap); /* Create the allocations for the global structures used in autlib3.c and autlib5.c. There are purely an efficiency thing. The allocation and deallocation of these scratch areas takes up a nontrivial amount of time if done directly in the wrapper functions in autlib3.c*/ allocate_global_memory(iap); /* ---------------------------------------------------------- */ /* ---------------------------------------------------------- */ /* One-parameter continuations */ /* ---------------------------------------------------------- */ /* ---------------------------------------------------------- */ if(list.type==AUTOAE) autoae(&iap, &rap, par, icp, list.aelist.funi, list.aelist.stpnt, list.aelist.pvli, thl, thu, iuz, vuz); if(list.type==AUTOBV) autobv(&iap, &rap, par, icp, list.bvlist.funi, list.bvlist.bcni, list.bvlist.icni, list.bvlist.stpnt, list.bvlist.pvli, thl, thu, iuz, vuz); free(thu); /* free(iuz); free(vuz); */ fclose(fp3); fclose(fp7); fclose(fp9); return 1; /* normal return */ }