TILERA--Makefile实例

Makefile文件内容:


# Default target.

all:


ifdef TILERA_ROOT
CC = $(TILERA_ROOT)/bin/tile-gcc
else
ifeq ($(filter tile%,$(shell uname -m)),)
$(error The 'TILERA_ROOT' environment variable is not set.)
endif
CC = gcc
endif
OPT = -Os
CFLAGS = -std=gnu99 -Wall -Werror -g $(OPT)
EXE = multi_tile
$(EXE).o: $(EXE).c
$(CC) $(CFLAGS) $(XFLAGS) -c -o $@ $<
$(EXE): $(EXE).o
$(CC) $(LDFLAGS) $(XFLAGS) -o $@ $< -ltmc
all: $(EXE)
clean:
rm -f *.o $(EXE)
.PHONY: all clean
ifdef TILERA_ROOT
SIZE = 4x4
TILE_MONITOR = $(TILERA_ROOT)/bin/tile-monitor

COMMON_ARGS = \
  --mkdir /opt/test --cd /opt/test \
  --upload $(EXE) $(EXE) -- $(EXE)
DEV_ARGS = --tile $(SIZE) $(COMMON_ARGS)
SIM_ARGS = --image $(SIZE) --functional $(COMMON_ARGS)
run_dev: $(EXE)
$(TILE_MONITOR) $(DEV_ARGS)
test_dev: $(EXE)
set -e -o pipefail; \
$(TILE_MONITOR) $(DEV_ARGS) \
 > [email protected]; \
diff $(EXE).out [email protected]
run_sim: $(EXE)
$(TILE_MONITOR) $(SIM_ARGS)
test_sim: $(EXE)
set -e -o pipefail; \
$(TILE_MONITOR) $(SIM_ARGS) \
 > [email protected]; \
diff $(EXE).out [email protected]
.PHONY: run_dev test_dev run_sim test_sim

else
run: $(EXE)
./$(EXE)
test: $(EXE)
set -e -o pipefail; \
./$(EXE) > [email protected]; \
diff $(EXE).out [email protected]
.PHONY: run test

endif


main.c文件包含头文件如下:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <tmc/alloc.h>
#include <sys/types.h>
#include <tmc/cpus.h>
#include <tmc/task.h>
#include <tmc/udn.h>

main.c文件内容如下:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <tmc/alloc.h>
#include <sys/types.h>
#include <tmc/cpus.h>
#include <tmc/task.h>
#include <tmc/udn.h>

// We will use N cpus to calculate the sum of N * M integers.
#define NUM_CPUS 8
#define INTS_PER_CPU 1024
#define TOTAL_INTS (NUM_CPUS * INTS_PER_CPU)


static int parallelize(int count)
 {
      cpu_set_t cpus;
     if (tmc_cpus_get_my_affinity(&cpus) != 0)
           tmc_task_die("Failure in 'tmc_cpus_get_my_affinity()'.");
     if (tmc_cpus_count(&cpus) < count)
         tmc_task_die("Insufficient cpus (%d < %d).", tmc_cpus_count(&cpus), count);
    // int watch_forked_children = tmc_task_watch_forked_children(1);
     tmc_task_watch_forked_children(1);
     int rank;
     for (rank = 1; rank < count; rank++)
     {
          pid_t child = fork();
          if (child < 0)
            tmc_task_die("Failure in 'fork()'.");
          if (child == 0) //父进程事物
             {   //  goto done;
              //if (tmc_cpus_set_my_cpu(tmc_cpus_find_nth_cpu(&cpus, rank)) < 0)
              if (tmc_cpus_set_my_cpu(rank) < 0)
                          tmc_task_die("Failure in 'tmc_cpus_set_my_cpu()'.");
             }
           if (child > 0) //父进程事物        
            {
              for (uint32_t i = 0; i < 500000; i++) //子进程事物
                          printf("childpid000\n");
             }    
     }
   //  rank = 0;
   // (void)tmc_task_watch_forked_children(watch_forked_children);
  //done:
   // if (tmc_cpus_set_my_cpu(tmc_cpus_find_nth_cpu(&cpus, rank)) < 0)
   //              tmc_task_die("Failure in 'tmc_cpus_set_my_cpu()'.");
   return rank;
 }


