How can i compile & run a c program (with OpenMP)

2019-07-09 05:26发布

I am an undergraduate student working on my thesis about parallel programming. I am using OpenMP model. Now i want to use gem5 for measure performance. That's why i install gem5 Full System successfully by following link:

http://cearial01.kaist.ac.kr/index.php/2016/08/26/gem5-documentation/

Now i want to compile & run a c program with OpenMP (matmul.c) using gem5. How can i compile & run this program? I mean inside which folder i stored this program file (matmul.c) for compile? How i create object file of this program? How can i change no of processor, cache memory size, no of cpu during running & compilation?

I am new student of this section. That's why my asking list is too big! Hope anybody don't mind.

Best Regards, Litu

标签: openmp gem5
1条回答
贼婆χ
2楼-- · 2019-07-09 05:58

How can I compile and run this program? I mean inside which folder I stored this program file (matmul.c) for compile? How I create object file of this program?

How to cross compile for an image is not gem5 specific, so I'll be brief.

First you must obtain a cross compiler for the image.

The best way to do that, is to get a cross compiler from the same source as the image to ensure compatibility.

My preferred approach is to use minimal Buildroot images. Buildroot:

  • builds both the cross compiler and the image for me, and thus ensure compatibility
  • makes it easy to automate building new software with its package system
  • can produce very simple images, which are more suitable for gem5 and architecture research

This is my setup on GitHub. It contains a minimal OpenMP hello world which I have successfully run inside of gem5.

Another good option is to use https://crosstool-ng.github.io/

Since you want OpenMP support, you must build the GCC cross compiler compiler with support.

I think this is done in GCC with:

./configure --enable-libgomp

or through the Buildroot option:

BR2_GCC_ENABLE_OPENMP=y

And then when compiling, you must pass the -fopenmp option to gcc.

How can I change the number of processors and the cache memory size?

The best way to answer that question yourself is to use something like:

./build/ARM/gem5.opt configs/example/fs.py -h

and search the options.

You come across:

  • -n NUM_CPUS, --num-cpus=NUM_CPUS.

    For ARM you also need to pass a .dtb with the corresponding core count, e.g.: ./system/arm/dt/armv7_gem5_v1_2cpu.dtb for 2 cores.

  • caches: you will find the following options easily:

     --caches --l1d_size=1024 --l1i_size=1024 --l2cache --l2_size=1024 --l3_size=1024
    

    But keep in mind that:

查看更多
登录 后发表回答