restricted pointers


 
Thread Tools Search this Thread
Top Forums Programming restricted pointers
# 1  
Old 02-29-2008
restricted pointers

Hi all. I am trying to use restricted pointers to allow the gcc compiler optimize the code, but I have not been able to make it work so far. I am testing with this code:

Code:
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <sys/time.h>

void vecmult(int n, int * restrict a, int * restrict b, int * restrict c)
{
  int i;
  for (i=0; i<n; ++i) {
    a[i] = b[i] * c[i];
  }
}

int main(){
  int Nsteps = 100000;
  int n = 1000;
  int* a=NULL; 
  int* b=NULL;
  int* c=NULL;

  //allocate memory
  a = malloc(n*sizeof(int));
  b = malloc(n*sizeof(int));
  c = malloc(n*sizeof(int));

  //initialize arrays
  for(int i = 0; i < n; ++i){
    a[i] = i;
    b[i] = 1;
    c[i] = 0;
  }

  //initialize time
  struct timeval tim;
  gettimeofday(&tim, NULL);
  long tcpu = clock();

  for(int i = 0; i < Nsteps; ++i){
    vecmult(n, a, b, c);
  }

  //time difference evaluation
  double t1 = tim.tv_sec + tim.tv_usec / 1000000.0;
  double start = (double)(tcpu);
  gettimeofday(&tim, NULL);
  double t2 = tim.tv_sec + tim.tv_usec / 1000000.0;
  tcpu = clock();
  double stop = (double)(tcpu);
  double t_elap = (t2 - t1);
  double t_cpu = (stop - start) / 1000000.0;
  //print
  printf("%f %f\n",t_elap, t_cpu);

  //deallocate memory
  free(a);
  free(b);
  free(c);

  //show that restrict does not work
  int l = 1;
  int* restrict p1=NULL;
  int* restrict p2=NULL;
  p1 = &l;
  p2 = p1;

  return 0;
}

The gcc-4.2 compiler does not even complaints for the last part with the -O3 and -std=c99 options. Dues someone knows how to make restricted pointers work? Thanks in advance.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Restricted user

Hello everyone I need to create a restricted user or a special user. Here is what I need. I have this path next to profiles I have server1, server2, server3....... The user that I have to create I need that he can move between server1. server2, server3 because in every one have logs... (1 Reply)
Discussion started by: lo-lp-kl
1 Replies

2. AIX

Restricted shell

Hello I have a user with a Restricted Shell on a Aix 5.3. My question is about if I can add one more path on the home directory. I mean the user have in his home directory. for example /test/my_application/logs but I need that this user can view another log that is on another path, if this... (1 Reply)
Discussion started by: lo-lp-kl
1 Replies

3. Programming

Need help with the Pointers in C

I have a special character called ô. When it is declared as a character variable its showing it can be printed. But when it is declared as a character pointer variable its showing it cannot be printed. I am just wondering why its happening like this.. c1 = '@'; c2 = 'ô'; char *fp; fp="XXô"; if... (1 Reply)
Discussion started by: sivakumar.rj
1 Replies

4. HP-UX

Restricted Login ID

I have a task to create a new id that going to used by vendor. The ID profiles are: 1)The ID to be created is MUST be restricted sharing. 2)create for their own user account 3)unable to read/navigate/view other directories 4)unable to write to other directories able to create their own... (3 Replies)
Discussion started by: yeazas
3 Replies

5. Programming

pointers

Hi I mash with pointers in C. I solve this problem about 5 hours and I don't know how I should continue. void InsertFirst (tList *L, int val) { tElemPtr new; if((new = malloc(sizeof(tElemPtr))) == NULL) Error(); new->data = val; new->ptr = L->frst; L->frst = new;... (2 Replies)
Discussion started by: Milla
2 Replies

6. UNIX for Advanced & Expert Users

HP-UX Restricted SAM

I am having trouble getting restricted SAM to work by allocating Privileges to a "group". I can make it work by allocaing to the userid's, but would preferre to use the "group" option. Running B.11.11 Tried the following.... 1) Created a user group in /etc/group first 2) Used the... (1 Reply)
Discussion started by: Andrek
1 Replies

7. Programming

pointers

is this a valid c declaration int (*ptr(int *b)); plz explain... (4 Replies)
Discussion started by: areef4u
4 Replies

8. UNIX for Dummies Questions & Answers

Restricted Shells. . .

Hey, Could someone please help me distinguish between a captive account and a restricted shell? Many thanks, L. (0 Replies)
Discussion started by: crispy
0 Replies

9. Cybersecurity

Restricted user

A few of the other employees here need to learn "vi" in order to use crontab to schedule / unschedule jobs on one of our production servers. I tried to set up a login on one of my Linux boxes for them to use "vimtutor", but scrapped it and decided to try for something more secure, since there are... (1 Reply)
Discussion started by: LivinFree
1 Replies

10. Programming

Pointers to Arrays

Below is the program i tried to execute...... main() { static int a = {0,1,2,3,4}; static int *p = {a, a+1, a+2, a+3, a+4}; printf (“\n %u %u %d”, p, *p, *(*p) ); } This works, but i wanted to know why both a and *p are declared as "static". If we dont declare a as static... (2 Replies)
Discussion started by: Jayathirtha
2 Replies
Login or Register to Ask a Question