# 武汉大学“多核架构及编程技术”精品课程课外作业

!--CTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dt--> 首页 申报信息 在线学习 教学改革 教学效果

```#include <math.h>
#include <omp.h>
#include <stdio.h>

void longest(float x[100],int M,float y[100],int N){
int i=0;
int j=0;
int L[101][101]={{0},{0}};
for(i=1;i<=M;i++) L[i][0]=0;
for(j=1;j<=N;j++) L[0][j]=0;
#pragma omp parallel for schedule (dynamic, 20) private (i)
for(i=1;i<=M;i++)
#pragma omp parallel for shared(i) private(j)

for(j=1;j<=N;j++){
if(x[i]==y[j])
L[i][j]=L[i-1][j-1]+1;
else

if(L[i-1][j]>L[i][j-1]) L[i][j]=L[i-1][j];
else L[i][j]=L[i][j-1];
}

/*
for(i=1;i<10;i++)
printf("x %d is %fn",i,x[i]);
for(i=1;i<10;i++)
printf("y %d is %fn",i,y[i]);

for(i=0;i<101;i++)
for(j=0;j<101;j++)*/
printf("longest %d,%d is %dn",i,j,L[100][100]);

}

void main(){
int i;
float x1[100];
float y1[100];
for(i=1;i<100;i++)
x1[i]=i+0.03;
for(i=1;i<100;i++)
y1[i]=i*2+1+0.03;
y1[5]=5.4;
y1[4]=6.4;
longest(x1,100,y1,100);

}

```

For more complete information about compiler optimizations, see our Optimization Notice.