Tab<float> FP_Basic::myFunction5(Tab<float> listRect) { mprintf(L"xin chao mytestfunction5\n"); mflush(); for (int i = 0; i < listRect.Count(); ++i) { listRect[i]++; mprintf(L"listRect[%d] = %f\n", i, listRect[i]); }; mflush(); return Tab<float>(); }
void warning(location l, const char *msg, ...) { va_list args; char err[4096]; prt_location(l); va_start(args, msg); vsprintf(err, msg, args); va_end(args); if (mudout) mflush(mudout); mprintf(muderr, "warning: %s" EOL, err); if (muderr) mflush(muderr); }
Tab<float> FP_Basic::myFunction3(Tab<float>& listRect) { mprintf(L"xin chao mytestfunction3\n"); mflush(); for (int i = 0; i < listRect.Count(); ++i) { listRect[i]++; mprintf(L"listRect[%d] = %f\n", i, listRect[i]); }; float a = 20; listRect.Append(1, &a); mflush(); //MessageBox(NULL, _T("Xin chao myFunction3!!!"), _T("Function Publishing Demonstration"), MB_OK); return Tab<float>(); }
void log_error(location l, const char *msg, ...) { va_list args; char err[4096]; prt_location(l); va_start(args, msg); vsprintf(err, msg, args); va_end(args); if (mudout) mflush(mudout); mprintf(muderr, "%s" EOL, err); if (muderr) mflush(muderr); erred = 1; }
void hpteEntry(size_t length) { char* start = (char*)mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); if (~0UL == (unsigned long)start) { printf("Error: %d %s\n", errno, strerror(errno)); } double result1 = runtest(start, length, 1); int ret = mflush((unsigned long)start, ((unsigned long)start) + length); if (ret < 0) { if (errno==ENOSYS) return; printf("mflush error: %d %s\n", errno, strerror(errno)); } double result2 = runtest(start, length, 1); munmap(start, length); printf("0x%4lx hpteEntry write: %.2lfus %.2lfus\n", length/PAGE_SIZE, result1, result2); }
int main(int argc, char *argv[]) { int do_restore = argc > 1 && strcmp("-r", argv[1]) == 0; const char *mode = (do_restore) ? "r+" : "w+"; /* call perm() and open() before malloc() */ perm(PERM_START, PERM_SIZE); mopen(MMAP_FILE, mode, MMAP_SIZE); bopen(BACK_FILE, mode); if (do_restore) { restore(); } else { home = (home_st *)malloc(sizeof(home_st)); /* initialize home struct... */ mflush(); backup(); } for (;/* each step */;) { /* Application_Step(); */ backup(); } free(home); mclose(); bclose(); return(0); }
static void mload_action(frameact action, u8 **ffp, u8 **fsp) { int exitcode = 0; switch (action) { case fa_unwind: /* program got an error */ exitcode = 1; /* fall through */ case fa_execute: /* program terminated successfully */ mflush(mudout); mflush(muderr); exit(exitcode); case fa_print: break; case fa_gcforward: case fa_pop: pop_frame(ffp, fsp, sizeof(struct generic_frame)); break; default: abort(); } }
int main (int argc, char *argv[]) { int my_rank, proc_num; MPI_Status status; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &proc_num); MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); double diff; /* change in value */ int i, j, m, n; int N=DEFAULT_N; double epsilon=0.01; double mean; FILE *fp; /* Argument processing */ int edgeElems = DEFAULT_ELEM; /* edge elements */ int cfreq = DEFAULT_FREQ; /* checkpoint frequency */ char *cpath = DEFAULT_PATH; /* checkpoint path */ int nok = 0; /* arguments not OK */ int pinit=1; char *s; while (--argc > 0 && (*++argv)[0] == '-') { for(s=argv[0]+1;*s;s++) switch (*s) { case 'd': if (isdigit(s[1])) edgeElems = atoi(s+1); else nok = 1; s+=strlen(s+1); break; case 'c': if (isdigit(s[i])) cfreq = atoi(s+1); else nok = 1; s+=strlen(s+1); break; case 'p': cpath = s+1; s+=strlen(s+1); break; case 'r': pinit = 0; break; case 'n': if (isdigit(s[1])) N = atoi(s+1); else nok = 1; s+=strlen(s+1); break; case 'e': if (isdigit(s[1])) epsilon = atof(s+1); else nok = 1; s+=strlen(s+1); break; default: nok = 1; break; } } if (nok) { fprintf(stderr, "Usage: %s -e<int> -c<int> -p<str> -r -n<int> -epsilon<double>\n", argv[0]); fprintf(stderr, " -d edge elements, default: %d\n", DEFAULT_ELEM); fprintf(stderr, " -c checkpoint frequency, default: %d\n", DEFAULT_FREQ); fprintf(stderr, " -p path to checkpoint file, default: %s\n", DEFAULT_PATH); fprintf(stderr, " -r restore\n"); fprintf(stderr, " -n size of n, default:1000\n"); fprintf(stderr, " -e epsilon, default:0.01\n"); exit(EXIT_FAILURE); } #ifdef DEBUG if(my_rank==0) printf("n=%d, epsilon=%lf\n", N, epsilon); #endif if(N>1000){ printf("Too big value for N, use no more than 1000, or change DEFAULT_N\n"); return 0; } // Persistent memory initialization const char *mode = (pinit) ? "w+" : "r+"; char back_fname[128]; char my_rank_str[4]; perm(PERM_START, PERM_SIZE); strcpy(back_fname, cpath); strcat(back_fname,"hw5_mpi.back."); sprintf(my_rank_str, "%d", my_rank); strcat(back_fname,my_rank_str); // printf("mopen: %s\n", back_fname); mopen(back_fname, mode, MMAP_SIZE); strcpy(back_fname, cpath); strcat(back_fname,"hw5_mpi.mmap."); strcat(back_fname,my_rank_str); // printf("bopen: %s\n", back_fname); bopen(back_fname, mode); if (!pinit){ restore(); printf("Resotored, iter=%d, myN=%d\n", iter, myN); } else{ iter = 0; /* Set boundary values and compute mean boundary value */ mean = 0.0; for (i=0; i<N; i++) { u[i][0] = u[i][N-1] = u[0][i] = 100.0; u[N-1][i] = 0.0; mean += u[i][0] + u[i][N-1] + u[0][i] + u[N-1][i]; } mean /= (4.0 *N); /* Initialize interior values */ for (i =1; i<N-1; i++) for (j=1; j<N-1; j++) u[i][j] = mean; // distribute data myN = N / proc_num; if(N%proc_num!=0){ if(my_rank==proc_num-1) myN=N-(proc_num-1)*myN; } if(proc_num > 1) { // ghost rows if(my_rank == 0 || my_rank == proc_num - 1) myN++; else myN += 2; } // initial value for(i = 0; i < myN; i++) { for(j = 0; j < N; j++) { if(my_rank == 0) myu[i][j] = u[i][j]; else myu[i][j] = u[my_rank*(N/proc_num)-1+i][j]; myw[i][j]=myu[i][j]; } } mflush(); backup(); } struct timeval start_tv, end_tv; gettimeofday(&start_tv, NULL); double alldiff=0; int left = my_rank - 1; int right = my_rank +1; MPI_Request send_req1, recv_req1; MPI_Request send_req2, recv_req2; while(1) { iter++; diff = 0.0; for (i=1; i<myN-1; i++) { for (j=1; j<N-1; j++) { myw[i][j] = (myu[i-1][j] + myu[i+1][j] + myu[i][j-1] + myu[i][j+1])/4.0; if (fabs (myw[i][j] - myu[i][j]) > diff) diff = fabs(myw[i][j] - myu[i][j]); } } // reduce diff MPI_Allreduce(&diff, &alldiff, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD); #ifdef PRINTITER if(my_rank==0){ printf("iter=%d, diff=%lf\n", iter, alldiff); fflush(stdout); } #endif if (alldiff <= epsilon) break; if(proc_num > 1) { // send second top row if(my_rank != 0){ MPI_Isend(myw[1], N, MPI_DOUBLE, left, 0, MPI_COMM_WORLD, &send_req1); //printf("Send: %d->%d\n", my_rank, left); } // send second to bottom row if(my_rank != proc_num - 1){ MPI_Isend(myw[myN-2], N, MPI_DOUBLE, right, 1, MPI_COMM_WORLD, &send_req2); //printf("Send %d->%d\n", my_rank, right); } // recive top if(my_rank != 0){ MPI_Irecv(myw[0], N, MPI_DOUBLE, left, 1, MPI_COMM_WORLD, &recv_req1); //printf("Recv: %d->%d\n", my_rank, left); } // receive bottom if(my_rank != proc_num - 1) { MPI_Irecv(myw[myN-1], N, MPI_DOUBLE, right, 0, MPI_COMM_WORLD, &recv_req2); //printf("Recv %d->%d\n", my_rank, right); } if(my_rank != 0) MPI_Wait(&send_req1, &status); if(my_rank != proc_num - 1) MPI_Wait(&send_req2, &status); if(my_rank != 0) MPI_Wait(&recv_req1, &status); if(my_rank != proc_num - 1) MPI_Wait(&recv_req2, &status); } for (i=0; i<myN; i++) { if( (i==0&&my_rank==0) ||(i==myN-1&&my_rank==proc_num-1)) continue; for (j=1; j<N-1; j++) myu[i][j] = myw[i][j]; } // backup if(iter%cfreq == 0) backup(); } gettimeofday(&end_tv, NULL); printf("Elapsed time: %f sec\n", (double)( (double)(end_tv.tv_sec - start_tv.tv_sec) + ( (double)(end_tv.tv_usec - start_tv.tv_usec)/1000000)) ); // gather data if(my_rank==0) { for (i=0; i<myN; i++) { for(j=0; j<N; j++) { u[i][j] = myu[i][j]; } } if(proc_num > 1) { for (i=1; i<proc_num-1; i++) MPI_Recv(u[i*(N/proc_num)], (N/proc_num)*N, MPI_DOUBLE, i, 0, MPI_COMM_WORLD, &status); // special care for last one if(N%proc_num==0) MPI_Recv(u[i*(N/proc_num)], (N/proc_num)*N, MPI_DOUBLE, i, 0, MPI_COMM_WORLD, &status); else{ MPI_Recv(u[i*(N/proc_num)], (N-(N/proc_num)*(proc_num-1))*N, MPI_DOUBLE, i, 0, MPI_COMM_WORLD, &status); } } } else { if(N%proc_num==0) MPI_Send(myu[1], (N/proc_num)*N, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD); else{ if(my_rank != proc_num-1) MPI_Send(myu[1], (myN-2)*N, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD); else MPI_Send(myu[1], (myN-1)*N, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD); } } if(my_rank == 0) { /* Print Solution */ fp = fopen("output.dat", "w"); for (i=0; i<N; i++) { for (j=0; j<N; j++) { fprintf(fp, "%6.2f ", u[i][j]); } fprintf(fp, "\n"); } fclose(fp); } mclose(); bclose(); MPI_Finalize(); return 0; }
Value* mouse_track_cf(Value** arg_list, int count) { // mouseTrack [on:node|#any] [prompt:"msg"] [snap:#2D|#3D] [trackCallback:fn|#(fn,arg)] // set up value local array to hold mouse tracker command mode Value*'s Value** vavl; value_local_array(vavl, sizeof(tmvl) / sizeof(Value*)); tmvl* vl = (tmvl*)vavl; // show any prompt Value* pv = key_arg(prompt); const TCHAR* prompt = NULL; if (pv != &unsupplied) { prompt = pv->to_string(); mprintf(_T("%s "), prompt); mflush(); } // setup snap Value* sv = key_arg_or_default(snap, n_2D); if (sv != n_2D && sv != n_3D) throw RuntimeError (MaxSDK::GetResourceStringAsMSTR(IDS_BAD_SNAP_MODE), sv); // setup track callback fn Value* tcb = NULL; Value* tcbarg = NULL; Value *tcbv = key_arg(trackCallback); if (tcbv != &unsupplied) { if (is_array(tcbv)) // an array, #(fn, arg), dig out fn & arg { Array* tcba = (Array*)tcbv; if (tcba->size != 2) throw RuntimeError (MaxSDK::GetResourceStringAsMSTR(IDS_BAD_MOVE_CALLBACK_ARGS), tcbv); tcb = tcba->data[0]; if (!is_function(tcb)) throw RuntimeError (MaxSDK::GetResourceStringAsMSTR(IDS_BAD_MOVE_CALLBACK_ARGS), tcb); tcbarg = tcba->data[1]; } else // just the fn { tcb = tcbv; if (!is_function(tcb)) throw RuntimeError (MaxSDK::GetResourceStringAsMSTR(IDS_BAD_MOVE_CALLBACK_ARGS), tcbv); } } // pickup any node to track on vl->node_val = key_arg(on); NodeTab& nodeTab = theTrackMouseCommandMode.proc.nodeTab; nodeTab.SetCount(0); if( vl->node_val->_is_collection() ) { //Multiple nodes specified Value* args[2] = { NULL, (Value*)&nodeTab }; node_map m = { NULL, collect_nodes, args, 2 }; vl->node_val->map(m); } else if( vl->node_val != &unsupplied ) { //Single node specified INode* node = vl->node_val->to_node(); nodeTab.Append( 1, &node ); } for( int i=(nodeTab.Count()-1); i>=0; i--) if( nodeTab[i]==NULL ) nodeTab.Delete(i,1); //Delete null nodes // set up pickpoint options, enter trackmouse command mode & wait for it to signal completion end_track_mouse = FALSE; theTrackMouseCommandMode.proc.vl = vl; theTrackMouseCommandMode.proc.snap_mode = sv; theTrackMouseCommandMode.proc.track_callback = tcb; theTrackMouseCommandMode.proc.track_callback_arg = tcbarg; theTrackMouseCommandMode.proc.start_track(); //Changed from Set to Push to prevent an exception when the maxscript code changes the command mode //Similar to fix done to MouseTool.cpp - line 661 MAXScript_interface->PushCommandMode(&theTrackMouseCommandMode); // process windows messages until point picked or canceled or keyboard message MSG wmsg; while (GetMessage(&wmsg, NULL, 0,0)) { if (wmsg.message == WM_KEYUP && (TCHAR)wmsg.wParam == VK_ESCAPE) end_track_mouse = TRUE; else if (wmsg.message == WM_KEYUP || wmsg.message == WM_KEYDOWN) continue; else if (wmsg.message != WM_RBUTTONUP) // ignore rmousebuttonup's - they mess focus MAXScript_interface->TranslateAndDispatchMAXMessage(wmsg); if (end_track_mouse) break; } if (!end_track_mouse) { // we came out of message loop because of a quit, repost the quit and throw a SignalException theTrackMouseCommandMode.proc.end_track(); MAXScript_interface->DeleteMode(&theTrackMouseCommandMode); throw SignalException(); } // pickup result value & dismiss input modes theTrackMouseCommandMode.proc.end_track(); MAXScript_interface->DeleteMode(&theTrackMouseCommandMode); Value* result = vl->result; pop_value_local_array(vavl); return_protected(result); }