int main(int argc, char**argv)
{
  // Make sure we have enough cpus.
  cpu_set_t cpus;
  if (tmc_cpus_get_my_affinity(&cpus) != 0)
    tmc_task_die("Failure in 'tmc_cpus_get_my_affinity()'.");

   parallelize(NUM_CPUS);


}


查找tmc库的位置:

[root@COMPASS-COMPASS:0115 /home]# find / -name *tmc.so
/usr/lib32/libtmc.so
/usr/lib/libtmc.so
[root@COMPASS-COMPASS:0115 /home]# find / -name *tmc.a
/usr/lib32/libtmc.a
/usr/lib/feedback/libtmc.a
/usr/lib/libtmc.a

[root@COMPASS-COMPASS:0115 /home]# 




如果在Makefile中不加入-ltmc连接自己的动态库libtmc.so时,编译过程中会出错:

[root@COMPASS-COMPASS:0115 /usr/tilera/examples/tmc/multi_tile]# make
gcc   -o multi_tile multi_tile.o 
multi_tile.o: In function `sum_of_sums':
/usr/tilera/examples/tmc/multi_tile/multi_tile.c:102: undefined reference to `tmc_cpus_find_nth_cpu'
/usr/tilera/examples/tmc/multi_tile/multi_tile.c:103: undefined reference to `tmc_udn_header_from_cpu'
multi_tile.o: In function `tmc_cpus_get_my_affinity':
//usr/include/tmc/cpus.h:401: undefined reference to `tmc_cpus_get_task_affinity'
multi_tile.o: In function `tmc_alloc_map':
//usr/include/tmc/alloc.h:328: undefined reference to `tmc_alloc_map_at'
multi_tile.o: In function `main':
/usr/tilera/examples/tmc/multi_tile/multi_tile.c:142: undefined reference to `tmc_udn_init'
multi_tile.o: In function `tmc_cpus_get_my_affinity':
//usr/include/tmc/cpus.h:401: undefined reference to `tmc_cpus_get_task_affinity'
multi_tile.o: In function `parallelize':
/usr/tilera/examples/tmc/multi_tile/multi_tile.c:48: undefined reference to `tmc_cpus_count'
/usr/tilera/examples/tmc/multi_tile/multi_tile.c:51: undefined reference to `tmc_task_watch_forked_children'
/usr/tilera/examples/tmc/multi_tile/multi_tile.c:64: undefined reference to `tmc_task_watch_forked_children'
/usr/tilera/examples/tmc/multi_tile/multi_tile.c:68: undefined reference to `tmc_cpus_find_nth_cpu'
multi_tile.o: In function `tmc_cpus_set_my_cpu':
//usr/include/tmc/cpus.h:415: undefined reference to `tmc_cpus_set_task_cpu'
multi_tile.o: In function `main':
/usr/tilera/examples/tmc/multi_tile/multi_tile.c:149: undefined reference to `tmc_udn_activate'
/usr/tilera/examples/tmc/multi_tile/multi_tile.c:137: undefined reference to `tmc_task_die'
multi_tile.o: In function `parallelize':
/usr/tilera/examples/tmc/multi_tile/multi_tile.c:49: undefined reference to `tmc_cpus_count'
/usr/tilera/examples/tmc/multi_tile/multi_tile.c:49: undefined reference to `tmc_task_die'
multi_tile.o: In function `main':
/usr/tilera/examples/tmc/multi_tile/multi_tile.c:137: undefined reference to `tmc_task_die'
/usr/tilera/examples/tmc/multi_tile/multi_tile.c:137: undefined reference to `tmc_task_die'
/usr/tilera/examples/tmc/multi_tile/multi_tile.c:137: undefined reference to `tmc_task_die'
/usr/tilera/examples/tmc/multi_tile/multi_tile.c:137: undefined reference to `tmc_task_die'
multi_tile.o:/usr/tilera/examples/tmc/multi_tile/multi_tile.c:137: more undefined references to `tmc_task_die' follow
collect2: ld returned 1 exit status
make: *** [multi_tile] Error 1
[root@COMPASS-COMPASS:0115 /usr/tilera/examples/tmc/multi_tile]# 

错误提示,找不到指定的库中的函数。


加入-ltmc选项后,系统会到默认的 /usr/lib 或/lib等目录下搜索相应的库文件,如libtmc.so或libtmc.a等动态库或静态库。如果同一个目录下有相同名字的库文件(动态库和静态库)时,如libtmc.so和libtmc.a,此时系统优先选择使用动态库libtmc.so。


查看系统环境变量:

[root@localhost ~]# env
HOSTNAME=localhost
SELINUX_ROLE_REQUESTED=
TERM=xterm
SHELL=/bin/bash
HISTSIZE=1000
SSH_CLIENT=172.23.22.159 63804 22
SELINUX_USE_CURRENT_RANGE=
QTDIR=/usr/lib/qt-3.3
QTINC=/usr/lib/qt-3.3/include
SSH_TTY=/dev/pts/0
USER=root
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.tbz=01;31:*.tbz2=01;31:*.bz=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:
MAIL=/var/spool/mail/root
PATH=/opt/tilera/TileraMDE/tilegx/bin:/usr/lib/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/subversion/bin:/root/bin
PWD=/root
LANG=zh_CN.UTF-8
SELINUX_LEVEL_REQUESTED=
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
HISTCONTROL=ignoredups
SHLVL=1
HOME=/root
TILERA_ROOT=/opt/tilera/TileraMDE/tilegx
LOGNAME=root
QTLIB=/usr/lib/qt-3.3/lib
CVS_RSH=ssh
SSH_CONNECTION=172.23.22.159 63804 172.23.22.245 22
LESSOPEN=||/usr/bin/lesspipe.sh %s
G_BROKEN_FILENAMES=1
_=/bin/env
[root@localhost ~]# vim /etc/profile 
[root@localhost ~]# 


查看/ect/profile文件内容:

[root@localhost ~]# vim /etc/profile 


 60 # /usr/share/doc/setup-*/uidgid file
 61 if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
 62     umask 002
 63 else
 64     umask 022
 65 fi
 66 
 67 for i in /etc/profile.d/*.sh ; do
 68     if [ -r "$i" ]; then
 69         if [ "${-#*i}" != "$-" ]; then
 70             . "$i"
 71         else
 72             . "$i" >/dev/null 2>&1
 73         fi
 74     fi
 75 done
 76 
 77 unset i
 78 unset -f pathmunge
 79 
 80 TILERA_ROOT=/opt/tilera/TileraMDE/tilegx
 81 PATH=$TILERA_ROOT/bin:$PATH
 82 export TILERA_ROOT PATH

 83 #export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 84 
 85 #svn
 86 
 87 #PATH=$PATH:/opt/svn/subversion-1.9.1/bin
 88 #export PATH
 89 
 90 SVN_HOME=/opt/subversion
 91 export PATH=$PATH:$SVN_HOME/bin
 92 
 93 
 94 # System wide environment and startup programs, for login setup
 95 # Function and aliases go in /etc/bashrc
 96 
 97 ulimit -u 1000
 98 ulimit -n 65535
 99 ulimit -d unlimited
100 ulimit -m unlimited
101 ulimit -s unlimited
102 ulimit -t unlimited
103 ulimit -v unlimited
                                              


你可能感兴趣的:(TILERA--Makefile实例)